子弹位置

master
kn5886348135 3 years ago
parent b7505d7bff
commit 1c269829e6

@ -5,7 +5,8 @@ import java.awt.Graphics;
public class Bullet { public class Bullet {
private static final int SPEED = 1; 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 int x, y;
private Dir dir; private Dir dir;
@ -38,7 +39,7 @@ public class Bullet {
default: default:
break; break;
} }
move(); move();
} }

@ -8,6 +8,9 @@ public class Tank {
private Dir dir = Dir.DOWN; private Dir dir = Dir.DOWN;
private static final int SPEED = 5; 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 boolean moving = false;
private TankFrame tf = null; private TankFrame tf = null;
@ -79,6 +82,8 @@ public class Tank {
} }
public void fire(){ 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