Jump methods
This commit is contained in:
@@ -666,9 +666,26 @@ public class Worm extends GameObject {
|
|||||||
if (!canJump())
|
if (!canJump())
|
||||||
throw new IllegalStateException();
|
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);
|
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
|
* Return the time the worm will jump
|
||||||
@@ -734,6 +751,18 @@ public class Worm extends GameObject {
|
|||||||
return (pow(v, 2) * sin(2 * getOrientation())) / G;
|
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
|
* Return the velocity of the jump
|
||||||
*
|
*
|
||||||
@@ -749,7 +778,15 @@ public class Worm extends GameObject {
|
|||||||
return force / getMass() * FORCE_TIME;
|
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) {
|
for (Worm wormB: worm2) {
|
||||||
Worm attackedWorm;
|
Worm attackedWorm;
|
||||||
Worm attacker;
|
Worm attacker;
|
||||||
@@ -765,9 +802,9 @@ public class Worm extends GameObject {
|
|||||||
}
|
}
|
||||||
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
|
double N = 10 * ceil((attacker.getRadius())/(attackedWorm.getRadius()));
|
||||||
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
long loseAttackedWorm = (long) rand.nextInt((((int) N) - 1) + 1) + 1;
|
||||||
attackedWorm.incrementHitPoints(loseAttackedWorm);
|
attackedWorm.decreaseHitPoints(loseAttackedWorm);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user