errors fixen
This commit is contained in:
@@ -4,6 +4,8 @@ import static java.lang.Math.*;
|
||||
|
||||
import worms.util.Coordinate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public abstract class Projectile extends GameObject {
|
||||
|
||||
private static final int rho = 7800;
|
||||
@@ -71,7 +73,7 @@ public abstract class Projectile extends GameObject {
|
||||
public Coordinate getJumpStep(double elapsedTime) {
|
||||
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,
|
||||
@@ -79,7 +81,7 @@ public abstract class Projectile extends GameObject {
|
||||
}
|
||||
|
||||
private double jumpVelocity() {
|
||||
return getForce()/getMass() * FORCE_TIME;
|
||||
return (getForce()/getMass()) * FORCE_TIME;
|
||||
}
|
||||
|
||||
public double getJumpTime(double jumpTimeStep) {
|
||||
@@ -94,12 +96,12 @@ public abstract class Projectile extends GameObject {
|
||||
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;
|
||||
double y = loc.getY() + v * time * sin(a) - (0.5 * G * time * time);
|
||||
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);
|
||||
newLoc = Coordinate.create(loc.getX() + v * time * cos(a), loc.getY() + v * time * sin(a) - (0.5 * G * time * time));
|
||||
if (newLoc.getX() < 0 || newLoc.getY() < 0 || newLoc.getX() > getWorld().getWidth() ||
|
||||
newLoc.getY() > world.getHeight() || world.isAdjacent(newLoc, radius)) {
|
||||
break;
|
||||
@@ -111,7 +113,6 @@ public abstract class Projectile extends GameObject {
|
||||
throw new RuntimeException();
|
||||
}
|
||||
}
|
||||
|
||||
return time;
|
||||
}
|
||||
|
||||
@@ -127,22 +128,29 @@ public abstract class Projectile extends GameObject {
|
||||
double t = getJumpTime(jumpTimeStep);
|
||||
double a = getOrientation();
|
||||
Coordinate newLocation;
|
||||
|
||||
|
||||
//TODO In case the initial position of a projectile already hits impassable terrain or a worm, the projectile will
|
||||
//TODO jump over a distance of 0.0 m.
|
||||
List<Worm> worms = getWorld().getGameObjectsByClass(Worm.class);
|
||||
|
||||
for (Worm worm: worms) {
|
||||
if (this.getDistance(worm) < 0) {
|
||||
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
||||
setLocation(newLocation);
|
||||
}
|
||||
}
|
||||
|
||||
if (getWorld().isAdjacent(getLocation(),getRadius())) {
|
||||
newLocation = Coordinate.create(getLocation().getX(), getLocation().getY());
|
||||
setLocation(newLocation);
|
||||
}
|
||||
else {
|
||||
else{
|
||||
newLocation = Coordinate.create(getLocation().getX() + v * t * cos(a), getLocation().getY() + v * t * sin(a) - (G * t * t) / 2.0);
|
||||
setLocation(newLocation);
|
||||
}
|
||||
|
||||
if (! isValidLocation(newLocation)) {
|
||||
terminate();
|
||||
return;
|
||||
}
|
||||
setLocation(newLocation);
|
||||
}
|
||||
|
||||
private static Coordinate calcLocation(Coordinate wormLocation, double wormOrientation, double wormRadius, double mass) {
|
||||
|
@@ -1226,9 +1226,6 @@ public class Worm extends GameObject {
|
||||
|
||||
public Projectile fire() {
|
||||
if (canFire()) {
|
||||
|
||||
//TODO location overlaps with 1 or more projectiles => firing worm is hit by one overlapping projectile
|
||||
//TODO => method returns null
|
||||
if (! getWorld().getGameObjectsByClass(Projectile.class).isEmpty()) {
|
||||
List<Projectile> projectiles = getWorld().getGameObjectsByClass(Projectile.class);
|
||||
for (Projectile project: projectiles) {
|
||||
|
Reference in New Issue
Block a user