• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Zelda-Styled Hearts (Split into quarters)

GM Version: GMS 1.4
Target Platform: Windows
Download: http://www.mediafire.com/file/oaffc8oeo42xahn/Zelda_Style_Hearts_Example.zip/file
Links: N/A

Summary:
This example/tutorial demonstrates how to make a Zelda-themed hearts system. Unlike most examples I've seen online, this one splits the hearts into quarters rather than halves.

Tutorial:
This example is better suited for users who are adept at programming in general, but should be relatively easy for beginners in GML. I included lots of comments/documentation to make the example easy to follow and customize.

This example takes a heart sprite made up of 5 frames, with the origin being at the center:


The heart drawing begins with a for loop that counts from 0 up to the player's maximum number of hearts. This is different from their maximum HP! Since the player's HP is based on quarters of hearts rather than a full heart, if a player has 3 full hearts, then their max number of hearts is 3, but their max HP is 12.

Firstly within the for loop, it draws what I call the "current" heart, which is the one that should grow and shrink (the correct quarter piece is obtained by taking the player's HP and modding it by 4), it then draws the player's remaining, full hearts (which are to the left of the "current" heart), and then it draws the depleted hearts (which are blue, and to the right of the "current" heart. If the maximum number of hearts reaches an equal multiple of 10 (i.e. 10, 20, 30, etc) then it adds a new row of hearts below the previous row.

Here's how it looks in action:


As you can see the heart sprite can be changed and the spacing between the hearts remains even. This is achieved by using a variable that is used to tell the object what sprite to draw that I named "heartSpr". In the draw event, storing the width and height of "heartSpr" will allow us to draw the hearts evenly spaced apart no matter it's sprite width or height.

That's all I believe, hope this can be useful c:
 
Top