diff --git a/tankWar/src/com/mashibing/tank/Bullet.java b/tankWar/src/com/mashibing/tank/Bullet.java index 224a0ff..9c5aa44 100644 --- a/tankWar/src/com/mashibing/tank/Bullet.java +++ b/tankWar/src/com/mashibing/tank/Bullet.java @@ -9,8 +9,8 @@ import java.awt.*; */ public class Bullet { private static final int SPEED = 10; - private static final int WIDTH = 20; - private static final int HEIGHT = 20; + public static int WIDTH = ResourceImageRead.BULLET_DOWN.getWidth(); + public static int HEIGHT = ResourceImageRead.BULLET_DOWN.getHeight(); private int x; private int y; diff --git a/tankWar/src/com/mashibing/tank/Tank.java b/tankWar/src/com/mashibing/tank/Tank.java index f73b03f..a31a9b5 100644 --- a/tankWar/src/com/mashibing/tank/Tank.java +++ b/tankWar/src/com/mashibing/tank/Tank.java @@ -9,6 +9,9 @@ import java.awt.*; */ public class Tank { private static final int SPEED = 5; + public static int WIDTH = ResourceImageRead.TANK_DOWN.getWidth(); + public static int HEIGHT = ResourceImageRead.TANK_DOWN.getHeight(); + private int x; private int y; private Direction direction; @@ -79,8 +82,11 @@ public class Tank { * 解决:坦克对象要持有FrameTank对象的引用 */ public void fire() { + int bulletX = this.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2; + int bulletY = this.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2; + // 将子弹加入子弹集合 - frameTank.bulletList.add(new Bullet(this.x, this.y, this.direction, this.frameTank)); + frameTank.bulletList.add(new Bullet(bulletX, bulletY, this.direction, this.frameTank)); } public Direction getDirection() {