Game Development Reference
In-Depth Information
programming form to do so. (If you do leave it out, AS3.0 will add it automatically when it compiles
the program.)
Next is the ^hk_g function definition:
op]pe_lq^he_bqj_pekj^hk_g$k^fa_p=6Ikrea?hel(k^fa_p>6Ikrea?hel%6rke`
The op]pe_ keyword means that you can use this method directly in any other class, in the format
?khheoekj*^hk_g, without having to make an instance of the class first. (If that's not too clear right
now, it will make a little more sense later in the topic when you work more closely with instances of
classes.) For now, just know that it makes it very easy to use this method anywhere in the program.
The other important things about this function definition are its parameters:
$k^fa_p=6Ikrea?hel(k^fa_p>6Ikrea?hel%
These are local variables that are defined with the type Ikrea?hel. In the I]ej[Lh]ucnkqj`*]o file,
you used this line of code to call the method:
?khheoekj*^hk_g$lh]uan(s]hh%7
Both lh]uan and s]hh are Ikrea?hel objects, so it makes sense that k^fa_p= and k^fa_p> should
be typed as Ikrea?hel objects, too. When the method is called, a reference to the lh]uan object is
copied into the k^fa_p= variable, and a reference to the s]hh object is copied into the k^fa_p> vari-
able. Whenever you see k^fa_p= and k^fa_p> in the body of the method, you can replace them with
lh]uan and s]hh in your mind if that helps you better understand how the code is working.
To allow the player to push the wall, the order of the objects in the method call is reversed like this:
?khheoekj*^hk_g$s]hh(lh]uan%7
The s]hh object was referenced by the k^fa_p= variable. The roles were reversed, and the s]hh object
was forced to reposition itself to avoid overlapping with the moving lh]uan object, creating the push-
ing effect.
The first few lines of code inside the ^hk_g function definition initialize the method's local variables:
r]nk^fa_p=[D]hbse`pd6Jqi^an9k^fa_p=*se`pd+.7
r]nk^fa_p=[D]hbdaecdp6Jqi^an9k^fa_p=*daecdp+.7
r]nk^fa_p>[D]hbse`pd6Jqi^an9k^fa_p>*se`pd+.7
r]nk^fa_p>[D]hbdaecdp6Jqi^an9k^fa_p>*daecdp+.7
r]n`t6Jqi^an9k^fa_p>*t)k^fa_p=*t7
r]nkt6Jqi^an9k^fa_p>[D]hbse`pd'k^fa_p=[D]hbse`pd)I]pd*]^o$`t%7
If you're this far into the topic, you're pretty much an expert on half-widths and half-heights! But the
last two lines deserve a good look. Let's start with this one:
r]n`t9k^fa_p>*t)k^fa_p=*t7
 
Search Nedrilad ::




Custom Search