Game Development Reference
In-Depth Information
That's it for the Sweet Beastie, and you'll be pleased to know that that was the most
complicated of the enemies we'll be adding to the game. See if you can get past him now that he
is armed with this new weapon. If there are any problems with your version, then check it against
the file zool10.gmk in Chapter05/Games on the CD.
Let it Bee
The final enemy we'll be tackling for the Sweet World are the Bees. These differ from the other
enemies in that they can fly and will actively follow Zool around the level. This is actually much
easier than it sounds, as Game Maker has built-in path-finding actions to help us do this. We will
use states for the Bee, but it only has two alternating states—move and wait—so it isn't worth
drawing a diagram. The bee will move very quickly for just a few steps and then hover for a while
before it moves again. Unlike the original game, Bees won't actually try to touch Zool and will
hover around him in order to give it the impression of a buzzing insect that is trying to size up
Zool instead. Of course, that still makes it very easy to touch one accidently:
Creating the Bee Enemy Object
1. Create a new object called obj_bee ( Hazards group), give it spr_bee_fly_right , and set
its Parent to obj_enemy .
2. Add a Create event and include a Set Variable action ( control tab) that sets the
Variable state to ESTATE_MOVE .
3. Include a second Set Variable action that sets the Variable facing to FACE_LEFT .
4. Include a third Set Variable action that sets the Variable targetx to 0 . We'll use this
later to work out the position for which the Bee is heading.
5. Include a Set Alarm action ( main2 tab) that sets Alarm 0 to 5 steps. The Bee will move
quite fast, so five steps of movement will be plenty.
6. Add a Destroy event and include a Set Variable action ( control tab) that sets the
Variable global.die_sprite_index to spr_bee_die .
7. Include a Call Parent Event action that will thereby handle the rest of the process of
creating dying enemy instances and the splat.
8. Add a Draw event. This will handle the drawing of the correct left- and right-facing
sprites, although the Bee's appearance is the same in all states.
9. Include a Test Variable action that checks if the Variable facing is equal to FACE_LEFT .
10. Follow this with a Draw Sprite action ( draw tab) that draws spr_bee_fly_left at a
Relative position of X = 0 , Y = 0 .
11. Include a Test Variable action ( control tab) that checks if the Variable facing is equal
to FACE_RIGHT .
12. Follow this with a Draw Sprite action ( draw tab) that draws spr_bee_fly_right at a
Relative position of X = 0 , Y = 0 .
13. Add a Step, Step event and include a Test Variable action ( control tab) that tests if
state is equal to ESTATE_MOVE . Again, we will use the Step event to control the
behaviors and transitions for each state.
 
Search WWH ::




Custom Search