fixes
This commit is contained in:
@@ -507,27 +507,44 @@ public class Worm extends GameObject {
|
||||
World world = getWorld();
|
||||
double step = Math.sqrt(Math.pow(world.getLengthX() * cos(direction), 2) + Math.pow(world.getLengthY() * sin(direction), 2));
|
||||
if (step > radius) step = radius;
|
||||
Coordinate nextLoc, prevLoc;
|
||||
nextLoc = prevLoc = currentLocation;
|
||||
Coordinate nextLoc = currentLocation;
|
||||
|
||||
while(getDistance(currentLocation, nextLoc) < maxDistance) {
|
||||
|
||||
prevLoc = nextLoc;
|
||||
nextLoc = Coordinate.create(round((nextLoc.getX() + step * cos(direction)) * 100.0) / 100.0,
|
||||
nextLoc = Coordinate.create(round((nextLoc.getX() + 0.1 * cos(direction)) * 100.0) / 100.0,
|
||||
round((nextLoc.getY() + step * sin(direction)) * 100.0) / 100.0);
|
||||
if (!world.isPassable(nextLoc.toArray(), radius)) {
|
||||
while (!world.isPassable(nextLoc.toArray(), radius)) {
|
||||
nextLoc = Coordinate.create(round((nextLoc.getX() - 0.1 * cos(direction)) * 10.0) / 10.0,
|
||||
round((nextLoc.getY() - 0.1 * sin(direction)) * 10.0) / 10.0);
|
||||
if (nextLoc.getX() < 0 || nextLoc.getY() < 0) {
|
||||
nextLoc = prevLoc;
|
||||
break;
|
||||
double max = radius * 0.1 + 0.001;
|
||||
while (!world.isAdjacent(nextLoc.toArray(), radius)) {
|
||||
max -= 0.01;
|
||||
nextLoc = Coordinate.create(round((nextLoc.getX() - 0.01 * cos(direction)) * 100.0) / 100.0,
|
||||
round((nextLoc.getY() - 0.01 * sin(direction)) * 100.0) / 100.0);
|
||||
if (max < 0) {
|
||||
return currentLocation;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (getDistance(currentLocation, prevLoc) > getDistance(currentLocation, nextLoc)) return prevLoc;
|
||||
// while(getDistance(currentLocation, nextLoc) < maxDistance) {
|
||||
// nextLoc = Coordinate.create(round((nextLoc.getX() + 0.1 * cos(direction)) * 100.0) / 100.0,
|
||||
// round((nextLoc.getY() + 0.1 * sin(direction)) * 100.0) / 100.0);
|
||||
// if (!world.isPassable(nextLoc.toArray(), radius)) {
|
||||
// break;
|
||||
// }
|
||||
// }
|
||||
// double max = radius * 0.1 + 0.001;
|
||||
// while(!world.isAdjacent(nextLoc.toArray(), radius)) {
|
||||
// max -= 0.01;
|
||||
// if (max < 0) {
|
||||
// nextLoc = currentLocation;
|
||||
// break;
|
||||
// }
|
||||
// nextLoc = Coordinate.create(round((nextLoc.getX() - 0.01 * cos(direction)) * 100.0) / 100.0,
|
||||
// round((nextLoc.getY() - 0.01 * sin(direction)) * 100.0) / 100.0);
|
||||
// }
|
||||
//if (getDistance(currentLocation, prevLoc) > getDistance(currentLocation, nextLoc)) return prevLoc;
|
||||
|
||||
return nextLoc;
|
||||
}
|
||||
|
||||
@@ -537,14 +554,17 @@ public class Worm extends GameObject {
|
||||
double minDirection = direction - 0.7875;
|
||||
double maxDirection = direction + 0.7875;
|
||||
double maxLocDirection = maxDirection;
|
||||
Coordinate maxLoc = getFurthestLocationInDirection(direction, this.getRadius());
|
||||
Coordinate maxLoc = location;
|
||||
for (; minDirection <= maxDirection; minDirection += 0.0175) {
|
||||
Coordinate tempLoc = getFurthestLocationInDirection(minDirection, this.getRadius());
|
||||
if (!getWorld().isAdjacent(tempLoc, getRadius())) tempLoc = location;
|
||||
if (getDistance(location, tempLoc) / Math.abs(direction - minDirection) > getDistance(location, maxLoc) / Math.abs(direction - maxLocDirection)) {
|
||||
maxLoc = tempLoc;
|
||||
maxLocDirection = minDirection;
|
||||
}
|
||||
}
|
||||
|
||||
if (maxLoc.getX() == location.getX() && maxLoc.getY() == location.getY()) return direction;
|
||||
return maxLocDirection;
|
||||
}
|
||||
|
||||
@@ -844,18 +864,18 @@ public class Worm extends GameObject {
|
||||
//===================================================================================
|
||||
|
||||
public void fall() {
|
||||
double heigth = getWorld().getHeight() - getRadius();
|
||||
double height = getWorld().getHeight() - getRadius();
|
||||
Coordinate oldLocation = getLocation();
|
||||
if (canFall()) {
|
||||
for (double y = oldLocation.getY(); y <= heigth; y = y - 0.01) {
|
||||
Coordinate newLoc = Coordinate.create(oldLocation.getX(), y);
|
||||
for (double y = oldLocation.getY(); y < height; y -= 0.01) {
|
||||
Coordinate newLoc = Coordinate.create(oldLocation.getX(), Math.floor(y * 100.0) / 100.0);
|
||||
|
||||
if (!isValidLocation(newLoc)) {
|
||||
if (y - radius < 0) {
|
||||
terminate();
|
||||
break;
|
||||
}
|
||||
|
||||
if (!getWorld().isAdjacent(newLoc, radius)) {
|
||||
if (getWorld().isPassable(newLoc, getRadius())) {
|
||||
setLocation(newLoc);
|
||||
} else {
|
||||
break;
|
||||
|
@@ -70,6 +70,7 @@ public class PartialPart2FacadeTest {
|
||||
Worm worm = facade.createWorm(world, new double[] { 1.5, 2.5 }, 3*Math.PI/2, 0.5, "Test", null);
|
||||
assertFalse(facade.canFall(worm));
|
||||
facade.move(worm);
|
||||
System.out.println(facade.getLocation(worm)[1]);
|
||||
assertTrue(facade.canFall(worm));
|
||||
facade.fall(worm);
|
||||
double[] xy = facade.getLocation(worm);
|
||||
|
Reference in New Issue
Block a user