Class InteractionDetector

All Implemented Interfaces:
com.badlogic.gdx.utils.Json.Serializable

public class InteractionDetector extends HitboxComponent
Represents a component that handles interaction detection with entities within a specified range.
  • 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

      public InteractionDetector(float range, List<EntityType> interactableEntities)
      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 class HitboxComponent
    • notifyOnDetection

      public void notifyOnDetection(boolean notify)
    • getEntitiesInRange

      public List<Entity> getEntitiesInRange()
      Gets the list of entities currently in the interaction range.
      Returns:
      A list of entities within the interaction range.
    • getEntitiesTowardsDirection

      public List<Entity> getEntitiesTowardsDirection(String direction)
      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

      public List<Entity> getEntitiesTowardsPosition(com.badlogic.gdx.math.Vector2 position)
      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

      public Entity getNearest(List<Entity> entities)
      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