diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/PathNode.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/PathNode.java index 6aa3badd..5b587bf9 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/PathNode.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/PathNode.java @@ -7,6 +7,7 @@ public class PathNode extends Entity { public transient short playerSmell = 0; public short weight = 0; + public boolean nodeEnabled = true; private transient Array connections = new Array(); private transient Array jumps = new Array(); @@ -82,7 +83,7 @@ public void walk(int iteration, PathNode previous) { // normal connections for (int i = 0; i < connections.size; i++) { PathNode node = connections.get(i); - if(node != previous) { + if(node != previous && node.nodeEnabled) { node.walk(iteration, this); } } @@ -94,4 +95,10 @@ public void reset() { playerSmell = Short.MAX_VALUE; } } + + public void setEnabled(boolean isEnabled) { + synchronized (this) { + this.nodeEnabled = isEnabled; + } + } } diff --git a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredElevator.java b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredElevator.java index fdc37e05..0fc86b78 100644 --- a/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredElevator.java +++ b/Dungeoneer/src/com/interrupt/dungeoneer/entities/triggers/TriggeredElevator.java @@ -8,7 +8,9 @@ import com.interrupt.dungeoneer.collision.Collision; import com.interrupt.dungeoneer.entities.AmbientSound; import com.interrupt.dungeoneer.entities.Entity; +import com.interrupt.dungeoneer.entities.PathNode; import com.interrupt.dungeoneer.entities.items.Weapon; +import com.interrupt.dungeoneer.game.Game; import com.interrupt.dungeoneer.game.Level; import com.interrupt.dungeoneer.gfx.WorldChunk; import com.interrupt.dungeoneer.tiles.Tile; @@ -56,6 +58,8 @@ public enum ReturnType { AUTO, WAITS } protected float deltaBuffer = 0; protected ElevatorState state = ElevatorState.NONE; + protected float amountFloorMovedSinceStart = 0; + public TriggeredElevator() { hidden = true; spriteAtlas = "editor"; tex = 11; selfDestructs = false; } private transient Array entitiesToMoveCache = new Array<>(); @@ -265,12 +269,13 @@ else if(state == ElevatorState.RETURNING) // Move the trigger as much as the floor, so that a touch could trigger it again z += floorMoveAmount; + amountFloorMovedSinceStart += floorMoveAmount; // Done with the cache entitiesToMoveCache.clear(); // The world changed here, retesselate - markWorldAsDirty(); + markWorldAsDirty(level); } } @@ -307,7 +312,7 @@ private void adjustWorldTiles(Level level, float thisMoveAmount) { } } - private void markWorldAsDirty() { + private void markWorldAsDirty(Level level) { // Mark this area as dirty to force world Tesselation here int minX = (int)Math.floor(x - collision.x); int maxX = (int)Math.ceil(x + collision.x); @@ -321,6 +326,17 @@ private void markWorldAsDirty() { markWorldAsDirty(tileX - 1, tileY); markWorldAsDirty(tileX, tileY + 1); markWorldAsDirty(tileX, tileY - 1); + + // Stop pathfinding to this tile if it has moved too much + Tile t = level.getTileOrNull(tileX, tileY); + if(t == null) + continue; + + PathNode n = Game.pathfinding.GetNodeAt(tileX + 0.5f, tileY + 0.5f, t.floorHeight); + if(n == null) + continue; + + n.setEnabled(!t.blockMotion && Math.abs(amountFloorMovedSinceStart) < 0.5f); } } }