Package com.csse3200.game.components
Class ButtonComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.ButtonComponent
Component for button entities that can be pushed by the player to trigger other events
Class controls the state of the button (normal or pushed) and
the button colour based on the type (door, platform or nothing)
-
Field Summary
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Creates the buttonvoid
Forces the button to unpress immediately regardless of current state or timer Resets texture, stops timer and triggers buttonToggled event (with false as unpressed)Retrieves the ColliderComponent of the player currently interacting with the boxboolean
Checks if the player is currently in range of the button.boolean
isPushed()
Returns true if button is pushed, false otherwisevoid
setDirection
(String direction) Sets the direction the button will face, for both texture and pressing logic Automatically left unless otherwise specified (right, up, down)void
setPlayerInRange
(ColliderComponent collider) Sets whether a player is in interaction range of this button Adds the player to the "interact" event the first timevoid
setPushed
(boolean pushed) Sets the buttons pushed state manually [for future implementations]void
setPuzzleManager
(ButtonManagerComponent puzzleManager) Assigns a puzzle manager to the button, so manager can be notified when its pressedvoid
Sets the type for this button (which selects texture)void
update()
Updates the button.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate
-
Constructor Details
-
ButtonComponent
public ButtonComponent()
-
-
Method Details
-
create
public void create()Creates the button -
update
public void update()Updates the button. If it is a timing button and the time runs out, button will unpress and return to original texture -
setPlayerInRange
Sets whether a player is in interaction range of this button Adds the player to the "interact" event the first time- Parameters:
collider
- Player's ColliderComponent (null if player leaves collision range)
-
setDirection
Sets the direction the button will face, for both texture and pressing logic Automatically left unless otherwise specified (right, up, down)- Parameters:
direction
- The direction string to set
-
forceUnpress
public void forceUnpress()Forces the button to unpress immediately regardless of current state or timer Resets texture, stops timer and triggers buttonToggled event (with false as unpressed) -
setPuzzleManager
Assigns a puzzle manager to the button, so manager can be notified when its pressed- Parameters:
puzzleManager
- the ButtonManagerComponent managing this button
-
setType
Sets the type for this button (which selects texture)- Parameters:
type
- String representing the button type (door, platform or nothing)
-
isPlayerInRange
public boolean isPlayerInRange()Checks if the player is currently in range of the button.- Returns:
- true if the player is in range, false otherwise
-
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
-
setPushed
public void setPushed(boolean pushed) Sets the buttons pushed state manually [for future implementations]- Parameters:
pushed
- state to set the button to
-
isPushed
public boolean isPushed()Returns true if button is pushed, false otherwise
-