errors fixen

This commit is contained in:
Leen Dereu
2018-05-22 15:38:40 +02:00
parent 63cabe27fc
commit ed6be5d2b8
2 changed files with 18 additions and 13 deletions

View File

@@ -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;
@@ -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;
}
@@ -128,21 +129,28 @@ public abstract class Projectile extends GameObject {
double a = getOrientation();
Coordinate newLocation;
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);
}
}
//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.
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) {

View File

@@ -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) {