Jump methods

This commit is contained in:
Leen Dereu
2018-04-13 20:22:15 +02:00
parent 5171f36916
commit 1fff8ee8b9

View File

@@ -666,9 +666,26 @@ public class Worm extends GameObject {
if (!canJump())
throw new IllegalStateException();
setLocation(Coordinate.create( getLocation().getX() + jumpDistance(this.jumpVelocity()), getLocation().getY()));
Coordinate newLocation = Coordinate.create( getLocation().getX() + jumpDistance(this.jumpVelocity()), getLocation().getY());
isNewLocationInWorld(newLocation);
if (! getWorld().isPassable(newLocation) && validJumpDistance(jumpDistance(jumpVelocity())) && ! isTerminated()) {
setLocation(newLocation);
setActionPoints(0);
}
}
/**
*
* @param location
*/
public void isNewLocationInWorld (Coordinate location) {
if (location.getX() - radius < 0 || location.getX() + radius > getWorld().getWidth() ||
location.getY() - radius < 0 || location.getY() + radius > getWorld().getHeight()) {
terminate();
}
}
/**
* Return the time the worm will jump
@@ -734,6 +751,18 @@ public class Worm extends GameObject {
return (pow(v, 2) * sin(2 * getOrientation())) / G;
}
/**
*
* @param distance
* @return
*/
public boolean validJumpDistance(double distance) {
if (distance >= getRadius()) {
return true;
}
return false;
}
/**
* Return the velocity of the jump
*
@@ -749,7 +778,15 @@ public class Worm extends GameObject {
return force / getMass() * FORCE_TIME;
}
public void fight(Worm worm1, Worm... worm2) {
/**
*
* @param newLocation
* @param oldLocation
* @param worm1
* @param worm2
*/
public void fight(Coordinate newLocation, Coordinate oldLocation, Worm worm1, Worm... worm2) {
if (! worm1.isTerminated() && newLocation != oldLocation) {
for (Worm wormB: worm2) {
Worm attackedWorm;
Worm attacker;
@@ -765,9 +802,9 @@ public class Worm extends GameObject {
}
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
attackedWorm.incrementHitPoints(loseAttackedWorm);
attackedWorm.decreaseHitPoints(loseAttackedWorm);
}
}
}