📄 showplane.java
字号:
package spriteplane;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
import spritebullet.*;
public class ShowPlane
extends GameCanvas
implements CommandListener, Runnable {
int scnW, scnH;
Plane plane;
Graphics g;
Bullet bullets;
public ShowPlane() {
super(false);
scnW = getWidth();
scnH = getHeight();
addCommand(new Command("Exit", Command.EXIT, 1));
setCommandListener(this);
g = this.getGraphics();
plane = new Plane(g, scnW, scnH, 24, 24);
bullets = new Bullet();
Thread t = new Thread(this);
t.start();
}
public void commandAction(Command command, Displayable displayable) {
if (command.getCommandType() == Command.EXIT) {
MainMIDlet.quitApp();
}
}
public void KeyInput() {
int key = this.getKeyStates();
if ( (key & this.LEFT_PRESSED) != 0) {
plane.moveLeft();
}
else if ( (key & this.RIGHT_PRESSED) != 0) {
plane.moveRight();
}
if ( (key & this.UP_PRESSED) != 0) {
plane.moveUp();
}
else if ( (key & this.DOWN_PRESSED) != 0) {
plane.moveDown();
}
if ( (key & this.GAME_A_PRESSED) != 0) {
plane.moveNS();
}
//开火
if ( (key & this.FIRE_PRESSED) != 0) {
bullets.addBullet(plane.x,plane.y,24);
}
}
public void Clear() {
g.setColor(255, 255, 255); //clear screen
g.fillRect(0, 0, getWidth(), getHeight());
}
public void run() {
while (true) {
Clear();
KeyInput();
plane.DrawSelf();
bullets.DrawSelf(g);
bullets.Move();
flushGraphics();
try {
Thread.sleep(30);
}
catch (Exception e) {}
Clear();
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -