Game Development Reference
In-Depth Information
Line 2 first clears all input from mouse and keyboard. This is necessary to avoid
entering and immediately exiting this event when the user presses the space bar. Line
3 then draws the “game paused” sprite centered on the screen, and line 4 refreshes the
screen so the message will immediately be visible (normally Game Maker doesn't show
anything until all instances are drawn). Finally, the last line creates a loop that keeps
running until the user presses a key. The sleep(100) tells Game Maker to pause
everything and temporarily give other processes on the computer some time to run
before checking back on the loop 100 milliseconds later.
3.
For all rooms in the game where you want to allow pausing, add an instance of
obj_pausegame .
Result: Reference/Result/pausing_the_game.gmk
Tip Don't forget to tell the player which key allows them to pause the game!
Pushing Boxes
If you know the game Sokoban, you need no introduction to this feature. If you don't, just
imagine a game where the player object can push boxes around to cover holes, to push them into
enemies, or to clear exits. For as simple and logical as it looks on a screen, it's not always a trivial
thing to build into your game. Here are some things to keep in mind:
The player object should be lined up correctly next to the box to be able to push it (the
player object should not be able to push it with only a fraction of its sprite).
The box needs to be moved into the direction the player object is walking into.
It should not be possible to push the box if there is something behind it.
We're going to use our Grid Movement example and extend it to push boxes, so read that
section first, earlier in this chapter, to understand this one. We're using grid movement because
grid alignment always takes care of putting the instances straight next to each other. Once the
player starts moving in the direction of the box, we simply make it move 32 pixels in that
direction all by itself using an alarm to stop its movement.
Start with: Reference/Framework/explorer6.gmk
Creating Boxes That Can Be Pushed
1.
Create an object obj_impassable . This object will do nothing more than serve as a
parent to group all objects that a box cannot be pushed through. This way, we only
have to check moving the boxes against one object!
Double-click to open obj_wall and set its Parent to obj_impassable .
2.
Add an object called obj_box and set its Sprite to spr_box . Set its Parent to
obj_impassable too (we should not be able to push boxes through other boxes).
3.
 
 
Search WWH ::




Custom Search