Game Development Reference
In-Depth Information
19. Follow this with a Set Variable action that sets the Variable facing to -facing and thus
reverses the Jelly's direction of travel.
20. Include a Check Object action that checks for there being a collision with an instance
of obj_hazard at a Relative position of X = facing*16 and Y = 0 . This checks whether the
Jelly has collided with a hazard (spike), as we want it to reverse direction in this case
too.
21. Follow this with another Set Variable action that sets the Variable facing to -facing .
22. Add a Destroy event and include a Set Variable action that sets the Variable
global.die_sprite_index to spr_jelly_die . This is the global variable that gets passed
on to the obj_enemy_die object so that it knows which sprite to use.
23. Include a Call Parent Event action. The Jelly's parent object ( obj_enemy ) already has a
Destroy event, so the current event overrides that event with the Jelly's own version.
However, that's not what we want, as it is the Destroy event of obj_enemy that creates
the exploding instances of obj_enemy_die . Fortunately, Game Maker provides a way of
allowing us to explicitly call inherited events from the parent object as well using the
Call Parent Event action.
24. Finally, reopen obj_zool . Right-click on the Collision event with obj_hazard and select
Duplicate Event to create a Collision event with obj_enemy . This now provides the
same behavior for a collision with enemies as we already had for hazards.
Now return to the room editor and place a few instances of the new Jelly object around the
level. Test them out to make sure they roam back and forth as they should and try killing them all
by pressing the K key. The only problem now is that the Jelly doesn't move up and down ramps
properly (it's not designed to go on the steep icy slopes, so avoid putting it there). So it needs to
change orientation and height when it moves up and down shallow ramps. This could involve a
lot of different checks for all the different ramp objects, so we'll group all the up ramps together,
and all down ramps together, using parent objects. This will then allow us to detect collisions
with all the up or down ramps at once, and while we're dealing with collisions, we'll also add a
limiter object that will force enemies to turn around if they collide with it.
Creating Enemy Limits and Coping with Ramps
Create a new object called obj_enemy_limit ( Hazards group). Give it the
spr_enemy_limit sprite, but uncheck the Visible option. This will be our invisible
marker that turns enemies around. It will eventually affect all enemies, but we'll start
with the Jelly.
1.
Create two new objects (outside of any groups at the top level) called obj_ramp_up and
obj_ramp_down . Set both of their parents to obj_ramp .
2.
Now go through all of the inclining ramp objects (with names ending u1 to u8 ) and
change their parents to be obj_ramp_up . This was made a lot easier because
obj_ramp_up was not in a group, but it should really live in the Platform , Ramps group,
so drag it there afterward.
3.
4.
Repeat for all the declining ramp objects (with names ending d1 to d8 ) and change
their parents to be obj_ramp_down . Now, drag obj_ramp_down to the Platform , Ramps
group as well. All this has no effect on the rest of the game, but now allows us to easily
distinguish between up and down ramps in collisions.
Reopen obj_jelly and select the Step event. Include a Check Object action ( control
tab) that checks if there would be a collision with an instance of obj_enemy_limit at a
Relative position of X = facing*16 , Y = 0 .
5.
 
Search WWH ::




Custom Search