Merge branch 'master' of gitlab.principis.be:OGP/worms
This commit is contained in:
@@ -1,5 +1,7 @@
|
|||||||
package worms.model;
|
package worms.model;
|
||||||
|
|
||||||
|
import static java.lang.Math.*;
|
||||||
|
|
||||||
import worms.util.Coordinate;
|
import worms.util.Coordinate;
|
||||||
|
|
||||||
public abstract class Projectile extends GameObject {
|
public abstract class Projectile extends GameObject {
|
||||||
@@ -17,7 +19,7 @@ public abstract class Projectile extends GameObject {
|
|||||||
|
|
||||||
|
|
||||||
public static double calcRadius(double mass) {
|
public static double calcRadius(double mass) {
|
||||||
return Math.pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * Math.PI))), 1.0 / 3.0);
|
return pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * PI))), 1.0 / 3.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getForce() {
|
public double getForce() {
|
||||||
@@ -63,19 +65,88 @@ public abstract class Projectile extends GameObject {
|
|||||||
!getWorld().isAdjacent(location, radius));
|
!getWorld().isAdjacent(location, radius));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static final double G = 5.0;
|
||||||
|
|
||||||
|
public static final double FORCE_TIME = 0.5;
|
||||||
|
|
||||||
public Coordinate getJumpStep(double elapsedTime) {
|
public Coordinate getJumpStep(double elapsedTime) {
|
||||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
return null;
|
// DONE?
|
||||||
|
if (Double.isNaN(elapsedTime) || elapsedTime > this.getJumpTime(elapsedTime) || elapsedTime < 0)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
double velocity = this.jumpVelocity();
|
||||||
|
|
||||||
|
return Coordinate.create(getLocation().getX() + velocity * cos(getOrientation()) * elapsedTime,
|
||||||
|
getLocation().getY() + velocity * sin(getOrientation()) * elapsedTime - 0.5 * G * pow(elapsedTime, 2) );
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getJumpTime(double jumpTimeStep) {
|
private double jumpVelocity() {
|
||||||
|
//wat met de action points?
|
||||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
double force = 5 * Worm.getActionPoints() + getMass() * G;
|
||||||
return 0.0;
|
return force/getMass() * FORCE_TIME;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jump() {
|
private double getJumpTime(double jumpTimeStep) {
|
||||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
|
//wat met parameter jumpTimeStep?
|
||||||
|
|
||||||
|
double v = jumpVelocity();
|
||||||
|
double time = 0;
|
||||||
|
double a = getOrientation();
|
||||||
|
Coordinate loc = getLocation();
|
||||||
|
World world = getWorld();
|
||||||
|
double radius = getRadius();
|
||||||
|
Coordinate newLoc;
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
time += 0.05;
|
||||||
|
double x = loc.getX() + v * time * cos(a);
|
||||||
|
double y = loc.getY() + v * time * sin(a) - (G * time * time) / 2.0;
|
||||||
|
newLoc = Coordinate.create(x, y);
|
||||||
|
if (! world.isPassable(newLoc, radius) || x < 0 || y < 0 || x > world.getWidth() || y > world.getHeight()) {
|
||||||
|
while (true) {
|
||||||
|
time -= 0.01;
|
||||||
|
newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (G * time * time) / 2.0);
|
||||||
|
if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
|
||||||
|
newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
if ((int) round(time) == 10) {
|
||||||
|
throw new RuntimeException();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return time;
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean canJump() {
|
||||||
|
// wat met action points.
|
||||||
|
return Worm.getActionPoints() > 0 && getOrientation() < PI;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void jump() throws IllegalStateException {
|
||||||
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
|
// wat meegeven met getJumpTime() ?
|
||||||
|
// wat met action points?
|
||||||
|
|
||||||
|
if (!canJump())
|
||||||
|
throw new IllegalStateException();
|
||||||
|
|
||||||
|
double v = jumpVelocity();
|
||||||
|
double t = getJumpTime();
|
||||||
|
double a = getOrientation();
|
||||||
|
|
||||||
|
Coordinate newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||||
|
|
||||||
|
if (! isValidLocation(newLocation)) {
|
||||||
|
terminate();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
setLocation(newLocation);
|
||||||
|
Worm.setActionPoints(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
@@ -1211,7 +1211,6 @@ public class Worm extends GameObject {
|
|||||||
// TODO We gaan maar 1 hit function gebruiken
|
// TODO We gaan maar 1 hit function gebruiken
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// ===================================================================================
|
// ===================================================================================
|
||||||
// endregion
|
// endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user