Game Development Reference
In-Depth Information
The bounce value has to be negative because bouncing works by reversing the object's velocity. You'll
see how this happens in a moment. A value of ),*3 creates the effect of a moderate bounce. A value
of )- makes the object super bouncy. A value of - makes the object completely bounce-less. Any
value less than )- makes the object look like it's hitting an extremely springy surface, such as a tram-
poline. This is important to keep in mind if you want to make a springing platform in a game.
The [^kqj_a variable doesn't make a further appearance until the section of code that handles stage
boundaries:
eb$t'lh]uanD]hbSe`pd:op]ca*op]caSe`pd%
w
[rt&9[^kqj_a7
t9op]ca*op]caSe`pd)lh]uanD]hbSe`pd7
y
ahoaeb$tÌlh]uanD]hbSe`pd8,%
w
[rt&9[^kqj_a7
t9,'lh]uanD]hbSe`pd7
y
eb$uÌlh]uanD]hbDaecdp8,%
w
[ru&9[^kqj_a7
u9,'lh]uanD]hbDaecdp7
y
ahoaeb$u'lh]uanD]hbDaecdp:op]ca*op]caDaecdp%
w
[ru&9[^kqj_a7
u9op]ca*op]caDaecdp)lh]uanD]hbDaecdp7
y
All that's happening is that the object's velocity is being multiplied by the [^kqj_a value, which is
negative. If you reverse an object's velocity, it looks as if it is bouncing!
Gravity
Gravity is just as easy to implement as the other physical forces. All you need to do is create one more
value and add it to the object's [ru velocity.
To see gravity at work, bind the Lh]uan[Cn]repu class to the ?]p symbol. Test the project. The cat
drops to the bottom of the stage. If you press the up arrow key, the cat moves up. When the up arrow
is released again, the cat falls to the ground. When the cat reaches its maximum speed, terminal velocity
displays in the Output panel.
 
Search Nedrilad ::




Custom Search