day3,子弹发射位置改至坦克中间

master
zhanxinlin 3 years ago
parent 96e195961c
commit 3cd93dc1ee

@ -9,8 +9,8 @@ import java.awt.*;
*/ */
public class Bullet { public class Bullet {
private static final int SPEED = 10; private static final int SPEED = 10;
private static final int WIDTH = 20; public static int WIDTH = ResourceImageRead.BULLET_DOWN.getWidth();
private static final int HEIGHT = 20; public static int HEIGHT = ResourceImageRead.BULLET_DOWN.getHeight();
private int x; private int x;
private int y; private int y;

@ -9,6 +9,9 @@ import java.awt.*;
*/ */
public class Tank { public class Tank {
private static final int SPEED = 5; private static final int SPEED = 5;
public static int WIDTH = ResourceImageRead.TANK_DOWN.getWidth();
public static int HEIGHT = ResourceImageRead.TANK_DOWN.getHeight();
private int x; private int x;
private int y; private int y;
private Direction direction; private Direction direction;
@ -79,8 +82,11 @@ public class Tank {
* FrameTank * FrameTank
*/ */
public void fire() { public void fire() {
int bulletX = this.x + Tank.WIDTH / 2 - Bullet.WIDTH / 2;
int bulletY = this.y + Tank.HEIGHT / 2 - Bullet.HEIGHT / 2;
// 将子弹加入子弹集合 // 将子弹加入子弹集合
frameTank.bulletList.add(new Bullet(this.x, this.y, this.direction, this.frameTank)); frameTank.bulletList.add(new Bullet(bulletX, bulletY, this.direction, this.frameTank));
} }
public Direction getDirection() { public Direction getDirection() {

Loading…
Cancel
Save