坦克大战(一期)-画出一个爆炸

Network
bingor_yhj 2 years ago
parent 4a687543fa
commit afd0aaf2f4

@ -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;
}
}

@ -14,6 +14,7 @@ public class ResourcesMgr {
public static BufferedImage tankL, tankR, tankU, tankD; public static BufferedImage tankL, tankR, tankU, tankD;
public static BufferedImage bulletL, bulletR, bulletU, bulletD; public static BufferedImage bulletL, bulletR, bulletU, bulletD;
public static BufferedImage [] explodeImages = new BufferedImage[16];
static { static {
try { try {
@ -26,6 +27,10 @@ public class ResourcesMgr {
bulletR = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif")); bulletR = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif"));
bulletU = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif")); bulletU = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif"));
bulletD = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletD.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) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }

@ -18,6 +18,7 @@ import java.util.Objects;
public class TankFrame extends Frame { public class TankFrame extends Frame {
Tank myTank = new Tank(100, 500, DirEnum.RIGHT, GroupEnum.GOOD, this); 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); // Bullet bullet = new Bullet(200, 200, DirEnum.DOWN);
List<Bullet> bullets = new ArrayList<>(); List<Bullet> bullets = new ArrayList<>();
List<Tank> tanks = new ArrayList<>(); //敌方坦克 List<Tank> tanks = new ArrayList<>(); //敌方坦克
@ -54,6 +55,8 @@ public class TankFrame extends Frame {
g.setColor(color); g.setColor(color);
myTank.paint(g); myTank.paint(g);
explode.paint(g);
//画出敌方坦克 //画出敌方坦克
for (int i=0; i<tanks.size(); i++) { for (int i=0; i<tanks.size(); i++) {
tanks.get(i).paint(g); tanks.get(i).paint(g);

Loading…
Cancel
Save