Merge branch 'master' of gitlab.principis.be:OGP/worms

This commit is contained in:
2018-04-12 17:25:09 +02:00

View File

@@ -814,11 +814,14 @@ public class Worm extends GameObject {
* @post the current hit points should be substracted with the given value. * @post the current hit points should be substracted with the given value.
* |new.getHitPoints() == old.getHitPoints() - value * |new.getHitPoints() == old.getHitPoints() - value
*/ */
public void incrementHitPoints(long value) { public void decreaseHitPoints(long value) {
setHitPoints(getHitPoints() - value); setHitPoints(getHitPoints() - value);
} }
public void incrementHitPoints(long value) {
setHitPoints(getHitPoints() + value);
}
//=================================================================================== //===================================================================================
// endregion // endregion
@@ -830,30 +833,29 @@ public class Worm extends GameObject {
Coordinate oldLocation = getLocation(); Coordinate oldLocation = getLocation();
double endY = getLocation().getY(); double endY = getLocation().getY();
if (! getWorld().isAdjacent(center, minRadius)) { if (! getWorld().isAdjacent(center, minRadius)) {
for (double y = oldLocation.getY(); y < 0; y--) { for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) {
if (y < 0) { if (y >= (getWorld().getHeight() + 1)) {
terminate(); terminate();
} }
double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc);
if (getWorld().isAdjacent(center, minRadius)) { if (getWorld().isAdjacent(center, minRadius)) {
double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc);
endY = y; endY = y;
break; break;
} }
center[1] = y; center[1] = y;
} }
} }
//TODO hitpoints en eventuele botsing long cost = 3 * (long) Math.floor(oldLocation.getY() - endY);
double distanceY = getWorld().getHeight(); decreaseHitPoints(cost);
long cost = 3 * (long) (oldLocation.getY() - endY);
incrementHitPoints(cost);
} }
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;
fallingWorm.incrementHitPoints(value);
stationaryWorm.decreaseHitPoints(value);
} }
} }