|
|
@ -19,20 +19,21 @@ import com.msb.model.abstracts.GameObject;
|
|
|
|
*/
|
|
|
|
*/
|
|
|
|
public class BulletTankCollider implements Collider {
|
|
|
|
public class BulletTankCollider implements Collider {
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void collide(GameObject o1, GameObject o2) {
|
|
|
|
public boolean collide(GameObject o1, GameObject o2) {
|
|
|
|
if(o1 instanceof Bullet && o2 instanceof Tank) {
|
|
|
|
if(o1 instanceof Bullet && o2 instanceof Tank) {
|
|
|
|
Bullet bullet = (Bullet) o1;
|
|
|
|
Bullet bullet = (Bullet) o1;
|
|
|
|
Tank tank = (Tank) o2;
|
|
|
|
Tank tank = (Tank) o2;
|
|
|
|
if(bullet.getGroup() == tank.getGroup()) return;
|
|
|
|
if(bullet.getGroup() == tank.getGroup()) return true; //没有撞继续执行
|
|
|
|
|
|
|
|
|
|
|
|
if(bullet.getRectangle().intersects(tank.getRectangle())) {
|
|
|
|
if(bullet.getRectangle().intersects(tank.getRectangle())) {
|
|
|
|
bullet.die();
|
|
|
|
bullet.die();
|
|
|
|
tank.die();
|
|
|
|
tank.die();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false; //撞上就不再向下执行了
|
|
|
|
} else if (o1 instanceof Tank && o2 instanceof Bullet) {
|
|
|
|
} else if (o1 instanceof Tank && o2 instanceof Bullet) {
|
|
|
|
collide(o2, o1);
|
|
|
|
return collide(o2, o1);
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|