坦克大战(一期)-把爆炸放在坦克被打死的位置

Network
bingor_yhj 2 years ago
parent afd0aaf2f4
commit 99c37fe372

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

@ -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() {

@ -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<Bullet> bullets = new ArrayList<>();
List<Tank> tanks = new ArrayList<>(); //敌方坦克
List<Explode> 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<tanks.size(); i++) {
@ -72,6 +73,11 @@ public class TankFrame extends Frame {
}
}
//爆炸效果
for (int i=0; i<explodes.size(); i++) {
explodes.get(i).paint(g);
}
}
//双缓冲,解决闪烁现象

Loading…
Cancel
Save