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.
* |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
@@ -830,30 +833,29 @@ public class Worm extends GameObject {
Coordinate oldLocation = getLocation();
double endY = getLocation().getY();
if (! getWorld().isAdjacent(center, minRadius)) {
for (double y = oldLocation.getY(); y < 0; y--) {
if (y < 0) {
terminate();
}
for (double y = oldLocation.getY(); y <= (getWorld().getHeight() + 1); y--) {
if (y >= (getWorld().getHeight() + 1)) {
terminate();
}
double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc);
if (getWorld().isAdjacent(center, minRadius)) {
double[] newLoc = {oldLocation.getX(), y};
setLocation(newLoc);
endY = y;
break;
}
center[1] = y;
}
}
//TODO hitpoints en eventuele botsing
double distanceY = getWorld().getHeight();
long cost = 3 * (long) (oldLocation.getY() - endY);
incrementHitPoints(cost);
long cost = 3 * (long) Math.floor(oldLocation.getY() - 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);
}
}