Player HUD
The players HUD has many different aspects to it. Within the player HUD is the Lives counter, HP and Stamina meters, Screw collection counter, timer, and inventory. All aspects of the player HUD needed to be individually adjusted with their own properties set up. These were all controlled with functions within the player HUD widget blueprint in unreal engine 5. Each element needed to be properly placed in the players screen bounds and designed in a way that is easy to understand for the player.
Lives Counter
The lives Counter is the second most simple of the HUD elements. This counter tracks the number of lives the player has throughout each level. Within Gears of Discovery the player is given 3 lives for each level they play with no way to obtain more. If the player runs out of lives the level will end and they will need to restart from the beginning.
To obtain the number of lives the player has a reference of the player character is pulled and the player lives variable is appended to a string (X (Player Lives)) This value is then posted to the text block in the upper right hand corner next to the player lives icon to accurately show the player lives as the level progresses. Each time that variable is changed the string will be updated and pushed to the player HUD
HP and Stamina Meters
The HP and Stamina meters work exactly the same. They both take a reference of the player character and grab the respected variables from the player. Those being the stamina and HP. These are both 100. These amounts are then divided by 100 to get a percentage for the meter fill rate. If the player has 70 HP that value is divided by 100 to get 0.7 which means that the meter is filled 70% of the way. This information is then pushed to the players owned meter within the HUD and is updated whenever the value changes.
Screw Collection Counter
The screw collection counter uses two separate blueprints to function. Within each level a BPManager actor is placed within the level. This tracks when the player overlaps with the coin pickup. The event is called and the BP_Manager increases the coin collection by 1. The widget for the player HUD then pulls that number from the manager and changes the coin text in the player HUD to the current value.
Timer
The timer is the simplest thing to set up. By getting the game time is seconds we are able to obtain the seconds and minutes elapsed. These values are then split off and the text is set based on whatever that value is.
Player Inventory
The player inventory works in a few different ways. The UI element of it is pretty straight forward though. If the player wants to scroll through their inventory a check is done on what direction the player is scrolling. This then changes the integer for the currently selected item, which updates what inventory slot will be highlighted. This value is changed either up 1 or down 1 depending on the direction the player scrolls and is reset if the integer exceeds 2 or goes below 0. So if the value were to be -1 it would update that value to 2 instead. This allows the player to loop through the inventory rather than only being able to scroll one way or the other.
When a player picks up an item there is a check that is done that gets the items name and then checks to see if the first slot in the players inventory is empty. If it is it will set the first slot in the array to the name of the picked up item and add the image associated with that item name into the players HUD on screen. If the first slot is full it will then check the second slot, and so on. If the players inventory is full and they run through a pickup the item will not be picked up and the item will in turn not be added to the players inventory.