Game Development Reference
In-Depth Information
[fqilBkn_a is the force with which the object will jump. It needs to project upward toward the top
of the stage, so it has a negative value. The actual value that you give it is again a matter of trial and
error. You'll need to make sure that its value is enough to counteract gravity and any other forces that
might be acting on the object.
How does the object know whether it's on the ground? This is something that could become quite com-
plex, depending on the game you're designing, so you'll need to think about this carefully when you start
any project that uses jumping. In this simple example, the _]p object is on the ground when it's at the
bottom of the stage. So all you need to do is set [eoKjCnkqj` to pnqa in the same section of code that
checks for the bottom stage boundary:
eb$t'lh]uanD]hbSe`pd:op]ca*op]caSe`pd%
w
[rt9,7
t9op]ca*op]caSe`pd)lh]uanD]hbSe`pd7
y
ahoaeb$tÌlh]uanD]hbSe`pd8,%
w
[rt9,7
t9,'lh]uanD]hbSe`pd7
y
eb$u)lh]uanD]hbDaecdp8,%
w
[ru9,7
u9,'lh]uanD]hbDaecdp7
y
ahoaeb$u'lh]uanD]hbDaecdp:op]ca*op]caDaecdp%
w
[ru9,7
u9op]ca*op]caDaecdp)lh]uanD]hbDaecdp7
[eoKjCnkqj`9pnqa7
y
That's pretty straightforward. In most games that use jumping, game characters also need to know
when they're standing on platforms. That makes detecting the ground a little more complex, but you'll
be looking at a solution in the Bug Catcher game that you'll build later in the chapter.
Making the object actually jump happens in the kjGau@ksj event handler:
lner]pabqj_pekjkjGau@ksj$arajp6Gau^k]n`Arajp%6rke`
w
eb$arajp*gau?k`a99Gau^k]n`*HABP%
w
[]__ahan]pekjT9),*.7
y
eb$arajp*gau?k`a99Gau^k]n`*NECDP%
w
[]__ahan]pekjT9,*.7
y
eb$$arajp*gau?k`a99Gau^k]n`*QL%
 
Search Nedrilad ::




Custom Search