LinkedList<PlayerTank> players = map.getPlayers();
LinkedList<EnemyTank> enemies = map.getEnemies();
if (d == Direction.EAST) {
location = new Point(location.row, location.col + player.getSpeed());
rect = new CrateRectangle(location.col - 25, location.row - 25);
for (int i = 0; i < players.size(); i++) {
PlayerTank p = players.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
- player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
for (int i = 0; i < enemies.size(); i++) {
EnemyTank p = enemies.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
- player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
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
- player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
- player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof SpikePit) {
if (((SpikePit) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
}
}
if (o instanceof Crate) {
if (o != this) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
- player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
}
if (o instanceof FireRing) {
if (((FireRing) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
break;
}
}
}
if (location.col > 955) {
location = new Point(location.row, location.col
- player.getSpeed());
rect = new CrateRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveCrate");
setChanged();
}
if (d == Direction.WEST) {
location = new Point(location.row, location.col - player.getSpeed());
rect = new CrateRectangle(location.col - 25, location.row - 25);
for (int i = 0; i < players.size(); i++) {
PlayerTank p = players.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
for (int i = 0; i < enemies.size(); i++) {
EnemyTank p = enemies.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
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
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof Crate) {
if (o != this) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
}
if (o instanceof SpikePit) {
if (((SpikePit) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
}
}
if (o instanceof FireRing) {
if (((FireRing) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
break;
}
}
}
if (location.col < 30) {
location = new Point(location.row, location.col
+ player.getSpeed());
rect = new CrateRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveCrate");
setChanged();
}
if (d == Direction.NORTH) {
location = new Point(location.row - player.getSpeed(), location.col);
rect = new CrateRectangle(location.col - 25, location.row - 25);
for (int i = 0; i < players.size(); i++) {
PlayerTank p = players.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row + player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
for (int i = 0; i < enemies.size(); i++) {
EnemyTank p = enemies.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row + player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
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 + player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row + player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof Crate) {
if (o != this) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row
+ player.getSpeed(), location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
}
if (o instanceof SpikePit) {
if (((SpikePit) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
}
}
if (o instanceof FireRing) {
if (((FireRing) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
break;
}
}
}
if (location.row < 30) {
location = new Point(location.row + player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveCrate");
setChanged();
}
if (d == Direction.SOUTH) {
location = new Point(location.row + player.getSpeed(), location.col);
rect = new CrateRectangle(location.col - 25, location.row - 25);
for (int i = 0; i < players.size(); i++) {
PlayerTank p = players.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row - player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
for (int i = 0; i < enemies.size(); i++) {
EnemyTank p = enemies.get(i);
if (p.getRectangle().intersects(rect)) {
location = new Point(location.row - player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
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 - player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof TNT) {
if (((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row - player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
if (o instanceof Crate) {
if (o != this) {
if (((Crate) o).getRectangle().intersects(rect)) {
location = new Point(location.row
- player.getSpeed(), location.col);
rect = new CrateRectangle(location.col - 25,
location.row - 25);
return false;
}
}
}
if (o instanceof SpikePit) {
if (((SpikePit) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
notifyObservers(new Point(location.row - 12,
location.col - 12));
setChanged();
}
}
if (o instanceof FireRing) {
if (((FireRing) o).getRectangle().intersects(rect)) {
this.recieveDamage(1);
break;
}
}
}
if (location.row > 665) {
location = new Point(location.row - player.getSpeed(),
location.col);
rect = new CrateRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveCrate");
setChanged();