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 TNTRectangle(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 TNTRectangle(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 TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
if(o instanceof TNT) {
if(o != this) {
if(((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col - player.getSpeed());
rect = new TNTRectangle(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 TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveTNT");
setChanged();
return true;
}
if(d == Direction.WEST) {
location = new Point(location.row, location.col - player.getSpeed());
rect = new TNTRectangle(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 TNTRectangle(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 TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
if(o instanceof TNT) {
if(o != this) {
if(((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row, location.col + player.getSpeed());
rect = new TNTRectangle(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 TNTRectangle(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 < 30) {
location = new Point(location.row, location.col + player.getSpeed());
rect = new TNTRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveTNT");
setChanged();
return true;
}
if(d == Direction.NORTH) {
location = new Point(location.row - player.getSpeed(), location.col);
rect = new TNTRectangle(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 TNTRectangle(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 TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
if(o instanceof TNT) {
if(o != this) {
if(((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row + player.getSpeed(), location.col);
rect = new TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
}
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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveTNT");
setChanged();
return true;
}
if(d == Direction.SOUTH) {
location = new Point(location.row + player.getSpeed(), location.col);
rect = new TNTRectangle(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 TNTRectangle(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 TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
if(o instanceof TNT) {
if(o != this) {
if(((TNT) o).getRectangle().intersects(rect)) {
location = new Point(location.row - player.getSpeed(), location.col);
rect = new TNTRectangle(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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
}
}
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 TNTRectangle(location.col - 25, location.row - 25);
return false;
}
notifyObservers("moveTNT");
setChanged();
return true;