canFall in Worm en Facade

This commit is contained in:
Leen Dereu
2018-04-12 17:34:18 +02:00
parent afbdd5a88e
commit f9a13b9cfd
2 changed files with 8 additions and 3 deletions

View File

@@ -120,7 +120,7 @@ public class Facade implements IFacade {
*/ */
@Override @Override
public boolean canFall(Worm worm) throws MustNotImplementException { public boolean canFall(Worm worm) throws MustNotImplementException {
return false; return worm.canFall();
} }
/** /**

View File

@@ -832,14 +832,14 @@ public class Worm extends GameObject {
double[] center = {getLocation().getX(), getLocation().getY()}; double[] center = {getLocation().getX(), getLocation().getY()};
Coordinate oldLocation = getLocation(); Coordinate oldLocation = getLocation();
double endY = getLocation().getY(); double endY = getLocation().getY();
if (! getWorld().isAdjacent(center, minRadius)) { if (canFall()) {
for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) { for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) {
if (y >= (getWorld().getHeight() + 1)) { if (y >= (getWorld().getHeight() + 1)) {
terminate(); terminate();
} }
double[] newLoc = {oldLocation.getX(), y}; double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc); setLocation(newLoc);
if (getWorld().isAdjacent(center, minRadius)) { if (! canFall()) {
endY = y; endY = y;
break; break;
} }
@@ -851,6 +851,11 @@ public class Worm extends GameObject {
decreaseHitPoints(cost); decreaseHitPoints(cost);
} }
public boolean canFall() {
double[] center = {getLocation().getX(), getLocation().getY()};
return ! getWorld().isAdjacent(center, minRadius);
}
public void collisionFall(Worm fallingWorm, Worm... worm) { public void collisionFall(Worm fallingWorm, Worm... worm) {
for (Worm stationaryWorm: worm) { for (Worm stationaryWorm: worm) {
long value = stationaryWorm.getHitPoints()/2; long value = stationaryWorm.getHitPoints()/2;