From afd0aaf2f4b91e5ac77832926d002d900b871d65 Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Tue, 4 Oct 2022 18:31:58 +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)-=E7=94=BB=E5=87=BA=E4=B8=80=E4=B8=AA=E7=88=86?= =?UTF-8?q?=E7=82=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/Explode.java | 41 +++++++++++++++++++++++++++++++++++ src/com/msb/ResourcesMgr.java | 5 +++++ src/com/msb/TankFrame.java | 3 +++ 3 files changed, 49 insertions(+) create mode 100644 src/com/msb/Explode.java 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