diff --git a/src/com/msb/Explode.java b/src/com/msb/Explode.java new file mode 100644 index 0000000..d74336c --- /dev/null +++ b/src/com/msb/Explode.java @@ -0,0 +1,41 @@ +package com.msb; + +import java.awt.*; + +/** + * @Author bingor + * @Date 2022-09-29 21:53 + * @Description: com.msb + * @Version: 1.0 + */ +public class Explode { + + private int x,y; + private TankFrame tankFrame; + public static final int WIDTH = ResourcesMgr.explodeImages[0].getWidth(); + public static final int HEIGHT = ResourcesMgr.explodeImages[0].getHeight(); +// private boolean live = true; + private int step = 0; + + public Explode(int x, int y, TankFrame tankFrame) { + this.x = x; + this.y = y; + this.tankFrame = tankFrame; + } + + public void paint(Graphics g) { + + g.drawImage(ResourcesMgr.explodeImages[step++], x, y, null); + if(step >= ResourcesMgr.explodeImages.length) step = 0; + + } + + public int getX() { + return x; + } + + public int getY() { + return y; + } + +} diff --git a/src/com/msb/ResourcesMgr.java b/src/com/msb/ResourcesMgr.java index d17efae..4e73a48 100644 --- a/src/com/msb/ResourcesMgr.java +++ b/src/com/msb/ResourcesMgr.java @@ -14,6 +14,7 @@ public class ResourcesMgr { public static BufferedImage tankL, tankR, tankU, tankD; public static BufferedImage bulletL, bulletR, bulletU, bulletD; + public static BufferedImage [] explodeImages = new BufferedImage[16]; static { try { @@ -26,6 +27,10 @@ public class ResourcesMgr { bulletR = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif")); bulletU = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif")); bulletD = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletD.gif")); + + for (int i=1; i<=explodeImages.length ; i++) { + explodeImages[i-1] = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/e" + i + ".gif")); + } } catch (IOException e) { e.printStackTrace(); } diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java index 7d91473..958fb83 100644 --- a/src/com/msb/TankFrame.java +++ b/src/com/msb/TankFrame.java @@ -18,6 +18,7 @@ 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); // Bullet bullet = new Bullet(200, 200, DirEnum.DOWN); List bullets = new ArrayList<>(); List tanks = new ArrayList<>(); //敌方坦克 @@ -54,6 +55,8 @@ public class TankFrame extends Frame { g.setColor(color); myTank.paint(g); + explode.paint(g); + //画出敌方坦克 for (int i=0; i