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

Network
bingor_yhj 2 years ago
parent 1f324369f0
commit 9f0365da6c

@ -31,10 +31,19 @@ public class Bullet extends Frame {
return; return;
} }
Color color = g.getColor(); /*Color color = g.getColor();
g.setColor(Color.RED); g.setColor(Color.RED);
g.fillOval(x, y, WIDTH, HEIGHT); 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(); moving();
} }

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

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

Loading…
Cancel
Save