Package org.rspeer.game.coord.collision
Class LocalCollision
- java.lang.Object
-
- org.rspeer.game.coord.collision.LocalCollision
-
public class LocalCollision extends Object
Provides high-level collision and reachability utilities for determining whether tiles or scene nodes near the local player can be walked to or interacted with.Definitions
Walkable
A tile is considered walkable if the local player can pathfind to that tile using normal movement rules:- The tile is not collision-blocked (objects, walls, floor blockers).
- The tile is part of the local player's flood-filled reachable region.
- Diagonal and directional blocking rules are respected.
Interactable
A tile or scene node is considered interactable if the player can stand on at least one valid adjacent walkable tile and interact from there. Interactable does not require the target tile to be walkable itself. For example:- A wall object occupies its tile (not walkable) but is still interactable.
- A large object may be interactable from some sides but not others.
- Doors, chests, and NPCs are often interactable without the tile itself being walkable.
Purpose
This class consolidates collision checking, reachability tracking, and interactability logic into a simple interface used by pathfinding, targeting, object interaction, and movement systems.
-
-
Constructor Summary
Constructors Constructor Description LocalCollision()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static CoordgetInteractableCoord(SceneNode node)Attempts to find a tile the player can stand on in order to interact with the given scene node.static CoordgetInteractableCoord(Coord coord)Finds a walkable tile from which the player can interact with the given coordinate.static Set<Coord>getWalkableCoords()Returns a snapshot of all locally reachable tiles according to the most recent flood-fill computation.static booleanisEntityAreaWalkable(SceneNode node)Determines whether any tile occupied by the given scene node is walkable from the local player's current position.static booleanisEntityAreaWalkable(LocalReachability reachability, Coord src, SceneNode target)Determines whether any coordinate within the node'sCoordAreais walkable from the given source location.static booleanisInteractable(SceneNode node)Determines whether the given scene node is interactable from at least one walkable position around it.static booleanisInteractable(Coord coord)Returns whether the given coordinate is interactable, meaning that a walkable tile exists from which the player can interact with it.static booleanisWalkable(LocalReachability reachability, Coord src, Coord target)Core reachability check.static booleanisWalkable(Coord coord)Returns whether the given coordinate is walkable from the local player's current position.
-
-
-
Method Detail
-
isEntityAreaWalkable
public static boolean isEntityAreaWalkable(SceneNode node)
Determines whether any tile occupied by the given scene node is walkable from the local player's current position. Useful for large multi-tile entities.- Parameters:
node- the scene node to test- Returns:
trueif at least one tile of the node is walkable
-
isEntityAreaWalkable
public static boolean isEntityAreaWalkable(LocalReachability reachability, Coord src, SceneNode target)
Determines whether any coordinate within the node'sCoordAreais walkable from the given source location.- Parameters:
reachability- reachability map to usesrc- source coordinate (usually player's location)target- the scene node- Returns:
trueif any node tile is walkable
-
isWalkable
public static boolean isWalkable(Coord coord)
Returns whether the given coordinate is walkable from the local player's current position.- Parameters:
coord- the tile to test- Returns:
trueif tile is reachable and not blocked
-
isWalkable
public static boolean isWalkable(LocalReachability reachability, Coord src, Coord target)
Core reachability check. A tile is reachable if:- It is not collision-blocked.
- It lies within the player's flood-filled reachable region.
- Parameters:
reachability- cached reachability mapsrc- source coordinatetarget- the coordinate to test- Returns:
trueif the tile is reachable
-
getInteractableCoord
public static Coord getInteractableCoord(SceneNode node)
Attempts to find a tile the player can stand on in order to interact with the given scene node. This is useful for multi-tile objects or objects with blocked tiles inside their footprint.- Parameters:
node- the object/NPC/scene node to interact with- Returns:
- the first walkable tile that allows interaction, or
nullif none exist
-
getInteractableCoord
public static Coord getInteractableCoord(Coord coord)
Finds a walkable tile from which the player can interact with the given coordinate. If the tile itself is walkable, it is returned directly. Otherwise adjacent cardinal tiles are tested using collision-aware movement rules.- Parameters:
coord- the target coordinate- Returns:
- a walkable adjacent tile suitable for interaction, or
nullif none exist
-
isInteractable
public static boolean isInteractable(SceneNode node)
Determines whether the given scene node is interactable from at least one walkable position around it.- Parameters:
node- the scene node- Returns:
trueif any tile of the node is interactable
-
isInteractable
public static boolean isInteractable(Coord coord)
Returns whether the given coordinate is interactable, meaning that a walkable tile exists from which the player can interact with it.- Parameters:
coord- the tile to test- Returns:
trueif interactable
-
-