mirror of
https://github.com/OMGeeky/andors-trail.git
synced 2026-01-22 11:25:35 +01:00
Merge branch 'master' into stoutford_tests
This commit is contained in:
@@ -52,17 +52,17 @@ public final class MonsterMovementController implements EvaluateWalkable {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean monsterCanMoveTo(final PredefinedMap map, final LayeredTileMap tilemap, final CoordRect p) {
|
||||
public static boolean monsterCanMoveTo(final Monster movingMonster, final PredefinedMap map, final LayeredTileMap tilemap, final CoordRect p) {
|
||||
if (tilemap != null) {
|
||||
if (!tilemap.isWalkable(p)) return false;
|
||||
}
|
||||
if (map.getMonsterAt(p) != null) return false;
|
||||
if (map.getMonsterAt(p, movingMonster) != null) return false;
|
||||
|
||||
for (MapObject m : map.eventObjects) {
|
||||
if (m == null) continue;
|
||||
if (!m.isActive) continue;
|
||||
if (!m.position.intersects(p)) continue;
|
||||
switch (m.type) {
|
||||
for (MapObject mObj : map.eventObjects) {
|
||||
if (mObj == null) continue;
|
||||
if (!mObj.isActive) continue;
|
||||
if (!mObj.position.intersects(p)) continue;
|
||||
switch (mObj.type) {
|
||||
case newmap:
|
||||
case keyarea:
|
||||
case rest:
|
||||
@@ -90,7 +90,7 @@ public final class MonsterMovementController implements EvaluateWalkable {
|
||||
} else {
|
||||
determineMonsterNextPosition(m, area, world.model.player.position);
|
||||
|
||||
if (!monsterCanMoveTo(map, tileMap, m.nextPosition)) {
|
||||
if (!monsterCanMoveTo(m, map, tileMap, m.nextPosition)) {
|
||||
cancelCurrentMonsterMovement(m);
|
||||
return;
|
||||
}
|
||||
@@ -155,7 +155,7 @@ public final class MonsterMovementController implements EvaluateWalkable {
|
||||
|
||||
@Override
|
||||
public boolean isWalkable(CoordRect r) {
|
||||
return monsterCanMoveTo(world.model.currentMap, world.model.currentTileMap, r);
|
||||
return monsterCanMoveTo(null, world.model.currentMap, world.model.currentTileMap, r);
|
||||
}
|
||||
|
||||
public void moveMonsterToNextPosition(final Monster m, final PredefinedMap map) {
|
||||
|
||||
@@ -64,7 +64,7 @@ public final class MonsterSpawningController {
|
||||
p.topLeft.set(
|
||||
area.topLeft.x + Constants.rnd.nextInt(area.size.width)
|
||||
,area.topLeft.y + Constants.rnd.nextInt(area.size.height));
|
||||
if (!MonsterMovementController.monsterCanMoveTo(map, tileMap, p)) continue;
|
||||
if (!MonsterMovementController.monsterCanMoveTo(null, map, tileMap, p)) continue;
|
||||
if (playerPosition != null && p.contains(playerPosition)) continue;
|
||||
return p.topLeft;
|
||||
}
|
||||
|
||||
@@ -108,11 +108,13 @@ public final class PredefinedMap {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public Monster getMonsterAt(final CoordRect p) {
|
||||
return getMonsterAt(p, null);
|
||||
}
|
||||
public Monster getMonsterAt(final CoordRect p, Monster exceptMe) {
|
||||
for (MonsterSpawnArea a : spawnAreas) {
|
||||
Monster m = a.getMonsterAt(p);
|
||||
if (m != null) return m;
|
||||
if (m != null && (exceptMe == null || exceptMe != m)) return m;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -92,4 +92,24 @@ public final class CoordRect {
|
||||
|
||||
return new CoordRect(new Coord(x, y), new Size(w, h));
|
||||
}
|
||||
|
||||
public static CoordRect getBoundingRect(Coord c1, Coord c2, Size s) {
|
||||
int x, y, w, h;
|
||||
if (c2.x < c1.x) {
|
||||
x = c2.x;
|
||||
w = 1 + c1.x - c2.x;
|
||||
} else {
|
||||
x = c1.x;
|
||||
w = 1 + c2.x - c1.x;
|
||||
}
|
||||
if (c2.y < c1.y) {
|
||||
y = c2.y;
|
||||
h = 1 + c1.y - c2.y;
|
||||
} else {
|
||||
y = c1.y;
|
||||
h = 1 + c2.y - c1.y;
|
||||
}
|
||||
|
||||
return new CoordRect(new Coord(x, y), new Size(w + s.width - 1, h + s.height - 1));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -844,12 +844,12 @@ public final class MainView extends SurfaceView
|
||||
|
||||
@Override
|
||||
public void onNewSpriteMoveFrame(SpriteMoveAnimation animation) {
|
||||
redrawMoveArea_(CoordRect.getBoundingRect(animation.origin, animation.destination), animation);
|
||||
redrawMoveArea_(CoordRect.getBoundingRect(animation.origin, animation.destination, animation.actor.tileSize), animation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSpriteMoveCompleted(SpriteMoveAnimation animation) {
|
||||
redrawArea(CoordRect.getBoundingRect(animation.origin, animation.destination), RedrawAreaDebugReason.EffectCompleted);
|
||||
redrawArea(CoordRect.getBoundingRect(animation.origin, animation.destination, animation.actor.tileSize), RedrawAreaDebugReason.EffectCompleted);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Reference in New Issue
Block a user