|
|
|
@ -16,6 +16,8 @@ public class Tank {
|
|
|
|
|
private boolean move = false;
|
|
|
|
|
//为了解决能够在坦克中发射子弹,将创建的子弹通过坦克发射出来,那么需要在坦克类中持有游戏窗口的引用
|
|
|
|
|
private TankFrame tankFrame;
|
|
|
|
|
public static final int WIDTH = ResourcesMgr.tankD.getWidth();
|
|
|
|
|
public static final int HEIGHT = ResourcesMgr.tankD.getHeight();
|
|
|
|
|
|
|
|
|
|
public Tank(int x, int y, DirEnum dir, TankFrame tankFrame) {
|
|
|
|
|
this.x = x;
|
|
|
|
@ -62,6 +64,8 @@ public class Tank {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void fire() {
|
|
|
|
|
tankFrame.bullets.add(new Bullet(this.x, this.y, this.dir, tankFrame));
|
|
|
|
|
int bX = this.x + WIDTH/2 - Bullet.WIDTH/2;
|
|
|
|
|
int bY = this.y+HEIGHT/2-Bullet.HEIGHT/2;
|
|
|
|
|
tankFrame.bullets.add(new Bullet(bX, bY, this.dir, tankFrame));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|