Game Development Reference
In-Depth Information
An important thing to know is that if you remove an element from an array in the middle of a loop,
you also need to subtract - from the counter variable, e. If you don't do this, it throws the counter off
by one and the loop will skip the next item. That's what this directive does:
e))7
The rest of the code in the osep_d statement checks for collisions between op]n bullets and the
player. It's almost identical to the code you just looked at.
Removing bullets at the stage boundaries
The last thing the document class does is remove the bullets when they reach the stage boundaries.
I added this code in the I]ej[Ol]_aOdkkkpan class because I want the document class to be entirely
responsible for removing objects from the game. It makes it easier to manage the [^qhhap array.
This code is also in the kjAjpanBn]ia event handler, and like the collision detection code, it runs inside
a bkn loop. It checks each bullet in the [^qhhapo array, one at time, to see whether it's crossed the
stage boundaries. (The loop counter variable is f to avoid conflicting with e in the previous loop.)
bkn$r]nf6ejp9,7f8[^qhhapo*hajcpd7f''%
w
++Pkl
eb$[^qhhapoWfY*u'[^qhhapoWfY*daecdp+.8,%
w
naikra?deh`$[^qhhapoWfY%7
[^qhhapo*olhe_a$f(-%7
f))7
y
++>kppki
ahoaeb$[^qhhapoWfY*u)[^qhhapoWfY*daecdp+.:op]ca*op]caDaecdp%
w
naikra?deh`$[^qhhapoWfY%7
[^qhhapo*olhe_a$f(-%7
f))7
y
++Habp
ahoaeb$[^qhhapoWfY*t'[^qhhapoWfY*se`pd+.8,%
w
naikra?deh`$[^qhhapoWfY%7
[^qhhapo*olhe_a$f(-%7
f))7
y
++Necdp
ahoaeb$[^qhhapoWfY*t)[^qhhapoWfY*se`pd+.:op]ca*op]caSe`pd%
w
naikra?deh`$[^qhhapoWfY%7
[^qhhapo*olhe_a$f(-%7
f))7
y
y
 
Search Nedrilad ::




Custom Search