Visually representing health.

healthrepresentation
Picture of the game with the health represented through bottles at the top left the screen.

There are many ways to represent health in games. What we decided upon was representing health visually through bottles. As of this moment we have 5 bottles that constitute 100 hit points of the player character. So each bottles is essentially 1/5 of the player characters health. So if the player has 100 hitpoints and each hit removes 10 each bottle has to indicate that they are hurt. This is done by making the bottles more red the less hitpoints they have. Should the player take two hits in this case, one of the bottles will be removed.

healthhurt
One bottle is hurt, which is shown by being more red than the other bottles.
healthremoved
The player gets hit again, now the previously red bottle is gone.

 

 

However, should we in the future for whatever reason want less or more bottles to represent health then it should be no harder than to just remove or add a bottle. If we remove one bottle then the remaining bottles will represent the players health with a 1/4 divide, making sure we can spend less time in the future should we decide that 5 bottles is too much.

As for the actual code, each bottle has a script that finds every other bottle and loops through them and adds them to an integer, maxBottles. This is done so that each bottle knows how much health they should represent. The script then assigns each bottle a maximum and a minimum health, based on the characters total health and what number is assigned to the bottle, which is a public variable that needs to be assigned within the inspector. The bottle number essentially decides what part of the health each bottle should represent. If there are 5 total bottles, and the bottle we are looking at this point has the bottle number of 3, then it’s max health will be 60 and minimum health will be 40, if we assume the player has a maximum health of 100.

lanternnumber
For some reason I confused lanterns with bottles while making this script. The lantern Number shown above is what I’m refering to as bottle number in the text.

Overall I’m pretty happy with the script. There where a lot of hiccups trying to get it to work, but at this point it does what it’s supposed to do. And should anyone be interested in doing something similiar in the future, here is the actual code used:

lanterncode

About Patrik Selleby

2016 Programming