Class MoveableBoxComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.MoveableBoxComponent

public class MoveableBoxComponent extends Component
Component for a box that can be moved by the player.

Handles player interactions with a box, including lifting, carrying and dropping.

  • Constructor Details

    • MoveableBoxComponent

      public MoveableBoxComponent()
      Default constructor to remove gradle warnings about missing constructor in this class.
  • Method Details

    • create

      public void create()
      Retrieves the PhysicsComponent of the box when the component is created.
      Overrides:
      create in class Component
    • setPlayerInRange

      public void setPlayerInRange(ColliderComponent collider)
      Sets the player collider when the player is range of the box. Adds event listeners to the player for interacting and walking.
      Parameters:
      collider - The ColliderComponent of the player
    • isPlayerInRange

      public boolean isPlayerInRange()
      Checks if the player is currently in range of the box.
      Returns:
      true if the player is in range, false otherwise
    • isLifted

      public boolean isLifted()
      Checks if the box is currently lifted by the player.
      Returns:
      true if the box is lifted, false otherwise
    • isAddToPlayer

      public boolean isAddToPlayer()
      Checks if the event listeners have been added to the player.
      Returns:
      true if listeners are added, false otherwise
    • getBoxPhysics

      public PhysicsComponent getBoxPhysics()
      Retrieves this box's PhysicsComponent.
      Returns:
      the box's PhysicsComponent
    • getPlayerCollider

      public ColliderComponent getPlayerCollider()
      Retrieves the ColliderComponent of the player currently interacting with the box
      Returns:
      the player's ColliderComponent, or null if no player is in range
    • update

      public void update()
      Updates the box every frame. If the player is lifting the box, the box continues to move with the player.
      Overrides:
      update in class Component
    • onPlayerWalk

      public void onPlayerWalk(com.badlogic.gdx.math.Vector2 direction)
      Called when the player moves. Updates the box position if it is lifted.
      Parameters:
      direction - The direction the player is walking (currently unused)