|
|
@ -18,6 +18,7 @@ public class Tank {
|
|
|
|
private TankFrame tankFrame;
|
|
|
|
private TankFrame tankFrame;
|
|
|
|
public static final int WIDTH = ResourcesMgr.tankD.getWidth();
|
|
|
|
public static final int WIDTH = ResourcesMgr.tankD.getWidth();
|
|
|
|
public static final int HEIGHT = ResourcesMgr.tankD.getHeight();
|
|
|
|
public static final int HEIGHT = ResourcesMgr.tankD.getHeight();
|
|
|
|
|
|
|
|
private boolean live = true;
|
|
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, DirEnum dir, TankFrame tankFrame) {
|
|
|
|
public Tank(int x, int y, DirEnum dir, TankFrame tankFrame) {
|
|
|
|
this.x = x;
|
|
|
|
this.x = x;
|
|
|
@ -27,6 +28,12 @@ public class Tank {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
public void paint(Graphics g) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if( ! live) {
|
|
|
|
|
|
|
|
tankFrame.tanks.remove(this);
|
|
|
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* Color color = g.getColor();
|
|
|
|
/* Color color = g.getColor();
|
|
|
|
g.setColor(Color.YELLOW);
|
|
|
|
g.setColor(Color.YELLOW);
|
|
|
|
g.fillRect(x, y, 50, 50);
|
|
|
|
g.fillRect(x, y, 50, 50);
|
|
|
@ -64,8 +71,21 @@ public class Tank {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void fire() {
|
|
|
|
public void fire() {
|
|
|
|
|
|
|
|
//子弹在坦克每个方向上的中心点应该是不一样的. TODO
|
|
|
|
int bX = this.x + WIDTH/2 - Bullet.WIDTH/2;
|
|
|
|
int bX = this.x + WIDTH/2 - Bullet.WIDTH/2;
|
|
|
|
int bY = this.y+HEIGHT/2-Bullet.HEIGHT/2;
|
|
|
|
int bY = this.y+HEIGHT/2-Bullet.HEIGHT/2;
|
|
|
|
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, tankFrame));
|
|
|
|
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, tankFrame));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getX() {
|
|
|
|
|
|
|
|
return x;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public int getY() {
|
|
|
|
|
|
|
|
return y;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void die() {
|
|
|
|
|
|
|
|
this.live = false;
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|