From 3cd93dc1ee86d0386283746823f695d43c5cc30f Mon Sep 17 00:00:00 2001 From: zhanxinlin <2452913979@qq.com> Date: Thu, 29 Sep 2022 00:17:30 +0800 Subject: [PATCH] =?UTF-8?q?day3=EF=BC=8C=E5=AD=90=E5=BC=B9=E5=8F=91?= =?UTF-8?q?=E5=B0=84=E4=BD=8D=E7=BD=AE=E6=94=B9=E8=87=B3=E5=9D=A6=E5=85=8B?= =?UTF-8?q?=E4=B8=AD=E9=97=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- tankWar/src/com/mashibing/tank/Bullet.java | 4 ++-- tankWar/src/com/mashibing/tank/Tank.java | 8 +++++++- 2 files changed, 9 insertions(+), 3 deletions(-) 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() {