|
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
The basic idea is that the screen is filled with a number of face-down cards. Each card is part of a matched pair. The player can turn any two cards over at a time to look at them. If the player turns two matching cards over, those cards are removed from the table. Otherwise, both cards are turned back to face-down. The goal, of course, is to remove all the cards from the table. As the player turns over cards, he or she should remember which cards are where to make it easier to find matches in the future. Figure 4.1 shows a game in progress. This game consists of 100 cards, which is a high number. A game with 25 or 36 is more common. In the figure, some cards are missing. These have already been matched. In addition, two cards are turned over, indicating that the player has just selected the second card in an attempt to make a match.
Figure 4.1
A matching game in progress.
Try the game out before reading any further. It can be found on the book's CD-ROM, in the folder for this chapter. Shuffling the DeckAs opposed to the matching game in Chapter 3, "Matching Game," this game is one that can be played over and over by the same person. For it to be challenging, however, the cards should not be in the same position each time. To make a random board, you need to have the cards shuffled each time the game is played. This is done in a similar way that a real-life deck of cards is shuffled. First, the deck of cards is created as a Lingo list. This deck of cards is in order. Then, a random one is picked from this deck and placed in a second pile. Then another card is picked. This goes on until the deck is empty and the pile is full. The result is that the pile is a randomly sorted deck of cards. They are then dealt out onto the table for the game. We'll look at the Lingo code for this later in the chapter. This shuffling technique comes in handy for a lot of the games in this book. Time for PauseWhen the game starts, all the cards are face-down on the table. The player then clicks on a card. This card is turned over and its value revealed. Then, the user clicks on a second card. If this card is a match, both cards should be taken off the table. If it isn't a match, both cards are turned back down. However, there is one thing that needs to be taken into account: a pause. If the player turns over the second card, and both are immediately turned back or taken off, then the player never gets to see the value of the second card. This is unimportant if the cards match, but it's important if the cards don't. Seeing the second card is a crucial part of the game, because the player will want to note its value for future reference. You need to create a pause of a certain length when the second card is turned over. After this pause, both cards are turned back down or removed from the table. In addition you should allow the player to end the pause by clicking the next card. This allows fast players to continue playing without waiting. The Hidden PictureA typical motivation for this type of game is to have a picture hidden under the cards. As the cards are removed from the screen, the picture is revealed. This allows the game to take on a theme. For instance, a site promoting a movie, for instance, can have a still image from the movie underneath. To add this hidden picture element to the game actually requires no additional programming at all. The game takes place in a series of sprites in a frame. The picture needs to merely reside in a lower-numbered frame channel than the cards. The image is under the game at all times, and is revealed as the sprites are removed from the Stage. The CardsThe cards can be any size and shape, as long as they are all the same size and shape. The way the code is written in this chapter, the cards need to be placed in their own cast library. This cast library should have absolutely nothing else in it besides the cards. This makes it easy for the behavior to figure out how many cards there are and where in the cast they are. In addition, there needs to be a single graphic of a card turned face-down. This bitmap should be in the default, internal cast library, not the "Cards" cast library. This face-down card bitmap needs to be placed on the Stage in as many sprites as there are to be cards on the screen. For instance, in Figure 4.1, shown previously, there are 100 of these cards needed. The position of each card on the Stage is irrelevant to the game, but is usually a grid as shown earlier in Figure 4.1. Note that there needs to be exactly twice as many sprites on the Stage as there are cards in the "Cards" cast library. This is because each card graphic represents a pair of cards. The game behavior expects the cards to be placed in consecutive sprites in the Score. For instance, in the game on the CD-ROM, they are in sprite channels 11 through 110. The cards themselves can have any sort of image on them. You can use photographs, drawings, colors, symbols, letters, or even words. The game on the CD-ROM uses simple symbols taken from various specialty fonts. Figure 4.2 shows the "Cards" cast library.
Figure 4.2
The "Cards" cast library contains all the cards used in the game.
Game OverLike the previous chapter, a game over condition is reached when all the cards have been matched. Because we are removing sprites from the Stage when each match is made, the program just needs to check out all the sprites. If any are still on the Stage, then the game is still in progress. Because the only way a game can end is by the user making a final match, it's only necessary to check for the end of the game when a match is made. Special EffectsLike all games, sounds can be added to spice things up a bit. A sound would make sense when a match is made. This would signify the two cards being removed from the board. However, it's not always a good idea to have a sound when the second card does not match. This is because this situation occurs a lot, especially during the beginning of the game. A sound for a non-match can get annoying. Still, it's a good idea to include an option for a sound and decide when setting up the Score. In addition, a sound can be played when a card is clicked. This little bit of feedback makes it a more pleasant experience for the player. | |