By processing buttons simulation acceleration, brakes, etc.

xiaoxiao2021-04-10  409

Import java.lang. *; import java.io. *; import java.util. *; import javax.microedition.lcdui. *;

public class gKey {public int key_UP; public int key_DOWN; public int key_LEFT; public int key_RIGHT; public int key_A; public int key_B; public int key_C; public int key_D; public int key_STAR; public int key_POUND; public int key_TIMER; public int movespeed; public int leftvalue; public int upvalue; public int rightvalue; public int downvalue; public gKey (int keytime, int mspeed) {key_TIMER = keytime; refreshKey (); movespeed = mspeed;} public void refreshKey () {key_UP = 0 Key_DOWN = 0; key_right = 0; key_a = 0; key_b = 0; key_c = 0; key_star = 0; key_pound = 0;} public void flushkey () {f (key_up> 0) if (key_UP 0) if (key_DOWN 0) if (key_LEFT 0 ) IF (key_right

public void keyPressed (int keyCode, Canvas canvas) {switch (canvas.getGameAction (keyCode)) {case Canvas.UP: key_UP = (key_UP

rightvalue = movespeed; break; case Canvas.KEY_POUND: key_POUND = (key_POUND

}

Import java.lang. *; import java.io. *; import java.util. *; import javax.microedition.lcdui. *;

Public Class Gcanvas Extends Canvas IMPLEments Runnable {

private Graphics bgGraphics; private Image bgBuf; private int width; private int height; private int dfwidth; private int dfheight; private int snoffx; private int snoffy; private boolean isOver; private boolean isFirstRun; public gKey keyParam; public int thDelay; private Thread MTHREAD; // Test Private Int X, Y; INT W, INT H, INT Keytimer, INT THDELAY {Try {width = getWidth (); height = getHeight (); dfWidth = W; Dfheight = h; isfirstrun = true; snoffx = (width - dfwidth) / 2; snoffy = (height - dfheight) / 2; isOver = false; bgBuf = Image.createImage (dfwidth, dfheight); bgGraphics = bgBuf.getGraphics (); mThread = new Thread (this); x = 0; y = 0; keyparam = new gkey (keytimer); trise = trise; // test} catch (exception ex) {isover = true;}} public void overprocess () {isover = true; // add destroy code} public void run () {{while (! isover) {// add execute code f (keyparam.key_a> 0) { KeyParam.refreshkey (); // Key press to respond only to call this function overprocess ();} if (y> 0) y - = keyparam.key_up; if (y 0) x - = keyparam.key_left; if (x

} // add draw functiong.drawimage (BGBUF, Snoffx, Snoffy, G.Left | g.top);} public void keypressed (int keycode) {keyparam.KeyPressed (keycode, this)

Public void keyreleased (int keycode) {keyparam.keyreleased (keycode, this);

}

转载请注明原文地址:https://www.9cbs.com/read-133377.html

New Post(0)