Package com.csse3200.game.components
Class InteractionDetector
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.physics.components.ColliderComponent
com.csse3200.game.physics.components.HitboxComponent
com.csse3200.game.components.InteractionDetector
- All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable
Represents a component that handles interaction detection with entities
within a specified range.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionInteractionDetector
(float range) Constructs an InteractionDetector with the specified interaction range.InteractionDetector
(float range, List<EntityType> interactableEntities) Constructs an InteractionDetector with the specified interaction range. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
When entity is created, sets up circular collider with radius as range used for detecting entities.Gets the list of entities currently in the interaction range.getEntitiesTowardsDirection
(String direction) Gets the list of entities currently in the interaction range in the specified direction.getEntitiesTowardsPosition
(com.badlogic.gdx.math.Vector2 position) Gets the list of entities currently in the interaction range towards a position.getNearest
(List<Entity> entities) Gets a list containing the nearest entity from a list of entities.void
notifyOnDetection
(boolean notify) Methods inherited from class com.csse3200.game.physics.components.ColliderComponent
dispose, getFixture, getLayer, setAsBox, setAsBox, setAsBoxAligned, setDensity, setFriction, setLayer, setRestitution, setSensor, setShape
Methods inherited from class com.csse3200.game.components.Component
earlyUpdate, getEntity, read, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update, write
-
Constructor Details
-
InteractionDetector
public InteractionDetector(float range) Constructs an InteractionDetector with the specified interaction range.- Parameters:
range
- The interaction range within which entities are detected.
-
InteractionDetector
Constructs an InteractionDetector with the specified interaction range.- Parameters:
range
- The interaction range within which entities are detected.
-
-
Method Details
-
create
public void create()When entity is created, sets up circular collider with radius as range used for detecting entities. Also attaches collision event listeners.- Overrides:
create
in classHitboxComponent
-
notifyOnDetection
public void notifyOnDetection(boolean notify) -
getEntitiesInRange
Gets the list of entities currently in the interaction range.- Returns:
- A list of entities within the interaction range.
-
getEntitiesTowardsDirection
Gets the list of entities currently in the interaction range in the specified direction.- Parameters:
direction
- The direction in which to filter entities (e.g., "UP", DOWN", "LEFT", "RIGHT").- Returns:
- A list of entities within the interaction range in the specified direction.
-
getEntitiesTowardsPosition
Gets the list of entities currently in the interaction range towards a position.- Parameters:
position
- The vector position in which to filter entities.- Returns:
- A list of entities within the interaction range towards the position.
-
getNearest
Gets a list containing the nearest entity from a list of entities.- Parameters:
entities
- The list of entities to search for the nearest entity.- Returns:
- nearest Entity or null if list is empty
-