Class DoorComponent

java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.obstacles.DoorComponent

public class DoorComponent extends Component
  • Constructor Details

    • DoorComponent

      public DoorComponent(String keyId, GameArea area)
      A component that represents a door which can be locked or unlocked with a specific key.

      The door listens for collisions with player entities and checks their inventory for a matching key. If the player has the correct key, the door is unlocked and opened.

  • Method Details

    • create

      public void create()
      Registers listeners for collision and door events when the component is created.
      Overrides:
      create in class Component
    • tryUnlock

      public void tryUnlock(Entity player)
      Attempts to unlock the door using the player's inventory. If the player has the required key, it consumes the key, unlocks, and triggers the openDoor event.
      Parameters:
      player - the player entity attempting to open the door
    • openDoor

      public void openDoor()
      Opens the door by making its collider a sensor (non-blocking).
    • isLocked

      public boolean isLocked()
      Check if door is currently locked