This is a quick tutorial for making a heart bar, like those on the Legend of Zelda games. When you’re done, you should have something similar to this:
Step #1: Setting up the Scene
Go ahead and add a empty (called “HEALTH_DEBUG”), and a plane.
Step #2: Scripts
There are two scripts:
import GameLogic cont = GameLogic.getCurrentController() own = cont.getOwner() if own.healthMax >= 10: own.healthMax = 10 elif own.healthMax < 0: own.healthMax = 0 if own.health > own.healthMax: own.health = own.healthMax elif own.health <=0: own.health = 0 own.gameOver = 1 else: own.gameOver = 0
import GameLogic cont = GameLogic.getCurrentController() own = cont.getOwner() act = cont.getActuator("visible") true = 1 false = 0 if own.health >= own.number: act.set(true) elif own.health <= own.number: act.set(true) GameLogic.addActiveActuator(act, true)
Step #3: Setting up LogicBricks
Select the empty and make your logic bricks to look like this:
Now, select the plane, and make the logic bricks look like this:
Step #4: Making the Hearts work
Copy The plane and paste 10 of them in the way you want the hearts aligned, then edit each one’s “number” property. We want the number properties to go from 1, and build up to 10. I have it so that number 1 is on the left (in a row), and 10 is on the rightmost. If you don’t know what I’m talking about, take a look at the .Blend. This is all you have to do here 🙂
Step #5: Texturing & Testing
Now, all you have to do is to texture the planes, and test it (P). If it works, then you have successfuly completed this tutorial, if not, then take a look at my working example, and compare what I have with what you have.