📄 tank.java
字号:
package pack04;import javax.microedition.lcdui.game.Sprite;public class Tank extends Sprite { private int speed=2; public final static int UP=0; public final static int RIGHT=1; public final static int DOWN=2; public final static int LEFT=3; private int currentDirection=RIGHT; GameMap map; public Tank(GameMap map) { super(Utility.getImage("/Splash.png")); this.defineReferencePixel(6, 6); this.map=map; } private void changeDirection (int direction) { if(direction ==currentDirection) return ; currentDirection=direction; switch(direction) { case UP: this.setTransform(Sprite.TRANS_ROT270); break; case DOWN: this.setTransform(Sprite.TRANS_ROT90); break; case LEFT: this.setTransform(Sprite.TRANS_ROT180); break; case RIGHT: this.setTransform(Sprite.TRANS_NONE); break; } } public boolean tryMove(int direction) { changeDirection(direction); int dx=0,dy=0; switch(direction) { case UP: dy = -speed; break; case RIGHT: dx = speed; break; case DOWN: dy = speed; break; case LEFT: dx = -speed; break; } this.move(dx, dy); if(map.isOutOfBorder(this)) { this.move(-dx, -dy); return false; } if(this.collidesWith(map, false)) { this.move(-dx, -dy); return false; } return true; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -