This commit is contained in:
Leen Dereu
2018-04-13 18:33:04 +02:00
parent c0be2de7c1
commit c069051001

View File

@@ -832,25 +832,29 @@ public class Worm extends GameObject {
//=================================================================================== //===================================================================================
public void fall() { public void fall() {
double[] center = {getLocation().getX(), getLocation().getY()}; double heigth = getWorld().getHeight() - getRadius();
Coordinate oldLocation = getLocation(); Coordinate oldLocation = getLocation();
double endY = getLocation().getY();
if (canFall()) { if (canFall()) {
for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) { for (double y = oldLocation.getY(); y <= heigth; y = y - 0.1) {
if (y >= (getWorld().getHeight() + 1)) {
terminate();
}
double[] newLoc = {oldLocation.getX(), y}; double[] newLoc = {oldLocation.getX(), y};
if (! getWorld().isPassable(newLoc, getRadius())) {
setLocation(newLoc); setLocation(newLoc);
if (! canFall()) {
endY = y;
break; break;
} }
center[1] = y; // for (double i = y; i >= y - 1; i = i - 0.1) {
} // double[] newLocation = {oldLocation.getX(), i};
// if (! getWorld().isPassable(newLocation, getRadius())) {
// setLocation(newLocation);
// endY = i;
// break;
// }
// }
} }
long cost = 3 * (long) Math.floor(oldLocation.getY() - endY); terminate();
}
long cost = 3 * (long) Math.floor(oldLocation.getY() - getLocation().getY());
decreaseHitPoints(cost); decreaseHitPoints(cost);
} }