Fall method
This commit is contained in:
@@ -807,10 +807,13 @@ 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
|
||||||
@@ -823,13 +826,13 @@ public class Worm extends GameObject {
|
|||||||
Coordinate oldLocation = getLocation();
|
Coordinate oldLocation = getLocation();
|
||||||
double endY = getLocation().getCoordinateY();
|
double endY = getLocation().getCoordinateY();
|
||||||
if (! getWorld().isAdjacent(center, minRadius)) {
|
if (! getWorld().isAdjacent(center, minRadius)) {
|
||||||
for (double y = oldLocation.getCoordinateY(); y < 0; y--) {
|
for (double y = oldLocation.getCoordinateY(); y <= (getWorld().getHeight() + 1); y--) {
|
||||||
if (y < 0) {
|
if (y >= (getWorld().getHeight() + 1)) {
|
||||||
terminate();
|
terminate();
|
||||||
}
|
}
|
||||||
|
double[] newLoc = {oldLocation.getCoordinateX(), y};
|
||||||
|
setLocation(newLoc);
|
||||||
if (getWorld().isAdjacent(center, minRadius)) {
|
if (getWorld().isAdjacent(center, minRadius)) {
|
||||||
double[] newLoc = {oldLocation.getCoordinateX(), y};
|
|
||||||
setLocation(newLoc);
|
|
||||||
endY = y;
|
endY = y;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -837,16 +840,15 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO hitpoints en eventuele botsing
|
long cost = 3 * (long) Math.floor(oldLocation.getCoordinateY() - endY);
|
||||||
double distanceY = getWorld().getHeight();
|
decreaseHitPoints(cost);
|
||||||
|
|
||||||
long cost = 3 * (long) (oldLocation.getCoordinateY() - 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user