From 9f0365da6c4cb18d2a789284f3ebe895e2fcd14a Mon Sep 17 00:00:00 2001 From: bingor_yhj Date: Mon, 3 Oct 2022 13:00:44 +0800 Subject: [PATCH] =?UTF-8?q?=E5=9D=A6=E5=85=8B=E5=A4=A7=E6=88=98(=E4=B8=80?= =?UTF-8?q?=E6=9C=9F)-=E5=B0=86=E5=AD=90=E5=BC=B9=E6=8D=A2=E6=88=90?= =?UTF-8?q?=E5=9B=BE=E7=89=87?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/com/msb/Bullet.java | 13 +++++++++++-- src/com/msb/ResourcesMgr.java | 6 ++++++ src/com/msb/TankFrame.java | 5 +++-- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/com/msb/Bullet.java b/src/com/msb/Bullet.java index 12083bf..3c6dd49 100644 --- a/src/com/msb/Bullet.java +++ b/src/com/msb/Bullet.java @@ -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(); } diff --git a/src/com/msb/ResourcesMgr.java b/src/com/msb/ResourcesMgr.java index 9e2caff..d17efae 100644 --- a/src/com/msb/ResourcesMgr.java +++ b/src/com/msb/ResourcesMgr.java @@ -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(); } diff --git a/src/com/msb/TankFrame.java b/src/com/msb/TankFrame.java index 9163f89..f5d37ca 100644 --- a/src/com/msb/TankFrame.java +++ b/src/com/msb/TankFrame.java @@ -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);