From 99c37fe372acb88cf82c0b5f6ddda616f20d1ecb Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Tue, 4 Oct 2022 18:55:56 +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)-=E6=8A=8A=E7=88=86=E7=82=B8=E6=94=BE=E5=9C=A8?= =?UTF-8?q?=E5=9D=A6=E5=85=8B=E8=A2=AB=E6=89=93=E6=AD=BB=E7=9A=84=E4=BD=8D?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/Explode.java | 5 ++++- src/com/msb/Tank.java | 3 ++- src/com/msb/TankFrame.java | 10 ++++++++-- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/com/msb/Explode.java b/src/com/msb/Explode.java index d74336c..45e03d9 100644 --- a/src/com/msb/Explode.java +++ b/src/com/msb/Explode.java @@ -26,7 +26,10 @@ public class Explode { public void paint(Graphics g) { g.drawImage(ResourcesMgr.explodeImages[step++], x, y, null); - if(step >= ResourcesMgr.explodeImages.length) step = 0; + if(step >= ResourcesMgr.explodeImages.length) { + step = 0; + tankFrame.explodes.remove(this); + } } diff --git a/src/com/msb/Tank.java b/src/com/msb/Tank.java index 9599d05..242f6a0 100644 --- a/src/com/msb/Tank.java +++ b/src/com/msb/Tank.java @@ -13,7 +13,7 @@ public class Tank { private int x,y; private DirEnum dir; - private static final int SPEED = 5; + private static final int SPEED = 2; private boolean move = true; //为了解决能够在坦克中发射子弹,将创建的子弹通过坦克发射出来,那么需要在坦克类中持有游戏窗口的引用 private TankFrame tankFrame; @@ -93,6 +93,7 @@ public class Tank { public void die() { this.live = false; + tankFrame.explodes.add(new Explode(this.x, this.y, tankFrame)); } public GroupEnum getGroup() { diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java index 958fb83..2edf76d 100644 --- a/src/com/msb/TankFrame.java +++ b/src/com/msb/TankFrame.java @@ -18,10 +18,11 @@ import java.util.Objects; public class TankFrame extends Frame { Tank myTank = new Tank(100, 500, DirEnum.RIGHT, GroupEnum.GOOD, this); - Explode explode = new Explode(100, 100, this); +// Explode explode = new Explode(100, 100, this); // Bullet bullet = new Bullet(200, 200, DirEnum.DOWN); List bullets = new ArrayList<>(); List tanks = new ArrayList<>(); //敌方坦克 + List explodes = new ArrayList<>(); //爆炸效果 public static final int GAME_WIDTH = 800; public static final int GAME_HEIGHT = 600; @@ -55,7 +56,7 @@ public class TankFrame extends Frame { g.setColor(color); myTank.paint(g); - explode.paint(g); +// explode.paint(g); //画出敌方坦克 for (int i=0; i