improved jump

This commit is contained in:
2018-03-07 18:36:21 +01:00
parent d7426ca4f8
commit 83e2ff1638

View File

@@ -1,3 +1,5 @@
import be.kuleuven.cs.som.annotate.*;
public class Worm {
/**
* a class with the specifications of the worm
@@ -13,10 +15,14 @@ public class Worm {
// region properties
//===================================================================================
// Location
private Tuple<Double, Double> location;
// jumping
private Tuple<Double, Double> oldLocation;
private double jumpForce;
private double jumpVelocity;
/**
* this variable contains the orientation of the worm
@@ -361,8 +367,8 @@ public class Worm {
throw new IllegalStateException();
this.oldLocation = this.location;
this.location = Tuple.create(location.item1 + jumpDistance(jumpVelocity()), location.item2);
this.jumpVelocity = jumpVelocity();
this.location = Tuple.create(location.item1 + jumpDistance(this.jumpVelocity), location.item2);
this.points = 0;
}
@@ -372,12 +378,14 @@ public class Worm {
public double jumpTime() {
double v = jumpVelocity();
return jumpDistance(v) / (v * Math.cos(this.orientation));
return jumpDistance(this.jumpVelocity) / (this.jumpVelocity * Math.cos(this.orientation));
}
public double jumpStep() {
return 0.0;
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));
}
private double jumpDistance(double v) {
return (Math.pow(v, 2) * Math.sin(2 * this.orientation)) / this.G;