if(enemies.size() != 0) {
enemy = enemies.getFirst();
}
if (d == Direction.EAST) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
if(enemy.getHuman() != 0) {
if(enemy.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
for (int i = 0; i < obs.size(); i++) {
Obstacle o = obs.get(i);
if (o instanceof ImmovableBlock) {
if (((ImmovableBlock) o).getRectangle()
.intersects(rect)) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof Crate) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof FireRing) {
if (o != this) {
if (((FireRing) o).getRectangle().intersects(rect)) {
location = new Point(location.row,
location.col - 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
}
}
if (location.col > 955) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
moveable = true;
notifyObservers(this);
setChanged();
}
if (d == Direction.WEST) {
location = new Point(location.row, location.col - 1);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
if(enemy.getHuman() != 0) {
if(enemy.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
for (int i = 0; i < obs.size(); i++) {
Obstacle o = obs.get(i);
if(o instanceof ImmovableBlock) {
if(((ImmovableBlock) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof Crate) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof FireRing) {
if (o != this) {
if (((FireRing) o).getRectangle().intersects(rect)) {
location = new Point(location.row,
location.col + 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
}
}
if (location.col < 30) {
location = new Point(location.row, location.col + 1);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
moveable = true;
notifyObservers(this);
setChanged();
}
if (d == Direction.NORTH) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
if(enemy.getHuman() != 0) {
if(enemy.getRectangle().intersects(rect)) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
for (int i = 0; i < obs.size(); i++) {
Obstacle o = obs.get(i);
if(o instanceof ImmovableBlock) {
if(((ImmovableBlock) o).getRectangle().intersects(rect)) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if(o instanceof Crate) {
if(((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
if(o instanceof FireRing) {
if(o != this) {
if(((FireRing) o).getRectangle().intersects(rect)) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
}
}
if (location.row < 30) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
moveable = true;
notifyObservers(this);
setChanged();
}
if (d == Direction.SOUTH) {
location = new Point(location.row + 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
if(enemy.getHuman() != 0) {
if(enemy.getRectangle().intersects(rect)) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
for (int i = 0; i < obs.size(); i++) {
Obstacle o = obs.get(i);
if(o instanceof ImmovableBlock) {
if(((ImmovableBlock) o).getRectangle().intersects(rect)) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25, location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof Crate) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
if (o instanceof FireRing) {
if (o != this) {
if (((FireRing) o).getRectangle().intersects(rect)) {
location = new Point(location.row - 1,
location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
}
}
}
if (location.row > 665) {
location = new Point(location.row - 1, location.col);
rect = new FireRingRectangle(location.col - 25,
location.row - 25);
moveable = false;
return false;
}
notifyObservers(this);