diff --git a/src/com/msb/Bullet.java b/src/com/msb/Bullet.java index 3c6dd49..5bc66f8 100644 --- a/src/com/msb/Bullet.java +++ b/src/com/msb/Bullet.java @@ -8,12 +8,12 @@ import java.awt.*; * @Description: 子弹类 * @Version: 1.0 */ -public class Bullet extends Frame { +public class Bullet { private int x, y; private DirEnum dir; - public static final int WIDTH = 20; - public static final int HEIGHT = 20; + public static final int WIDTH = ResourcesMgr.bulletD.getWidth(); + public static final int HEIGHT = ResourcesMgr.bulletD.getHeight(); public static final int SPEED = 5; private boolean live = true; private TankFrame tankFrame; diff --git a/src/com/msb/Tank.java b/src/com/msb/Tank.java index 7819564..2f32cdf 100644 --- a/src/com/msb/Tank.java +++ b/src/com/msb/Tank.java @@ -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)); } }