子弹位置

master
kn5886348135 3 years ago
parent b7505d7bff
commit 1c269829e6

@ -5,7 +5,8 @@ import java.awt.Graphics;
public class Bullet {
private static final int SPEED = 1;
private static final int WIDTH = 30, HEIGHT = 30;
public static final int WIDTH = ResourceMgr.bulletD.getWidth();
public static final int HEIGHT = ResourceMgr.bulletD.getHeight();
private int x, y;
private Dir dir;

@ -8,6 +8,9 @@ public class Tank {
private Dir dir = Dir.DOWN;
private static final int SPEED = 5;
private static final int WIDTH = ResourceMgr.tankD.getWidth();
private static final int HEIGHT = ResourceMgr.tankD.getHeight();
private boolean moving = false;
private TankFrame tf = null;
@ -79,6 +82,8 @@ public class Tank {
}
public void fire(){
tf.bullets.add(new Bullet(this.x, this.y, this.dir, this.tf));
int bX = this.x + Tank.WIDTH >> 1 - Bullet.WIDTH >> 1;
int bY = this.y + Tank.HEIGHT >> 1 - Bullet.HEIGHT >> 1;
tf.bullets.add(new Bullet(bX, bY, this.dir, this.tf));
}
}

Loading…
Cancel
Save