public boolean moveDown() {
LinkedList<Obstacle> obs = map.getObstacles();
LinkedList<EnemyTank> enemies = map.getEnemies();
d = Direction.SOUTH;
p = new Point(p.row + this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
if (health == 1) {
img = new ImageIcon("images/tankSOUTH.png").getImage();
}
if (health == 2) {
img = new ImageIcon("images/tankShieldSOUTH.png").getImage();
}
if (activeIceBlock) {
img = new ImageIcon("images/tankFrozenSOUTH.png").getImage();
}
for (int i = 0; i < enemies.size(); i++) {
EnemyTank e = enemies.get(i);
if (e.getRectangle().intersects(t)) {
p = new Point(p.row - this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
System.out.println("stopped at enemy");
return false;
}
}
for (int i = 0; i < obs.size(); i++) {
Obstacle o = obs.get(i);
if (o instanceof ImmovableBlock) {
ImmovableBlock b = (ImmovableBlock) o;
if (b.getRectangle().intersects(t)) {
p = new Point(p.row - this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
System.out.println("stopped at obs");
return false;
}
}
if (o instanceof Crate) {
Crate c = (Crate) o;
if (c.getRectangle().intersects(t)) {
if (!c.move(d)) {
p = new Point(p.row - this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
System.out.println("stopped at crate");
return false;
}
}
}
if (o instanceof TNT) {
TNT c = (TNT) o;
if (c.getRectangle().intersects(t)) {
if (!c.move(d)) {
p = new Point(p.row - this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
System.out.println("stopped at crate");
return false;
}
}
}
}
if (p.row > 665) {
p = new Point(p.row - this.speed, p.col);
t = new TankRectangle(p.col - 25, p.row - 25);
System.out.println("stopped at row");
return false;
}
notifyObservers(this);
setChanged();