Jump methods in projectile
This commit is contained in:
@@ -70,7 +70,6 @@ public abstract class Projectile extends GameObject {
|
|||||||
|
|
||||||
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!
|
||||||
// DONE?
|
|
||||||
if (Double.isNaN(elapsedTime) || elapsedTime > this.getJumpTime(elapsedTime) || elapsedTime < 0)
|
if (Double.isNaN(elapsedTime) || elapsedTime > this.getJumpTime(elapsedTime) || elapsedTime < 0)
|
||||||
throw new IllegalArgumentException();
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
@@ -81,17 +80,13 @@ public abstract class Projectile extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private double jumpVelocity() {
|
private double jumpVelocity() {
|
||||||
// wat met de action points?
|
return getForce()/getMass() * FORCE_TIME;
|
||||||
double force = 5 ;//* Worm.getActionPoints() + getMass() * G;
|
|
||||||
return force/getMass() * FORCE_TIME;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private double getJumpTime(double jumpTimeStep) {
|
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 v = jumpVelocity();
|
||||||
double time = 0;
|
double time = jumpTimeStep;
|
||||||
double a = getOrientation();
|
double a = getOrientation();
|
||||||
Coordinate loc = getLocation();
|
Coordinate loc = getLocation();
|
||||||
World world = getWorld();
|
World world = getWorld();
|
||||||
@@ -123,31 +118,36 @@ public abstract class Projectile extends GameObject {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private boolean canJump() {
|
private boolean canJump() {
|
||||||
// wat met action points.
|
return getOrientation() < PI;
|
||||||
//return this.getActionPoints() > 0 && getOrientation() < PI;
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void jump() throws IllegalStateException {
|
public void jump(double jumpTimeStep) throws IllegalStateException {
|
||||||
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
// TODO zie naar worm hoe dit moet, implementatie moet wel anders!
|
||||||
// wat meegeven met getJumpTime() ?
|
|
||||||
// wat met action points?
|
|
||||||
|
|
||||||
if (!canJump())
|
if (!canJump())
|
||||||
throw new IllegalStateException();
|
throw new IllegalStateException();
|
||||||
|
|
||||||
double v = jumpVelocity();
|
double v = jumpVelocity();
|
||||||
double t = 0;//getJumpTime();
|
double t = getJumpTime(jumpTimeStep);
|
||||||
double a = getOrientation();
|
double a = getOrientation();
|
||||||
|
Coordinate newLocation;
|
||||||
|
|
||||||
Coordinate newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
|
||||||
|
//TODO extra parameter if: als de worm die wil schieten tegen een andere worm staat
|
||||||
|
//
|
||||||
|
//In case the initial position of a projectile already hits impassable terrain or a worm, the projectile will
|
||||||
|
//jump over a distance of 0.0 m.
|
||||||
|
if (getWorld().isAdjacent(getLocation(),getRadius())) {
|
||||||
|
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||||
|
}
|
||||||
|
|
||||||
if (! isValidLocation(newLocation)) {
|
if (! isValidLocation(newLocation)) {
|
||||||
terminate();
|
terminate();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
setLocation(newLocation);
|
setLocation(newLocation);
|
||||||
//Worm.setActionPoints(0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
||||||
|
Reference in New Issue
Block a user