Documentatie Porjectile
This commit is contained in:
@@ -13,6 +13,26 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
public static final double FORCE_TIME = 0.5;
|
||||
private static final int rho = 7800;
|
||||
|
||||
/**
|
||||
* @param worm
|
||||
* @param mass
|
||||
* @param force
|
||||
*
|
||||
* @post ...
|
||||
* |new.getWorld() == worm.getWorld()
|
||||
* @post ...
|
||||
* |new.getLocation() == calcLocation(worm.getLocation(), worm.getOrientation(), worm.getRadius(), mass)
|
||||
* @post ...
|
||||
* |new.getRadius() == calcRadius(mass)
|
||||
* @post ...
|
||||
* |new.getMass() == mass
|
||||
* @post ...
|
||||
* |new.getForce() == force
|
||||
* @post ...
|
||||
* |new.getOrientation() == worm.getOrientation()
|
||||
* @post ...
|
||||
* |new.getHitPoints() == getRadomHitPoints()
|
||||
*/
|
||||
protected Projectile (Worm worm, double mass, double force) {
|
||||
super(worm.getWorld(), calcLocation(worm.getLocation(), worm.getOrientation(), worm.getRadius(), mass), calcRadius(mass));
|
||||
super.mass = mass;
|
||||
@@ -28,41 +48,69 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
// region radius / orientation / force
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* @return ...
|
||||
* |result == orientation
|
||||
*/
|
||||
public double getOrientation() {
|
||||
return orientation;
|
||||
}
|
||||
|
||||
private final double orientation;
|
||||
|
||||
|
||||
/**
|
||||
* @param mass
|
||||
*
|
||||
* @return ...
|
||||
* |result == pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * PI))), 1.0 / 3.0)
|
||||
*/
|
||||
public static double calcRadius(double mass) {
|
||||
return pow(((mass / 1000.0 / rho) * (3.0 / (4.0 * PI))), 1.0 / 3.0);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ...
|
||||
* |result == this.force
|
||||
*/
|
||||
public double getForce() {
|
||||
return this.force;
|
||||
}
|
||||
|
||||
protected final double force;
|
||||
|
||||
|
||||
|
||||
// ===================================================================================
|
||||
// endregion
|
||||
|
||||
|
||||
// region hitpoints
|
||||
// region hit points
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* @return ...
|
||||
* |result == this.hitPoints
|
||||
*/
|
||||
public int getHitPoints() {
|
||||
return this.hitPoints;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param value
|
||||
*
|
||||
* @post ...
|
||||
* |new.getHitPoints() == this.hitPoints + value
|
||||
*/
|
||||
public void incrementHitPoints(int value) {
|
||||
setHitPoints(this.hitPoints + value);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param worm
|
||||
*
|
||||
* @post ...
|
||||
* |new.worm.getHitPoints() == worm.getHitPoints - getImpactHitPoints()
|
||||
* @post ...
|
||||
* |terminate()
|
||||
*/
|
||||
public void hit(Worm worm){
|
||||
|
||||
worm.decreaseHitPoints(getImpactHitPoints());
|
||||
@@ -83,6 +131,34 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
// region jump
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* @param jumpTimeStep
|
||||
*
|
||||
* @post ...
|
||||
* |double v = jumpVelocity();
|
||||
* |double t = jumpTime(jumpTimeStep);
|
||||
* |double a = getOrientation();
|
||||
* |
|
||||
* |if (!getWorld().isAdjacent(getLocation(),getRadius()))
|
||||
* | newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a),
|
||||
* | getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||
* |newLocation = this.location
|
||||
* @post ...
|
||||
* |if (!isValidLocation(newLocation))
|
||||
* | terminate()
|
||||
* | return
|
||||
* @post ...
|
||||
* |new.getLocation() == newLocation
|
||||
* @post ...
|
||||
* | List<Worm> worms = getWorld().getGameObjectsByClass(Worm.class)
|
||||
* |for (Worm worm: worms)
|
||||
* | if (this.getDistance(worm) < 0)
|
||||
* | setLocation(newLocation)
|
||||
* | hit(worm)
|
||||
*
|
||||
* @throws IllegalStateException ...
|
||||
* |!canJump()
|
||||
*/
|
||||
public void jump(double jumpTimeStep) throws IllegalStateException {
|
||||
if (!canJump())
|
||||
throw new IllegalStateException();
|
||||
@@ -113,7 +189,30 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param timeStep
|
||||
*
|
||||
* @return ...
|
||||
* |World world = getWorld()
|
||||
* |double v = jumpVelocity();
|
||||
* |double time = 0;
|
||||
* |double a = getOrientation();
|
||||
* |double radius = getRadius();
|
||||
* |List<Worm> worms = world.getGameObjectsByClass(Worm.class);
|
||||
* |if (!world.isPassable(this.location) || worms.stream().anyMatch(w -> w.getDistance(this) < 0))
|
||||
* | result == 0.0
|
||||
* |while(true)
|
||||
* | time += timeStep
|
||||
* | Coordinate newLoc = Coordinate.create(this.location.getX() + v * time * cos(a),
|
||||
* | this.location.getY() + v * time * sin(a) - (G * time * time) / 2.0)
|
||||
* | if (newLoc.getX() - radius < 0 || newLoc.getY() - radius < 0 || newLoc.getX() + radius >
|
||||
* | world.getWidth() || newLoc.getY() + radius > world.getHeight() || !world.isPassable(newLoc) ||
|
||||
* | worms.stream().anyMatch(w -> w.getDistance(newLoc, this.radius) < 0))
|
||||
* | result == time
|
||||
*
|
||||
* @throws IllegalStateException ...
|
||||
* |world == null
|
||||
*/
|
||||
public double jumpTime(double timeStep) {
|
||||
World world = getWorld();
|
||||
|
||||
@@ -144,7 +243,18 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param elapsedTime
|
||||
*
|
||||
* @return ...
|
||||
* |double velocity = this.jumpVelocity()
|
||||
* |result == Coordinate.create(getLocation().getX() + velocity * cos(getOrientation()) * elapsedTime,
|
||||
* | getLocation().getY() + velocity * sin(getOrientation()) * elapsedTime - 0.5 * G *
|
||||
* | pow(elapsedTime, 2))
|
||||
*
|
||||
* @throws IllegalArgumentException ...
|
||||
* |Double.isNaN(elapsedTime) || elapsedTime < 0
|
||||
*/
|
||||
public Coordinate jumpStep(double elapsedTime) {
|
||||
if (Double.isNaN(elapsedTime) || elapsedTime < 0)
|
||||
throw new IllegalArgumentException();
|
||||
@@ -155,12 +265,18 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
getLocation().getY() + velocity * sin(getOrientation()) * elapsedTime - 0.5 * G * pow(elapsedTime, 2));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ...
|
||||
* result == getOrientation() < PI
|
||||
*/
|
||||
private boolean canJump() {
|
||||
return getOrientation() < PI;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @return ...
|
||||
* |result == (getForce() / (getMass() / 1000)) * FORCE_TIME
|
||||
*/
|
||||
private double jumpVelocity() {
|
||||
return (getForce() / (getMass() / 1000)) * FORCE_TIME;
|
||||
}
|
||||
@@ -172,6 +288,16 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
// region location
|
||||
//===================================================================================
|
||||
|
||||
/**
|
||||
* @param location
|
||||
*
|
||||
* @return ...
|
||||
* |if (getWorld() == null)
|
||||
* | result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY())
|
||||
* |result == !Double.isNaN(location.getX()) && !Double.isNaN(location.getY()) &&
|
||||
* | !(location.getX() - getRadius() < 0) && !(location.getX() + getRadius() > getWorld().getWidth()) &&
|
||||
* | !(location.getY() + getRadius() > getWorld().getHeight()) && !(location.getY() - getRadius() < 0)
|
||||
*/
|
||||
@Override
|
||||
protected boolean isValidLocation(Coordinate location) {
|
||||
double radius = getRadius();
|
||||
@@ -188,6 +314,17 @@ public abstract class Projectile extends GameObject implements IJumpable {
|
||||
!(location.getY() - radius < 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param wormLocation
|
||||
* @param wormOrientation
|
||||
* @param wormRadius
|
||||
* @param mass
|
||||
*
|
||||
* @return ...
|
||||
* |double radius = calcRadius(mass)
|
||||
* |result == Coordinate.create(wormLocation.getX() + cos(wormOrientation) * (wormRadius + radius),
|
||||
* | wormLocation.getY() + sin(wormOrientation) * (wormRadius + radius))
|
||||
*/
|
||||
public static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
||||
double radius = calcRadius(mass);
|
||||
|
||||
|
Reference in New Issue
Block a user