|
|
|
@ -11,6 +11,7 @@ public class Bullet {
|
|
|
|
|
private boolean live = true;
|
|
|
|
|
private Group group = Group.BAD;
|
|
|
|
|
private TankFrameV4 tf;
|
|
|
|
|
Rectangle rect = new Rectangle();
|
|
|
|
|
|
|
|
|
|
public Bullet(int x, int y, Direction direction, Group group, TankFrameV4 tf) {
|
|
|
|
|
this.x = x;
|
|
|
|
@ -18,6 +19,11 @@ public class Bullet {
|
|
|
|
|
this.direction = direction;
|
|
|
|
|
this.group = group;
|
|
|
|
|
this.tf = tf;
|
|
|
|
|
|
|
|
|
|
rect.x = this.x;
|
|
|
|
|
rect.y = this.y;
|
|
|
|
|
rect.width = Bullet.WIDTH;
|
|
|
|
|
rect.height = Bullet.HEIGHT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void paint(Graphics g){
|
|
|
|
@ -57,15 +63,15 @@ public class Bullet {
|
|
|
|
|
if(x < 0 || y < 0 || x > TankFrameV4.GAME_WIDTH || y > TankFrameV4.GAME_HEIGHT){
|
|
|
|
|
live = false;
|
|
|
|
|
}
|
|
|
|
|
rect.x = this.x;
|
|
|
|
|
rect.y = this.y;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//检测是否跟坦克碰撞
|
|
|
|
|
public void collideWith(Tank tank){
|
|
|
|
|
//关闭队友伤害
|
|
|
|
|
if(this.group == tank.getGroup()) return;
|
|
|
|
|
Rectangle bulletRect = new Rectangle(x, y, WIDTH, HEIGHT);
|
|
|
|
|
Rectangle tankRect = new Rectangle(tank.getX(), tank.getY(), Tank.WIDTH, Tank.HEIGHT);
|
|
|
|
|
if(bulletRect.intersects(tankRect)){
|
|
|
|
|
if(rect.intersects(tank.rect)){
|
|
|
|
|
tank.die();
|
|
|
|
|
this.die();
|
|
|
|
|
//爆炸
|
|
|
|
|