渲染爆炸

master
kn5886348135 3 years ago
parent 90d7c933ba
commit 5334cb5391

@ -0,0 +1,29 @@
package com.example.tankbattle;
import java.awt.*;
public class Explode {
public static int WIDTH = ResourceMgr.explodes[0].getWidth();
public static int HEIGHT = ResourceMgr.explodes[0].getHeight();
private int x, y;
private boolean living = true;
TankFrame tf = null;
private int step = 0;
public Explode(int x, int y, TankFrame tf) {
this.x = x;
this.y = y;
this.tf = tf;
}
public void paint(Graphics g) {
g.drawImage(ResourceMgr.explodes[step++], x, y, null);
if (step >= ResourceMgr.explodes.length)
step = 0;
}
}

@ -7,6 +7,7 @@ import javax.imageio.ImageIO;
public class ResourceMgr {
public static BufferedImage tankL, tankU, tankR, tankD;
public static BufferedImage bulletL, bulletU,bulletR, bulletD;
public static BufferedImage[] explodes = new BufferedImage[16];
static {
try {
@ -19,6 +20,7 @@ public class ResourceMgr {
bulletU = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletU.gif"));
bulletR = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletR.gif"));
bulletD = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/bulletD.gif"));
for (int i = 0; i < 16; i++) explodes[i] = ImageIO.read(ResourceMgr.class.getClassLoader().getResourceAsStream("images/e" + (i + 1) + ".gif"));
} catch (IOException e) {
e.printStackTrace();
}

@ -81,7 +81,7 @@ public class Tank {
break;
}
if (random.nextInt(10) > 5) this.fire();
if (random.nextInt(10) > 8) this.fire();
}
public void paint(Graphics g) {

@ -17,6 +17,8 @@ public class TankFrame extends Frame {
List<Bullet> bullets = new ArrayList<>();
List<Tank> tanks = new ArrayList<>();
Explode e = new Explode(100, 100, this);
static final int GAME_WIDTH = 800,GAME_HEIGHT=600;
public TankFrame() {
@ -69,6 +71,8 @@ public class TankFrame extends Frame {
for (int j = 0; j < tanks.size(); j++)
bullets.get(i).collideWith(tanks.get(j));
}
e.paint(g);
// for (Iterator<Bullet> it = bullets.iterator(); it.hasNext()) {
// Bullet b = it.next();
// if (!b.live) it.remove();

Loading…
Cancel
Save