This commit is contained in:
Leen Dereu
2018-04-16 21:29:24 +02:00
2 changed files with 11 additions and 14 deletions

View File

@@ -3,9 +3,6 @@ package worms.model;
import worms.util.Coordinate;
import java.util.*;
import java.util.stream.Collectors;
import org.omg.PortableServer.ServantActivatorOperations;
public class World {
@@ -191,7 +188,7 @@ public class World {
double length = lengthX;
if (lengthX > lengthY) length = lengthY;
return isPassable(center, radius) && !isPassable(center, radius + maxDistance + 0.001);
return isPassable(center, radius) && !isPassable(center, radius + maxDistance + 0.00001);
}
public double getLengthX() {

View File

@@ -566,7 +566,7 @@ public class Worm extends GameObject {
double direction = getOrientation();
double minDirection = direction - 0.7875;
double maxDirection = direction + 0.7875;
double maxLocDirection = maxDirection;
double maxLocDirection = minDirection;
Coordinate maxLoc = location;
for (; minDirection <= maxDirection; minDirection += 0.0175) {
Coordinate tempLoc = getFurthestLocationInDirection(minDirection, this.getRadius());
@@ -1037,44 +1037,44 @@ public class Worm extends GameObject {
World world = getWorld();
Coordinate location = getLocation();
if (!world.isPassable(location, radius)) {
if (!world.isAdjacent(location, radius)) {
Coordinate newLoc = Coordinate.create(location.getX() + changeRadius, location.getY());
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX() - changeRadius, location.getY());
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX(), location.getY() - changeRadius);
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX(), location.getY() + changeRadius);
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX() - changeRadius, location.getY() - changeRadius);
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX() + changeRadius, location.getY() + changeRadius);
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX() + changeRadius, location.getY() - changeRadius);
if (world.isPassable(newLoc, radius)) {
if (world.isAdjacent(newLoc, radius)) {
setLocation(newLoc);
return;
}
newLoc = Coordinate.create(location.getX() - changeRadius, location.getY() + changeRadius);
if (!world.isPassable(newLoc, radius)) {
if (!world.isAdjacent(newLoc, radius)) {
terminate();
return;
}