Class DoorComponent

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

public class DoorComponent extends Component
Door that can be unlocked with a key and (optionally) trigger an area transition.

Usage:

  • Locked until the player collides and has keyId in InventoryComponent.Bag.INVENTORY.
  • On unlock: collider becomes sensor, plays door_opening, then switches to door_open.
  • After opening finishes, emits GameArea event "doorEntered"(player, door) if non-static and has target.

Requires: AnimationRenderComponent with animations: door_closed (loop), door_opening (non-loop), door_open (loop); ColliderComponent, HitboxComponent on the door entity.

  • Constructor Details

    • DoorComponent

      public DoorComponent(String keyId, GameArea area, boolean isStaticDoor, String targetArea)
      Parameters:
      keyId - inventory key id that unlocks the door
      area - owning game area (used to emit doorEntered)
      isStaticDoor - if true, acts as barrier only (no transition)
      targetArea - target area id (used only when non-static)
  • Method Details

    • create

      public void create()
      Wire listeners and set initial animation to door_closed.
      Overrides:
      create in class Component
    • update

      public void update()
      Advance the animation; emit transition when it finishes (if eligible).
      Overrides:
      update in class Component
    • tryUnlock

      public void tryUnlock(Entity player)
      Try to unlock the door using the player's inventory.
    • openDoor

      public void openDoor()
      Open the door (non-blocking + play opening animation).
    • isLocked

      public boolean isLocked()
      Accessor for isLocked
      Returns:
      true if door is locked, false otherwise.
    • getTargetArea

      public String getTargetArea()
      Accessory for door target area
      Returns:
      the area (if any) on the other side of the door