📄 pogoroomidlet.java
字号:
break; case keyRight: dirRoo -= 5f; dirCam += 5f; tRoo.setOrientation(dirRoo, 0, 0, 1); tCams.setOrientation(dirCam, 0, 0, 1); break; default: if (dirCam > 4.9f) { dirCam -= 5.0f; } else if (dirCam < -4.9f) { dirCam += 5.0f; } else { dirCam = 0.0f; } tCams.setOrientation(dirCam, 0, 0, 1); break; } } /** * animateRoo() * Makes sure that the hopping animation loops correctly. */ private void animateRoo(int worldTime) { // control the kangaroo animation sequence if (animLastTime == 0) { animLastTime = worldTime; } animTime += (worldTime - animLastTime); // initialise animation at end of sequence if (animTime > animLength) // sequence is ~1000ms { animRoo.setActiveInterval(worldTime, worldTime + 2000); animRoo.setPosition(0, worldTime); animTime = 0; } // update storage of last position and time animLastTime = worldTime; } /** * moveRoo() * Act on key presses and any collision detection to move the kangaroo */ private void moveRoo(int worldTime) { hopRoo(); checkWorldEdge(); turnRoo(); animateRoo(worldTime); tRoo.getTranslation(posRooLast); } /** * pauseApp() */ public void pauseApp() { } /** * destroyApp() */ public void destroyApp(boolean unconditional) throws MIDletStateChangeException { myRefreshTimer.cancel(); myRefreshTimer = null; myRefreshTask = null; } /** * MIDlet paint method. */ public void paint(Graphics g) { // clear any area of the screen that is not drawn to by m3g if ((g.getClipWidth() != viewport_width) || (g.getClipHeight() != viewport_height) || (g.getClipX() != viewport_x) || (g.getClipY() != viewport_y)) { g.setColor(0x00); g.fillRect(0, 0, myCanvas.getWidth(), myCanvas.getHeight()); } // render the 3D scene if ((myGraphics3D != null) && (myWorld != null)) { myGraphics3D.bindTarget(g); myGraphics3D.setViewport(viewport_x, viewport_y, viewport_width, viewport_height); myGraphics3D.render(myWorld); myGraphics3D.releaseTarget(); } } /** * MIDlet keyEvent method. */ public void keyEvent(int type, int keyCode) { switch (type) { case KEY_REPEATED: break; case KEY_PRESSED: // game movement keys - Roo requires synchronized move with animation, // so can only accept key press when last move is complete if (keyMoveRoo == keyNone) { switch (myCanvas.getGameAction(keyCode)) { case Canvas.FIRE: break; case Canvas.UP: keyMoveRoo = keyForward; break; case Canvas.DOWN: keyMoveRoo = keyBackward; break; } if (keyMoveRoo != keyNone) { hopCount = MaxHops; } } // Roo can turn when it likes switch (myCanvas.getGameAction(keyCode)) { case Canvas.LEFT: keyTurnRoo = keyLeft; break; case Canvas.RIGHT: keyTurnRoo = keyRight; break; } break; case KEY_RELEASED: switch (myCanvas.getGameAction(keyCode)) { case Canvas.LEFT: //intentional fall through case Canvas.RIGHT: keyTurnRoo = keyNone; break; case Canvas.UP: //intentional fall through case Canvas.DOWN: keyMoveRoo = keyNone; break; } break; default: throw new IllegalArgumentException(); } } /** * Handle commands. */ public void commandAction(Command cmd, Displayable disp) { if (cmd == exitCommand) { try { destroyApp(false); notifyDestroyed(); } catch (Exception e) { e.printStackTrace(); } } } /** * Inner class for refreshing the view. */ private class RefreshTask extends TimerTask { public void run() { // Get the canvas to repaint itself. if ((myCanvas != null) && (myGraphics3D != null) && (myWorld != null)) { int startTime = (int)System.currentTimeMillis(); // update the control and game AI moveRoo(startTime); // Update the world to the current time. int validity = myWorld.animate(startTime); // Cause a repaint myCanvas.repaint(viewport_x, viewport_y, viewport_width, viewport_height); } } } /** * Inner class for handling the canvas. */ class PogoRooCanvas extends Canvas { PogoRooMIDlet myRooMIDlet; /** * Construct a new canvas */ PogoRooCanvas(PogoRooMIDlet Testlet) { myRooMIDlet = Testlet; } /** * Initialize self. */ void init() { } /** * Cleanup and destroy. */ void destroy() { } /* * Ask myRooMIDlet to paint itself */ protected void paint(Graphics g) { myRooMIDlet.paint(g); } /* * Ask myRooMIDlet to handle keyPressed events */ protected void keyPressed(int keyCode) { myRooMIDlet.keyEvent(myRooMIDlet.KEY_PRESSED, keyCode); } /* * Ask myRooMIDlet to handle keyReleased events */ protected void keyReleased(int keyCode) { myRooMIDlet.keyEvent(myRooMIDlet.KEY_RELEASED, keyCode); } /* * Ask myRooMIDlet to handle keyRepeated events */ protected void keyRepeated(int keyCode) { myRooMIDlet.keyEvent(myRooMIDlet.KEY_REPEATED, keyCode); } /* * Ask myRooMIDlet to handle pointerDragged events */ protected void pointerDragged(int x, int y) { } /* * Ask myRooMIDlet to handle pointerPressed events */ protected void pointerPressed(int x, int y) { } /* * Ask myRooMIDlet to handle pointerReleased events */ protected void pointerReleased(int x, int y) { } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -