Class DoorComponent
java.lang.Object
com.csse3200.game.components.Component
com.csse3200.game.components.obstacles.DoorComponent
-
Field Summary
-
Constructor Summary
ConstructorsConstructorDescriptionDoorComponent
(String keyId, GameArea area) A component that represents a door which can be locked or unlocked with a specific key. -
Method Summary
Modifier and TypeMethodDescriptionvoid
create()
Registers listeners for collision and door events when the component is created.boolean
isLocked()
Check if door is currently lockedvoid
openDoor()
Opens the door by making its collider a sensor (non-blocking).void
Attempts to unlock the door using the player's inventory.Methods inherited from class com.csse3200.game.components.Component
dispose, earlyUpdate, getEntity, setEnabled, setEntity, toString, triggerEarlyUpdate, triggerUpdate, update
-
Constructor Details
-
DoorComponent
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. -
tryUnlock
Attempts to unlock the door using the player's inventory. If the player has the required key, it consumes the key, unlocks, and triggers theopenDoor
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
-