📄 bullet.java
字号:
/* * To change this template, choose Tools | Templates * and open the template in the editor. */import javax.microedition.lcdui.Image;import javax.microedition.lcdui.game.GameCanvas;import javax.microedition.lcdui.game.Sprite;/* * To change this template, choose Tools | Templates * and open the template in the editor. *//** * * @author wutianyi */public class Bullet extends Sprite { private int Direction = -1; private int step = 5; public boolean isLive = true; private int width, height; public Bullet(Image img) { super(img); } public void setDirection(int Direction) { this.Direction = Direction; if (Direction == GameCanvas.LEFT_PRESSED) { setTransform(Sprite.TRANS_NONE); } if (Direction == GameCanvas.RIGHT_PRESSED) { setTransform(Sprite.TRANS_ROT180); } if (Direction == GameCanvas.UP_PRESSED) { setTransform(Sprite.TRANS_ROT90); } if (Direction == GameCanvas.DOWN_PRESSED) { setTransform(Sprite.TRANS_ROT270); } } public void setCanvasSize(int width, int height) { this.width = width; this.height = height; } public void tick() { if (Direction == GameCanvas.LEFT_PRESSED) { move(-step, 0); if (getX() <= 0) { isLive = false; } } if (Direction == GameCanvas.RIGHT_PRESSED) { move(step, 0); if (getX() >= width) { isLive = false; } } if (Direction == GameCanvas.UP_PRESSED) { move(0, -step); if (getY() <= 0) { isLive = false; } } if (Direction == GameCanvas.DOWN_PRESSED) { move(0, step); if (getY() >= height) { isLive = false; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -