📄 cortrol.java
字号:
package npc7776;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class cortrol
extends GameCanvas
implements CommandListener, Runnable {
Image imgs;
Graphics g;
Plane plane;
backdrop back;
bullet bullet;
Thread thread = null;
planemain mainScreen;
public cortrol(planemain mainScreen) {
super(true);
this.mainScreen= mainScreen;
g = this.getGraphics();
try {
jbInit();
}
catch (Exception e) {
e.printStackTrace();
}
plane = new Plane(imgs, 24, 24, this.getWidth(),this.getHeight());
bullet = new bullet();
back = new backdrop(this.getHeight());
thread = new Thread(this);
thread.start();
}
private void jbInit() throws Exception {
imgs = Image.createImage("/res/planes.png");
setCommandListener(this);
addCommand(new Command("Exit", Command.EXIT, 1));
}
public void commandAction(Command command, Displayable displayable) {
if (command.getCommandType() == Command.EXIT) {
mainScreen.goBack();
}
}
public void keyInput() {
plane.hf();
if ( (this.getKeyStates() & this.LEFT_PRESSED) != 0) {
plane.moveLeft();
}
if ( (this.getKeyStates() & this.RIGHT_PRESSED) != 0) {
plane.moveRight();
}
if ( (this.getKeyStates() & this.UP_PRESSED) != 0) {
plane.moveUp();
}
if ( (this.getKeyStates() & this.DOWN_PRESSED) != 0) {
plane.moveDown();
}
if ( (this.getKeyStates() & this.FIRE_PRESSED) != 0) {
bullet.addBullet(plane.x, plane.y, 24);
}
}
public void stop(){
thread = null;
}
public void clear() {
g.setColor(back.getGroundColor());
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
public void run() {
while (true) {
clear();
keyInput();
plane.drawSelf(g);
bullet.drawSelf(g);
bullet.move();
back.scrollTerrain(g);
this.flushGraphics();
try {
thread.sleep(100);
}
catch (Exception e) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -