|
|
|
@ -7,6 +7,9 @@ public class Bullet {
|
|
|
|
|
private static final int SPEED = 6;
|
|
|
|
|
public static int WIDTH = ResourceMgr.bulletD.getWidth();
|
|
|
|
|
public static int HEIGHT = ResourceMgr.bulletD.getHeight();
|
|
|
|
|
|
|
|
|
|
private Rectangle rect = new Rectangle();
|
|
|
|
|
|
|
|
|
|
private int x, y;
|
|
|
|
|
private Dir dir;
|
|
|
|
|
|
|
|
|
@ -20,6 +23,11 @@ public class Bullet {
|
|
|
|
|
this.dir = dir;
|
|
|
|
|
this.group = group;
|
|
|
|
|
this.tf = tf;
|
|
|
|
|
|
|
|
|
|
rect.x = this.x;
|
|
|
|
|
rect.y = this.y;
|
|
|
|
|
rect.width = WIDTH;
|
|
|
|
|
rect.height = HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public Group getGroup() {
|
|
|
|
@ -73,14 +81,15 @@ public class Bullet {
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rect.x = this.x;
|
|
|
|
|
rect.y = this.y;
|
|
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x > TankFrame.GAME_WIDTH || y > TankFrame.GAME_HEIGHT) living = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void collideWith(Tank tank){
|
|
|
|
|
if (this.group == tank.getGroup()) return;
|
|
|
|
|
Rectangle rect1 = new Rectangle(this.x, this.y, WIDTH, HEIGHT);
|
|
|
|
|
Rectangle rect2 = new Rectangle(tank.getX(), tank.getY(), Tank.WIDTH, Tank.HEIGHT);
|
|
|
|
|
if (rect1.intersects(rect2)) {
|
|
|
|
|
if (this.rect.intersects(tank.rect)) {
|
|
|
|
|
tank.die();
|
|
|
|
|
this.die();
|
|
|
|
|
int eX = tank.getX() + Tank.WIDTH / 2 - Explode.WIDTH / 2;
|
|
|
|
|