// Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
// on the object it has collided with the proper action will occur.
if (o instanceof EnemyTank) {
EnemyTank p = (EnemyTank) o;
TankRectangle rect = p.getRectangle();
// When the EnemyTank collides with an item it will activate the item's effect on that EnemyTank
for (Item i : itemList) {
if (i instanceof BubbleShield) {
BubbleShield c = (BubbleShield) i;
if (c.getRectangle().intersects(p.getRectangle())) {
// Can not have more than one BubbleShield active at a time
if (p.getHealth() == 1) {
c.activateEffect(p);
}
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
if (i instanceof SpeedBoost) {
SpeedBoost c = (SpeedBoost) i;
if (c.getRectangle().intersects(p.getRectangle())) {
c.activateEffect(p);
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
if (i instanceof IceBlock) {
IceBlock c = (IceBlock) i;
if (c.getRectangle().intersects(p.getRectangle())) {
c.activateEffect(p);
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
}
for (Obstacle obs : obstacleList) {
// This tank will push the crate if the crate is movable
if (obs instanceof Crate) {
Crate c = (Crate) obs;
if (rect.intersects(c.getRectangle())) {
c.move(tankList.getFirst().getDirection());
}
}
// This tank will push the TNT if the TNT is movable
if (obs instanceof TNT) {
TNT c = (TNT) obs;
if (rect.intersects(c.getRectangle())) {
c.move(tankList.getFirst().getDirection());
}
}
// FireRing's can not kill the AI for difficulty purposes
if (obs instanceof FireRing) {
FireRing c = (FireRing) obs;
if (rect.intersects(c.getRectangle())) {
p.recieveDamage(1);
notifyObservers();
setChanged();
}
}
// SpikePit's can not kill the AI either for difficulty purposes
if (obs instanceof SpikePit) {
SpikePit c = (SpikePit) obs;
if (rect.intersects(c.getRectangle())) {
p.recieveDamage(1);
notifyObservers();
setChanged();
}
}
}
notifyObservers();
setChanged();
}
// Whenever the EnemyTank moves this will check to see if it has collided with anything. Depeding
// on the object it has collided with the proper action will occur.
if (o instanceof PlayerTank) {
PlayerTank p = (PlayerTank) o;
TankRectangle rect = p.getRectangle();
for (Item i : itemList) {
// Only one BubbleShield can be active at a time
if (i instanceof BubbleShield) {
BubbleShield c = (BubbleShield) i;
if (c.getRectangle().intersects(p.getRectangle())) {
if (p.getHealth() == 1) {
c.activateEffect(p);
}
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
if (i instanceof SpeedBoost) {
SpeedBoost c = (SpeedBoost) i;
if (c.getRectangle().intersects(p.getRectangle())) {
if(!p.isActiveBoost()) {
c.activateEffect(p);
}
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
if (i instanceof IceBlock) {
IceBlock c = (IceBlock) i;
if (c.getRectangle().intersects(p.getRectangle())) {
c.activateEffect(p);
itemList.remove(c);
notifyObservers();
setChanged();
break;
}
}
}
for (Obstacle obs : obstacleList) {
// The PlayerTank will push the crate if it is movable
if (obs instanceof Crate) {
Crate c = (Crate) obs;
if (rect.intersects(c.getRectangle())) {
c.move(tankList.getFirst().getDirection());
}
}
// The PlayerTank will push the TNT if it is movable
if (obs instanceof TNT) {
TNT c = (TNT) obs;
if (rect.intersects(c.getRectangle())) {
c.move(tankList.getFirst().getDirection());
}
}
// If the PlayerTank collides with a FireRing it will die
if (obs instanceof FireRing) {
FireRing c = (FireRing) obs;
if (rect.intersects(c.getRectangle())) {
notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
p.recieveDamage(1);
}
}
// If the PlayerTank collides with a SpikePit it will die
if (obs instanceof SpikePit) {
SpikePit c = (SpikePit) obs;
if (rect.intersects(c.getRectangle())) {
notifyObservers(new Point(p.getLocation().row - 12, p.getLocation().col - 12));
p.recieveDamage(1);
}
}
}
notifyObservers();