public void run() { exitMidlet = false ; long startTime = 0 ; long timeCount = 0 ; gameInit() ; int curKey = 0 ; while (!exitMidlet) { startTime = System.currentTimeMillis(); //acquire key acquireKey() ; //call game loop gameLoop() ; //repaint the screen repaint(); serviceRepaints(); frameCount++ ; //lock fps timeCount = MIN_DELAY - (System.currentTimeMillis() - startTime); timeCount = (timeCount<1)?1:timeCount ; try { Thread.sleep(timeCount); } catch (InterruptedException ex) {} } endMidlet() ; } |
static int key , pressedKey, releasedKey ; |
final static int GKEY_0=1<<0, GKEY_1=1<<1 ; |
public void keyPressed(int keyCode) { int value = getKeyValue(keyCode) ; key |= value ; pressedKey |= value ; } public void keyReleased(int keyCode) { int value = getKeyValue(keyCode) ; key ^= value ; releasedKey |= value ; } |
private static void acquireKey() { frameKey = key ; framePressedKey = pressedKey ; frameReleasedKey = releasedKey ; pressedKey = 0 ; releasedKey = 0 ; } public static boolean keyHold(int gameKey) { return ((frameKey & gameKey)!=0) ; } public static boolean keyDown(int gameKey) { return ((framePressedKey & gameKey)!=0) ; } public static boolean keyUp(int gameKey) { return ((frameReleasedKey & gameKey)!=0) ; } |
public void gameLoop() { switch(gameState){ case GS_Logo: logic_Logo() ; break ; case GS_MainMenu: logic_MainMenu() ; break ; case GS_PlayerControl: logic_PlayerControl() ; break ; case GS_PauseMenu: logic_PauseMenu() ; break ; case GS_GameOver: endGame() ; break ; } } |
欢迎光临 51Testing软件测试论坛 (http://bbs.51testing.com/) | Powered by Discuz! X3.2 |