📄 engine.java
字号:
/*******************************************************************************
**
** Class: Engine (Engine.java)
**
** The "Engine" class encapsulates the entire application state machine, the
** MIDlet's Canvas, as well as miscellaneous functionality not directly
** associated with any of the other classes. Due to Engine being a meta-class
** of sorts, it's split up into various sections, and all constants, data
** members and methods are declared in these appropriate sections.
**
******************************************************************************/
// Engine header.
import javax.microedition.lcdui.Canvas;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;
import java.util.Random;
import java.io.InputStream;
import java.io.DataInputStream;
import javax.microedition.rms.RecordStore;
//#if SCREEN_PRINTOUTS
//# import javax.microedition.lcdui.Font;
//#endif
//#if Nokia_3100 || Nokia_3100_Unobfuscated
//# import com.nokia.mid.ui.*;
//# import com.nokia.mid.sound.*;
//# public final class Engine extends FullCanvas {
//#else
import javax.microedition.media.*;
import javax.microedition.media.control.*;
public class Engine extends Canvas implements PlayerListener{
//#endif
/****************************************************************************
** 'tors
***************************************************************************/
public static boolean isinterrupt = false;
public TOTFC m_midlet; // parent MIDlet.
public static Engine s_engine; // static manager of the Engine class.
public static boolean afterinterrupt = false;
// public static long AnswerPause = 1000L;
// public static long notifyPause = 1000L;
// public static boolean notifyE = false;
// class initializer.
public static void poke() { Thread.yield(); }
// default Engine constructor -- must contain reference to parent MIDlet.
public Engine(TOTFC parent) {
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
setFullScreenMode(true);
s_current_sound = s_current_sound_playing = FULL_INT;
//#else
//# s_current_sound = FULL_INT;
//#endif
m_midlet = parent;
s_engine = this;
m_state = STATE_UNINITIALIZED;
s_current_font = CUSTOM_FONT_NORMAL;
m_loading_count = 1;
COORDS = load2DShortArray("c", COORD_ELEMENTS);
loadLocale("e", LOCALE_REGION_1);
Level.s_paused = false;
Level.resetScores();
Level.s_puzzles_unlocked = Level.s_timetrial_unlocked = Level.s_survival_unlocked = 0;
loadSavedGameFromRecordStore();
//Level.s_puzzles_unlocked = Level.PUZZLE_COUNT;
//Level.s_timetrial_unlocked = Level.TIMETRIAL_COUNT;
//Level.s_survival_unlocked = FULL_BYTE;
//saveGameToRecordStore();
Menus.buildMenus();
S_IMAGES[IMAGE_SPLASHES] = loadImage(IMAGE_SPLASHES);
setScreen();
}
/****************************************************************************
** Extended Methods
***************************************************************************/
//#if Razr
//# public static final int LEFT_SOFT_KEY = -21; // phone's value for left soft key.
//# public static final int RIGHT_SOFT_KEY = -22; // phone's value for right soft key.
//#else
public static final int LEFT_SOFT_KEY = -6; // phone's value for left soft key.
public static final int RIGHT_SOFT_KEY = -7; // phone's value for right soft key.
//#endif
public static final int CLEAR_KEY = -8; // phone's value for clear key.
public static final int BACK_KEY = -9; // phone's value for back key.
public static final int SEND_KEY = -10; // phone's value for send key.
public static final int INPUT_NONE = 0; // no user input.
public static final int INPUT_ACTION = 1; // d-pad "in" direction, number 5 key.
public static final int INPUT_UP = 2; // d-pad up direction, number 2 key.
public static final int INPUT_RIGHT = 3; // d-pad right direction, number 6 key.
public static final int INPUT_DOWN = 4; // d-pad down direction, number 8 key.
public static final int INPUT_LEFT = 5; // d-pad left direction, number 4 key.
public static final int INPUT_1 = 6; // number 1 key.
public static final int INPUT_3 = 7; // number 3 key.
public static final int INPUT_7 = 8; // number 7 key.
public static final int INPUT_9 = 9; // number 9 key.
public static final int INPUT_0 = 10; // number 0 key.
public static final int INPUT_STAR = 11; // star key.
public static final int INPUT_POUND = 12; // pound key.
public static final int INPUT_LEFT_SOFT_KEY = 13; // left soft key.
public static final int INPUT_RIGHT_SOFT_KEY = 14; // right soft key.
public static volatile byte s_current_action; // current user-input value.
public static volatile byte s_last_action; // last user-input value.
// Canvas -- MIDlet loses focus.
public void hideNotify() {
isinterrupt = true;
m_midlet.m_paused = true;
//tira
//smudrievsky
//pause sound before interrupt
pauseSound();
//<-
// if(s_engine.m_state == STATE_GAME &&
// Level.s_state != Level.STATE_SCORE) {
// CRC-228
if(s_engine.m_state == STATE_GAME &&
Level.s_state != Level.STATE_SCORE && Level.s_state != Level.STATE_GAME_OVER) {
//<- CRC-228
Menus.startMenu(Menus.MENU_INGAME);
}
else if(s_engine.m_state == STATE_END_GAME) {
// special case, bring up the quit to title prompt during the ending credits
Menus.startConfirmation(Menus.MENU_ITEM_BACK_TO_TITLE);
Menus.m_prev_engine_state = STATE_END_GAME;
s_engine.m_state = STATE_INGAME_MENU;
}
else if(s_engine.m_state == STATE_INGAME_MENU &&
Level.s_type == Level.TYPE_TUTORIAL && Menus.m_current_menu !=13 && Menus.m_current_menu != 12 && Menus.m_current_menu != 8) { //TIRA CRC-215 -> && Menus.m_current_menu !=13
// weird workaround to get proper ingame menu interrupt behaviour during a tutorial text box
Menus.mb_go_back = true;
Menus.push();
Menus.setMenu(Menus.MENU_INGAME);
Menus.process();
}
Menus.m_menu_item_timer = 0; // to ensure menus are repainted when returning
if(s_engine.m_state >= STATE_TITLE) m_state_timer = 0; // to ensure background repainted when returning
//#if DefaultConfiguration || Nokia_6600 || Nokia_6600_Unobfuscated || Nokia_3220 || Nokia_3220_Unobfuscated || Razr
// stopSound();
if((Level.s_state == Level.STATE_BIGGS_FLY ||
Level.s_state == Level.STATE_BIGGS_FALL ||
Level.s_state == Level.STATE_SCORE) &&
Menus.m_prev_engine_state != STATE_END_GAME) s_current_sound = FULL_INT;
//#endif
pauseSound();
stopAllSounds();
}
// Canvas -- MIDlet gains focus.
public void showNotify() {
isinterrupt = false;
gc();
m_midlet.m_paused = false;
//tira
//smudrievsky
//resume sound after interrupt
if (Level.s_type == Level.TYPE_MAINMENU)
{
playSound(s_current_sound);
}
if (s_engine.m_state != STATE_INGAME_MENU)
{
playSound(s_current_sound);
}
// new Thread() {public void run() {loadSound(s_current_sound);}}.start();
// loadSound(s_current_sound);
//<-
}
// Canvas -- entry point for all rendering.
protected void paint(Graphics g) {
// System.out.println(Menus.m_current_menu);
//#ifdef MANUAL_BUFFER
//# // exit paint function if we have not yet initialized the screen buffer.
//# if(s_screen_image == null) { return; }
//#
//# Graphics tmp_g = s_screen_graphic;
//#else
Graphics tmp_g = g;
//#endif
int red, green, blue;
int x, y;
switch(m_state) {
case STATE_UNINITIALIZED:
fillScreen(tmp_g, 255, 255, 255);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -