From c7a49ad7ab91e5f423da2db7c245b6df560ae7ee Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Mon, 3 Oct 2022 13:31:30 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98(=E4=B8=80?= =?UTF-8?q?=E6=9C=9F)-=E5=B0=86=E5=AD=90=E5=BC=B9=E8=B0=83=E6=95=B4?= =?UTF-8?q?=E5=88=B0=E5=9D=A6=E5=85=8B=E7=9A=84=E4=B8=AD=E5=BF=83=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE=E6=89=93=E5=87=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/Bullet.java | 6 +++--- src/com/msb/Tank.java | 6 +++++- 2 files changed, 8 insertions(+), 4 deletions(-) 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)); } }