坦克大战(一期)-将子弹换成图片

Network
bingor_yhj 2 years ago
parent 1f324369f0
commit 9f0365da6c

@ -31,10 +31,19 @@ public class Bullet extends Frame {
return;
}
Color color = g.getColor();
/*Color color = g.getColor();
g.setColor(Color.RED);
g.fillOval(x, y, WIDTH, HEIGHT);
g.setColor(color); //还原画笔原来的颜色
g.setColor(color);*/ //还原画笔原来的颜色
switch (dir) {
case UP: g.drawImage(ResourcesMgr.bulletU, x, y, null); break;
case DOWN: g.drawImage(ResourcesMgr.bulletD, x, y, null); break;
case LEFT: g.drawImage(ResourcesMgr.bulletL, x, y, null); break;
case RIGHT: g.drawImage(ResourcesMgr.bulletR, x, y, null); break;
default: break;
}
moving();
}

@ -13,6 +13,7 @@ import java.io.IOException;
public class ResourcesMgr {
public static BufferedImage tankL, tankR, tankU, tankD;
public static BufferedImage bulletL, bulletR, bulletU, bulletD;
static {
try {
@ -20,6 +21,11 @@ public class ResourcesMgr {
tankR = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/tankR.gif"));
tankU = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/tankU.gif"));
tankD = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/tankD.gif"));
bulletL = ImageIO.read(ResourcesMgr.class.getClassLoader().getResourceAsStream("images/bulletL.gif"));
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"));
} catch (IOException e) {
e.printStackTrace();
}

@ -29,6 +29,7 @@ public class TankFrame extends Frame {
setSize(GAME_WIDTH, GAME_HEIGHT);
setResizable(true);
setVisible(true);
setBackground(Color.BLACK);
addWindowListener(new WindowAdapter() {
@Override
@ -46,7 +47,7 @@ public class TankFrame extends Frame {
public void paint(Graphics g) {
// super.paint(g);
Color color = g.getColor();
g.setColor(Color.BLACK);
g.setColor(Color.WHITE);
g.drawString("子弹的数量:" + bullets.size(), 10, 60);
g.setColor(color);
tank.paint(g);
@ -65,7 +66,7 @@ public class TankFrame extends Frame {
}
Graphics gOffScreen = offScreenImage.getGraphics();
Color color = gOffScreen.getColor();
gOffScreen.setColor(Color.WHITE);
gOffScreen.setColor(Color.BLACK);
gOffScreen.fillRect(0, 0, GAME_WIDTH, GAME_HEIGHT);
gOffScreen.setColor(color);
paint(gOffScreen);

Loading…
Cancel
Save