Game Development Reference
In-Depth Information
The collision_rectangle function in lines 4-5 checks if there would be a collision
with obj_enemy at that position with a rectangle the size of this instance's sprite. We
use collision_rectangle rather than instance_place because instance_place would
use precise collision detection as set in our sprites and this can cause instances to
detect collisions too late and get stuck. The last two parameters indicate that precise
collision detection should not be used at all and that the current instance should not
be checked in the detection.
In case of a collision, lines 7-8 set the path's position back to its previous position
and stop the sprite from animating (remember that sprite animation is changed in the
step event, so it will automatically kick back in action if this condition is no longer
true).
3.
The mummies make head-on collisions and that would make them wait forever upon
their meeting, so remove the second instance of obj_mummy in room_test (the mummy
with a Creation code assigned).
4.
The mummy's path is a bit long to see the effect, so let's shorten it. Open path_mummy1 ,
select the first point in the point list, and click Delete three times.
Result: Reference/Result/patrolling_enemies4.gmk
Pausing the Game
No fast-paced game can do without a pause button. Your game players will be grateful for the
opportunity to temporarily stop the game, take a breath, and fuel up on the caffeine that keeps
them awake at night while they battle through your levels.
The easiest way to force Game Maker to pause is to set an infinite loop and wait for the player
to press a key. This will stop everything in its tracks, but we need to make sure the game isn't
taking up the computer's processing power running the loop. Fortunately, there is a command to
make the computer take a break too, or at least to tell it to prioritise other applications. In the
following example, we'll use the space bar as the game's pause key.
Start with: Reference/Framework/bouncing4.gmk
Creating a Pause Feature
1. Create an object and call it obj_pausegame .
2. Add a Key Press , < Space> event. Include an Execute Code action and insert the
following lines:
1: {
2: io_clear();
3: draw_sprite(spr_gamepaused,0,80,200);
4: screen_refresh();
5: while ( !keyboard_check_pressed(vk_anykey) ) sleep(100);
6: }
 
 
Search WWH ::




Custom Search