|
Want to thank me for making this book available for free? Just buy Special Edition Using Macromedia Director MX
Advanced Lingo For Games
| |
| Game Overview
A sliding puzzle has puzzle pieces that are usually square, and are fixed to the board. One piece is missing. Figure 6.1 shows a typical setup.
Figure 6.1
The sliding puzzle game is played by moving one piece at a time into the empty slot.
The user arranges the pieces by sliding one into the empty slot from either the left, right, top, or bottom. By continuously moving pieces around, any arrangement can be obtained, although the combination of movements needed to get a certain arrangement is not always obvious. Puzzle PiecesA sliding puzzle game is similar to a jigsaw puzzle in that you start with a cast library filled with puzzle pieces. Because the pieces must slide by each other, they should be square, or at least rectangular. They should all be exactly the same size. In addition, we do not have to use the same registration point alignment that we used for the jigsaw puzzles. The registration point for each piece should be in the center of the bitmap. This makes it much easier to build the pieces, as anyone who has played with Director 7's Paint Window knows. One peculiar thing about the sliding puzzle is that one piece is always missing. It is almost always the bottom-right corner piece. This is fundamental, because the player needs an empty slot to slide the first piece into. Figure 6.2 shows a cast library with 24 puzzle pieces. The puzzle is meant to be a 5[ts]5 square puzzle, with the bottom-right corner piece missing at the start of the game.
Figure 6.2
A cast library with the pieces for a sliding puzzle game.
The Sliding MotionIn many Director-based versions of this game, when the user clicks on a piece, it jumps into an adjacent vacant slot. Although this gets the job done, let's go for something a little nicer here by actually having the sprites animate into the new spot, giving a smooth feel to the game. To do this, we will attach a sprite behavior to every piece that will get the signals to animate and where to animate to. The sprite behavior will then take care of that animation independent to the main game behavior. By making things like this independent of the game code, we avoid complicating the code with special effects that have little to do with the game logic. Detecting Game OverBecause all the puzzle pieces have their registration points marked in the center, there is no easy way, as there was with the jigsaw puzzles, to determine if the puzzle is complete. Instead, we will use a technique that relies on two facts. First, the sprites will be arranged in the Score in the same order that they appear on the Stage. So the sprite in the upper-left corner will be in the first sprite channel, the next piece to the right will be in the next channel, and so on. Second, the empty spot in the puzzle will be at the bottom right. These facts then enable us to look through the sprites and determine if each sprite is in its proper position throughout the puzzle. Thus, we can determine if the game is over. Special EffectsIn addition to the sliding animation, we will be adding sound and cursor changes to this game. The sound will be a simple one to go along with the sliding animation. The cursor change just consists of a finger cursor to be applied to each puzzle piece, indicating that it is clickable. | |