Skip to content

Commit

Permalink
Elevators can disable their path nodes when moved too much
Browse files Browse the repository at this point in the history
  • Loading branch information
Interrupt committed Oct 14, 2020
1 parent c3f2278 commit cb3d04e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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<PathNode> connections = new Array<PathNode>();
private transient Array<PathNode> jumps = new Array<PathNode>();
Expand Down Expand Up @@ -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);
}
}
Expand All @@ -94,4 +95,10 @@ public void reset() {
playerSmell = Short.MAX_VALUE;
}
}

public void setEnabled(boolean isEnabled) {
synchronized (this) {
this.nodeEnabled = isEnabled;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<Entity> entitiesToMoveCache = new Array<>();
Expand Down Expand Up @@ -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);
}
}

Expand Down Expand Up @@ -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);
Expand All @@ -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);
}
}
}
Expand Down

0 comments on commit cb3d04e

Please sign in to comment.