Player Torch - UQdeco2800/2021-studio-6 GitHub Wiki
Descriptions
The torch will be used in order to allow the player to view the world in darkness. The torch lighting component is attached to the player so that it follows them around.
Overview
The torch is mainly handled through a number of event listeners that toggle and turn off/on the lighting depending on where they get called. The manual button press toggles the torch while the timer either turns it off or on through their respective events. The lighting itself gets handled in PlayerLightingComponent, which the torch item is abstracted from through InventoryComponent.
Torch Activation (Inventory Component)
If the player presses T, the torch is activated. This achieved by adding the code for implementing the lighting engine into the player at creation in player factory.
Torch Timer (Inventory Component)
The torch also features a limited timer that slowly goes down to show the torch burning away. This occurs every second in the update function and will deactive the torch once the fuel runs out. The torch will stop emitting light once it has run out. Additionally, if the torch is manually deactived with the button press, it will stop using fuel and stay deactived until manually reactived again. If the torch runs out and the user acquires more fuel through the store, the torch will reactivate depending on the toggle state.
Torch State (Inventory Component)
The torch fuel timer is stored, updated and modified in InventoryComponent through public void addTorch(int addTorch) and public int getTorch(). It is also saved between levels so that the torch timer is preserved.