Class ButtonComponent

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

public class ButtonComponent extends Component
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)
  • Constructor Details

    • ButtonComponent

      public ButtonComponent()
  • Method Details

    • create

      public void create()
      Creates the button
      Overrides:
      create in class Component
    • 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
      Overrides:
      update in class Component
    • setPlayerInRange

      public void setPlayerInRange(ColliderComponent collider)
      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

      public void setDirection(String direction)
      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

      public void setPuzzleManager(ButtonManagerComponent puzzleManager)
      Assigns a puzzle manager to the button, so manager can be notified when its pressed
      Parameters:
      puzzleManager - the ButtonManagerComponent managing this button
    • setType

      public void setType(String type)
      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

      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
    • 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