Game Development Reference
In-Depth Information
Managing the Energy Bar
Every hero needs an energy bar! No, I am not talking about a chocolate caramel
snack. I am referring to the life bar for your main characters. There are many
ways to manage this in GameSalad. You can use attributes, actors, or any
combination of them with rules. I won't cover all of the possibilities; rather, I
want to show you a new behavior called ''Interpolate,'' which I will illustrate
through the energy bar.
The Interpolate Behavior
The Interpolate behavior is a very powerful behavior. In simple terms, it will
calculate all the values between a starting point and a finishing point in a given
period of time with a specific method. Imagine your actor is at point A (the
starting point) and the actor needs to go to point B. If you apply a Change
Attribute to the position, your actor will make a quantum jump from A to B.
That's not the effect you want.
If you have read the previous chapters or if you are proficient with GameSalad,
you will think to yourself, ''No need to use Interpolate, just use Move to.'' You
are almost correct! Move to is a linear implementation of Interpolate, but
Interpolate provides one more option: not being linear. This applies to any
attribute. I repeat: any attribute. This gives you a lot of possibilities to introduce
some very cool features in your game.
In this section, you will use the Interpolate behavior on the color of an actor.
Your energy bar will be green when 100% but will change from green to orange
(and all the colors between green and orange) when it is at 50% and then from
orange to red when it is at 25%. Every hit of an Asteroid will remove 25% of the
energy bar. You will also make a second use of the Interpolate behavior by
decreasing the size of the energy bar after each collision with an asteroid.
Enough talking. Let's practice now.
Interpolate in Action
You can continue from your existing Carrot_Invaders file or open
Carrot_Invaders_step3.gameproj .
Create two game attributes of type integer and name them respectively
''EnergyBar'' and ''EnergyBarInit.'' Set both to a default value of 100. The names
are quite implicit on the purpose of those attributes, but why do you need two?
 
Search WWH ::




Custom Search