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