commentaar methods ivm jump

This commit is contained in:
Leen Dereu
2018-03-07 20:39:28 +01:00
parent 3f87802dd6
commit 1136a8ddf9

View File

@@ -432,9 +432,29 @@ public class Worm {
// region Jump
//===================================================================================
/**
* this constant contains the gravity
*/
private final double G = 5.0;
/**
* this constant contains the duration of the force
*/
private final double FORCE_TIME = 0.5;
/**
* let the worm jump
*
* @post the worm jumps to his new place. The new place is the x-coordinate plus the jump distance
* with the jump velocity
* |Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2)
* @post the current action points schould be 0 after a jump
* |this.points = 0
* @throws IllegalStateException()
* if the current action points is equal to 0 or the orientation is more then
* pi the worm can not jump
* |this.points == 0 || this.orientation < Math.PI
*/
public void jump() {
if (!canJump())
@@ -446,25 +466,63 @@ public class Worm {
this.points = 0;
}
/**
* Return a boolean whether the worm can jump or not
*
* @return True if and only if the action points is bigger then 0 and the orientation
* is lower then pi
* |result == this.points > 0 && this.orientation < Math.PI
*/
private boolean canJump() {
return this.points > 0 && this.orientation < Math.PI;
}
/**
* Return the time the worm will jump
*
* @return the time the worm will jump. The distance divided by the velocity multiplied
* with the cosinus of the orientation
* |jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation))
*/
public double jumpTime() {
return jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation));
}
/**
*
* @param deltaTime
* @return
*/
public Tuple<Double, Double> jumpStep(double deltaTime) {
return Tuple.create(oldLocation.item1 + this.jumpVelocity * Math.cos(this.orientation) * deltaTime,
oldLocation.item2 + this.jumpVelocity * Math.sin(this.orientation) * deltaTime - (1/2) * G * Math.pow(deltaTime, 2));
}
/**
* Return the distance the worm will jump
*
* @param v
* the velocity of the jump
* @return the distance the worm will jump. The distance is equal to the velocity powered by 2 multiplied
* with the sinus of 2 times the orientation en this divided with the gravity
* |(Math.pow(v, 2) * Math.sin(2 * this.orientation)) / this.G
*/
private double jumpDistance(double v) {
return (Math.pow(v, 2) * Math.sin(2 * this.orientation)) / this.G;
}
/**
* Return the velocity of the jump
*
* @return the velocity of the jump. The force of the jump is equal to 5 multiplied with the
* current action points plus the mass multiplied with the gravity. Therefrom the velocity
* is equal to the force divided with the mass, multiplied with the time te force takes
* |force = 5 * this.points + this.mass * G
* |velocity = (force / this.mass) * FORCE_TIME
*/
private double jumpVelocity() {
double force = 5 * this.points + this.mass * G;