📄 showbullet.java
字号:
package spritebullet;
import javax.microedition.lcdui.*;
import javax.microedition.lcdui.game.*;
public class ShowBullet
extends GameCanvas implements Runnable,CommandListener {
Bullet bullet;
Graphics g;
int x, y, width;
public ShowBullet(int x, int y, int width) {
super(true);
this.x = x;
this.y = y;
this.width = width;
addCommand(new Command("Exit", Command.EXIT, 1));
setCommandListener(this);
g = this.getGraphics();
bullet = 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 input() {
if (getKeyStates() == FIRE_PRESSED) {
bullet.addBullet(getWidth()/2,getHeight()/2,32);
}
}
public void clear() {
g.setColor(0, 0, 0);
g.fillRect(0, 0, this.getWidth(), this.getHeight());
}
public void run() {
while (true) {
clear();
input();
bullet.DrawSelf(g);
this.flushGraphics();
bullet.Move();
try {
Thread.sleep(100);
}
catch (Exception e) {}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -