diff --git a/OGP1718-Worms/src/worms/model/Worm.java b/OGP1718-Worms/src/worms/model/Worm.java index c762b52..8c6de5e 100644 --- a/OGP1718-Worms/src/worms/model/Worm.java +++ b/OGP1718-Worms/src/worms/model/Worm.java @@ -807,11 +807,14 @@ public class Worm extends GameObject { * @post the current hit points should be substracted with the given value. * |new.getHitPoints() == old.getHitPoints() - value */ - public void incrementHitPoints(long value) { + public void decreaseHitPoints(long value) { setHitPoints(getHitPoints() - value); } - + public void incrementHitPoints(long value) { + setHitPoints(getHitPoints() + value); + } + //=================================================================================== // endregion @@ -823,13 +826,13 @@ public class Worm extends GameObject { Coordinate oldLocation = getLocation(); double endY = getLocation().getCoordinateY(); if (! getWorld().isAdjacent(center, minRadius)) { - for (double y = oldLocation.getCoordinateY(); y < 0; y--) { - if (y < 0) { + for (double y = oldLocation.getCoordinateY(); y <= (getWorld().getHeight() + 1); y--) { + if (y >= (getWorld().getHeight() + 1)) { terminate(); } + double[] newLoc = {oldLocation.getCoordinateX(), y}; + setLocation(newLoc); if (getWorld().isAdjacent(center, minRadius)) { - double[] newLoc = {oldLocation.getCoordinateX(), y}; - setLocation(newLoc); endY = y; break; } @@ -837,16 +840,15 @@ public class Worm extends GameObject { } } - //TODO hitpoints en eventuele botsing - double distanceY = getWorld().getHeight(); - - long cost = 3 * (long) (oldLocation.getCoordinateY() - endY); - incrementHitPoints(cost); + long cost = 3 * (long) Math.floor(oldLocation.getCoordinateY() - endY); + decreaseHitPoints(cost); } public void collisionFall(Worm fallingWorm, Worm... worm) { for (Worm stationaryWorm: worm) { - + long value = stationaryWorm.getHitPoints()/2; + fallingWorm.incrementHitPoints(value); + stationaryWorm.decreaseHitPoints(value); } }