Package com.csse3200.game.components
Class MoveableBoxComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.MoveableBoxComponent
Component for a box that can be moved by the player.
Handles player interactions with a box, including lifting, carrying and dropping.
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor to remove gradle warnings about missing constructor in this class. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Retrieves the PhysicsComponent of the box when the component is created.Retrieves this box's PhysicsComponent.Retrieves the ColliderComponent of the player currently interacting with the boxboolean
Checks if the event listeners have been added to the player.boolean
isLifted()
Checks if the box is currently lifted by the player.boolean
Checks if the player is currently in range of the box.void
onPlayerWalk
(com.badlogic.gdx.math.Vector2 direction) Called when the player moves.void
setPlayerInRange
(ColliderComponent collider) Sets the player collider when the player is range of the box.void
update()
Updates the box every frame.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
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. -
setPlayerInRange
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
Retrieves this box's PhysicsComponent.- Returns:
- the box's PhysicsComponent
-
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. -
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)
-