bullet.java

来自「j2me的坦克大战 元代码 单机版和蓝牙联网版」· Java 代码 · 共 76 行

JAVA
76
字号
/* * 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 + =
减小字号Ctrl + -
显示快捷键?