Game Development Reference
In-Depth Information
Health, dying, and lives
"No Mr. Kevin, I expect you to die." Unfortunately for Kevin, by the end of this
chapter, he will die. Poor Kevin! All he wants to do is save Dom. No pain, no game!
Let's get into it. Let's open up a level; we are going to create two new game-wide
attributes. Don't remember how? No problem. There's a lot of information to handle
here! In the scene editor, and in the
Inspector
window, make sure the
Game
button
is clicked, then click on the
Attributes
tab, and then click on the
+
button to add a
new attribute. Both of our new attributes will be Integers; call one
Health
and the
other
Shields
. Change the
Health
value to
100
, and leave
Shields
at
0
. We are
going to create a power up that will give Kevin shields. We are now going to create
two new blank actors. Again, name one of them
Health Bar
and the other
Shield
Bar
. Edit each one; change the
Width
to
100
, the
Height
to
2
, the Color for the health
bar to red, and for the shield bar blue. In the health bar, we are going to add in two
Constrain Attribute behaviors; we are going to change the first attribute's values
to
self.Position.X
To:
game.KevX
, and the second one to
self.Position.Y
To:
game.KevY + 25
, which means the bar will be floating above Kevin's head. Do the
same for the shield bar, but instead of placing it 25 pixels above his head, do 30.
Finally, for the health bar, we are going to add in a Constrain Attribute behavior, and
change it to the following:
Constrain Attribute:
self.Size.Width
to:
game.Health
Do the same for the shield bar, but instead of
game.Health
, change it to
game.
Shields
.