📄 xmain.java
字号:
temp--;
if (temp < 0) {
temp = options[menuItemSelected].length - 1;
}
} else {
temp++;
if (temp > options[menuItemSelected].length - 1) {
temp = 0;
}
}
optionSelected[menuItemSelected] = (byte) (temp);
menuItemName[menuItemSelected] = options[menuItemSelected][temp];
repaint = true;
break;
case INPUT_OK:
case INPUT_CANCEL:
byte[][] data = new byte[1][];
if (inputPressed == INPUT_OK) {
data[0] = optionSelected;
recordSave(data, recordData.length - 1);
if (optionSelected[options.length - 1] == 0) {
playLoop(musicLoop);
} else {
stopLoop();
}
} else {
recordLoad(data, recordData.length - 1);
optionSelected = data[0];
}
setState(STATE_MENU_MAIN);
break;
}
}
protected void logicOptions() {
}
protected void paintOptions(Graphics g) {
paintMenu(g);
}
protected String[][] createOptions() {
return null;
}
// ************************************
// state: message
// ************************************
protected String[] message;
protected int messageX;
protected int messageY;
protected int messageW;
protected int messageH;
protected int messageColor;
protected int messageSelected;
protected int messageStateOK;
protected int messageStateCancel;
protected void enterMessage() {
createMessage();
messageSelected = 0;
createText(message[messageSelected], messageX, messageY, messageW,
messageH, messageColor);
}
protected void inputMessage() {
switch (inputPressed) {
case INPUT_UP:
textUp();
repaint = true;
break;
case INPUT_DOWN:
textDown();
repaint = true;
break;
case INPUT_OK:
case INPUT_FIRE:
messageSelected++;
if (messageSelected < message.length) {
createText(message[messageSelected], messageX, messageY,
messageW, messageH, messageColor);
} else {
setState(messageStateOK);
}
break;
case INPUT_CANCEL:
setState(messageStateCancel);
break;
}
}
protected void logicMessage() {
}
protected void paintMessage(Graphics g) {
drawMessageBackground(g);
drawText(g);
}
protected void createMessage() {
messageX = 0;
messageY = 0;
messageW = width;
messageH = height;
messageColor = 0x000000;
}
protected void drawMessageBackground(Graphics g) {
g.setColor(0xFFFFFF);
g.fillRect(0, 0, width, height);
}
// ************************************
// state: game
// ************************************
protected void enterGame() {
}
protected void leaveGame() {
}
protected void logicGame() {
}
// ************************************
// sound
// ************************************
private static final String[] SOUND_OPTIONS = { "@OPTIONS_SOUND_ON@",
"@OPTIONS_SOUND_OFF@" };
private Object musicLoop = null;
private boolean isPlaying = false;
protected final Object createSound(String name) {
#if(${ant.handset_music}==${ant.handset_sound})
return createMusic(name);
#else
return null;
#end
}
protected final void deleteSound(Object sound) {
#if(${ant.handset_music}==${ant.handset_sound})
deleteMusic(sound);
#else
return;
#end
}
protected final void playSound(Object sound) {
#if(${ant.handset_music}==${ant.handset_sound})
playMusic(sound);
#else
return;
#end
}
protected final Object createMusic(String name) {
#if(${ant.handset_music}=="midi")
try {
Player midiPlayer = Manager.createPlayer(midlet.getClass()
.getResourceAsStream(name + ".mid"), "audio/midi");
if (midiPlayer != null) {
midiPlayer.realize();
midiPlayer.prefetch();
}
return midiPlayer;
} catch (MediaException e) {
showError(e);
} catch (IOException e) {
showError(e);
}
#end
return null;
}
protected final void deleteMusic(Object music) {
#if(${ant.handset_music}=="midi")
try {
Player midiPlayer = (Player) music;
if (midiPlayer != null) {
midiPlayer.stop();
midiPlayer.close();
}
} catch (MediaException e) {
showError(e);
}
#end
}
protected void playMusic(Object music) {
stopLoop();
musicLoop = null;
if (optionSelected[options.length - 1] == 1) {
return;
}
#if(${ant.handset_music}=="midi")
Player midiPlayer = (Player) music;
try {
if (midiPlayer != null) {
midiPlayer.setLoopCount(1);
midiPlayer.start();
}
} catch (MediaException e) {
showError(e);
}
#end
}
protected void playLoop(Object music) {
if (isPlaying) {
if (music == musicLoop) {
return;
}
stopLoop();
}
musicLoop = music;
if (optionSelected[options.length - 1] == 1) {
return;
}
#if(${ant.handset_music}=="midi")
Player midiPlayer = (Player) music;
try {
if (midiPlayer != null) {
midiPlayer.setLoopCount(-1);
midiPlayer.start();
}
} catch (MediaException e) {
showError(e);
}
#end
isPlaying = true;
}
protected void stopLoop() {
if (!isPlaying) {
return;
}
#if(${ant.handset_music}=="midi")
Player midiPlayer = (Player) musicLoop;
try {
if (midiPlayer != null) {
midiPlayer.stop();
}
} catch (MediaException e) {
showError(e);
}
#end
isPlaying = false;
}
// ************************************
// debug
// ************************************
protected final void showInfo(String info) {
#if(${ant.build_debug})
System.out.println(info);
#end
}
protected final void showError(Exception e) {
#if(${ant.build_debug})
e.printStackTrace();
#end
}
// ************************************
// graphics
// ************************************
public static final int TOP_LEFT = Graphics.TOP | Graphics.LEFT;
public static final int TOP_RIGHT = Graphics.TOP | Graphics.RIGHT;
protected final void drawClip(Graphics g, Image img, int posX, int posY,
int clipX, int clipY, int clipW, int clipH) {
int tempX = g.getClipX();
int tempY = g.getClipY();
int tempW = g.getClipWidth();
int tempH = g.getClipHeight();
if ((posX + clipW <= tempX) || (posX >= tempX + tempW)
|| (posY + clipH <= tempY) || (posY >= tempY + tempH)) {
return;
}
int x = posX;
int y = posY;
if (x < tempX) {
x = tempX;
}
if (y < tempY) {
y = tempY;
}
int w = posX + clipW - x;
int h = posY + clipH - y;
if (x + w > tempX + tempW) {
w = tempX + tempW - x;
}
if (y + h > tempY + tempH) {
h = tempY + tempH - y;
}
g.setClip(x, y, w, h);
g.drawImage(img, posX - clipX, posY - clipY, TOP_LEFT);
g.setClip(tempX, tempY, tempW, tempH);
}
protected final void drawNumber(Graphics g, int object, int n, int x,
int y, int w) {
if (n == 0) {
drawObject(g, object, 0, 0, x, y);
return;
}
while (n > 0) {
drawObject(g, object, n % 10, 0, x, y);
n = n / 10;
x -= w;
}
}
// ************************************
// data
// ************************************
private static final String FILE_DATA = "d.x";
private static final String FILE_RESOURCE = "r.x";
#if(${ant.handset_memory}!="memory_s")
private byte[] bufferData;
private byte[] bufferResource;
#end
private short[][][] dataObject;
private short[][][] dataFrame;
private short[][] dataClip;
private Image[] dataImage;
private int[] dataImageOffset;
private boolean[] dataImageActive;
private int[] dataSceneOffset;
private int[] dataValueOffset;
private int[] dataTextOffset;
// ************************************
// data
// ************************************
protected final void dataLoad() {
DataInputStream input = null;
//showInfo("dataLoad begin freeMemory2:"+Runtime.getRuntime().freeMemory());
try {
#if(${ant.handset_memory}!="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_DATA));
bufferData = new byte[input.readInt()];
input.read(bufferData);
input.close();
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
bufferResource = new byte[input.readInt()];
input.read(bufferResource);
input.close();
#end
#if(${ant.handset_memory}=="memory_s")
//showInfo("dataLoad befor new input freeMemory2:"+Runtime.getRuntime().freeMemory());
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_DATA));
//showInfo("dataLoad after new input freeMemory2:"+Runtime.getRuntime().freeMemory());
input.readInt();
#else
input = new DataInputStream(new ByteArrayInputStream(bufferData));
#end
// object
int nObject = input.readShort();
//showInfo("Object:"+nObject);
dataObject = new short[nObject][][];
for (int i = 0; i < nObject; i++) {
int nMotion = input.readShort();
dataObject[i] = new short[nMotion][];
for (int j = 0; j < nMotion; j++) {
int nFrame = input.readShort();
dataObject[i][j] = new short[nFrame];
for (int k = 0; k < nFrame; k++) {
dataObject[i][j][k] = input.readShort();
}
}
}
// frame
int nFrame = input.readShort();
//showInfo("nFrame:"+nFrame);
dataFrame = new short[nFrame][][];
for (int i = 0; i < nFrame; i++) {
int nPiece = input.readShort();
dataFrame[i] = new short[nPiece][3];
for (int j = 0; j < nPiece; j++) {
dataFrame[i][j][0] = input.readShort();
dataFrame[i][j][1] = input.readShort();
dataFrame[i][j][2] = input.readShort();
}
}
// clip
int nClip = input.readShort();
//showInfo("nClip:"+nClip);
dataClip = new short[nClip][5];
for (int i = 0; i < nClip; i++) {
dataClip[i][0] = input.readShort();
dataClip[i][1] = input.readShort();
dataClip[i][2] = input.readShort();
dataClip[i][3] = input.readShort();
dataClip[i][4] = input.readShort();
}
input.close();
#if(${ant.handset_memory}=="memory_s")
input = new DataInputStream(midlet.getClass().getResourceAsStream(
FILE_RESOURCE));
input.readInt();
#else
input = new DataInputStream(
new ByteArrayInputStream(bufferResource));
#end
// image
int nImage = input.readShort();
dataImage = new Image[nImage];
dataImageOffset = new int[nImage];
dataImageActive = new boolean[nImage];
for (int i = 0; i < nImage; i++) {
dataImage[i] = null;
dataImageOffset[i] = input.readInt();
dataImageActive[i] = false;
}
// scene
int nScene = input.readShort();
dataSceneOffset = new int[nScene];
for (int i = 0; i < nScene; i++) {
dataSceneOffset[i] = input.readInt();
}
// value
int nValue = input.readShort();
dataValueOffset = new int[nValue];
for (int i = 0; i < nValue; i++) {
dataValueOffset[i] = input.readInt();
}
// text
int nText = input.readShort();
dataTextOffset = new int[nText];
for (int i = 0; i < nText; i++) {
dataTextOffset[i] = input.readInt();
}
} catch (IOException e) {
showError(e);
} finally {
try {
if (input != null) {
input.close();
}
} catch (Exception e) {
showError(e);
}
}
System.gc();
//showInfo("dataLoad end freeMemory2:"+Runtime.getRuntime().freeMemory());
}
protected final void loadObject(int object) {
for (int i = 0; i < dataObject[object].length; i++) {
for (int j = 0; j < dataObject[object][i].length; j++) {
int frame = dataObject[object][i][j];
for (int k = 0; k < dataFrame[frame].length; k++) {
int image = dataClip[dataFrame[frame][k][0]][0];
dataImageActive[image] = true;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -