Game Development Reference
In-Depth Information
1. The player presses
the left arrow key on
the keyboard.
2. The Weapon class's
_direction property is
given the value “left”.
Weapon_FourDirections Class
eb$arajp*gau?k`a99Gau^k]n`*HABP%
w
[`ena_pekj 9habp7
y
3. The Weapon class creates
a new bullet object and
includes the _direction value
(“left”) in the argument.
***
l]najp*]``?deh`$jas>qhhap[Bkqn@ena_pekjo$[`ena_pekj%%7
Bullet_FourDirections Class
4. When the bullet object is
created, its weaponDirection
parameter has the value
“left”. It copies this
value into the bullet's
own_direction property.
5. The bullet's _vx
property gets a value
of -10 if the value of
_direction is “left”.
-10 makes the bullet
move ten pixels to the
left of each frame.
6. The player's position
is updated.
lq^he_bqj_pekj>qhhap[Bkqn@ena_pekjo$sa]lkj@ena_pekj6Opnejc%
w
[`ena_pekj 9sa]lkj@ena_pekj7
y
***
eb$[`ena_pekj99habp%
w
[rt9)-,7
y
***
t'9[rt7
Figure 8-30. How to make the bullets fire in the right direction
Here's the entire Sa]lkj[Bkqn@ena_pekjo class:
l]_g]ca
w
eilknpbh]od*`eolh]u*Ikrea?hel7
eilknpbh]od*arajpo*Gau^k]n`Arajp7
eilknpbh]od*qe*Gau^k]n`7
eilknpbh]od*arajpo*Arajp7
lq^he__h]ooSa]lkj[Bkqn@ena_pekjoatpaj`oIkrea?hel
w
lner]par]n[eo=nia`6>kkha]j7
lner]par]n[`ena_pekj6Opnejc7
lq^he_bqj_pekjSa]lkj[Bkqn@ena_pekjo$%
w
]``ArajpHeopajan$Arajp*=@@A@[PK[OP=CA(kj=``a`PkOp]ca%7
y
 
Search Nedrilad ::




Custom Search