|
Want to thank me for making this book available for free? Just buy Special Edition Using Macromedia Director MX
Advanced Lingo For Games
| |
| Game Variations
A game like this can be adapted for many purposes. It can be used for entertainment or education. It's a good exercise for computer-based training applications, too. This is because, as a teaching tool, the game reinforces what it is teaching by requiring the user to perform an action that associates two items. To this end, you can make a variety of improvements to this basic game. Making a Longer GameIf you want to make a longer game out of this, you need to make a set of several frames, each one a small matching game in itself. The game can then evolve over the series of frames. For instance, for a trivia game, you could have each frame represent a different topic. Or, for an educational game, each frame can pose more difficult challenges. Keeping ScoreYou don't need to keep score in a game like this. However, if you want, you can keep track of the number of correct matches and the number of incorrect matches. Of course, the number of correct matches will always be the same each time the game is played, because all matches need to be correct for the game to end. To keep track of this, add 1 to a global variable each time a match is made, and each time an incorrect match is attempted. Here is an example: gNumberCorrect = gNumberCorrect + 1 You could do the same with a "gNumberIncorrect" global. Both of these globals need to be set to 0 at the start of the movie. The lines of code that increment the score counters can be placed at the same spot as the puppetSound commands in the "on checkForMatch" handler. In addition, you can set a text member to show the update to the score. You can do this with a new handler that is called every time the score is changed.
on showScore me
member("score").text = "Score:"&&gNumberCorrect&&"correct."&& [cc]
gNumberIncorrect&&"incorrect."
End
These changes can be seen in the script "Drag, Drop and Match Game Behavior w/Score" in the example movie for this chapter. If you turn off script auto coloring by choosing File, Preferences, Script, and then deselecting the Auto Color option, you can see the new lines added in red. You must do this before opening the movie, because Auto Coloring will remove the red color that I have placed on this text. Timing the PlayerAnother way to keep score is to keep track of how long the player takes to complete the match. You can do this by recording the time at the start of the frame, and then checking it against the time when the matching is complete. To record the time, add a property called "pStartTime" and set it to the ticks during the on beginFrame handler. pStartTime = the ticks There are three system properties in Lingo that keep track of the time since Director, the Projector, or the Shockwave applet started. They are the ticks, the milliseconds, and the timer. The ticks and the timer measure 1/60ths of a second, and the milliseconds measures 1/1000ths of a second. The timer can be reset to 0 with the startTimer command. When the matching is all done, you can determine the final time by subtracting the "pStartTime" property from the current value of the ticks. The result is divided by 60 to convert it to seconds. finalTime = (the ticks - pStartTime)/60 You can place this value in a text member to display to the user at the end of the game. Or, you can constantly display the current time. Do this by calling a handler like this in the on exitFrame handler.
on showTimer me
finalTime = (the ticks - pStartTime)/60
text = "Time:"&&finalTime
if member("score").text <> text then
member("score").text = "Time:"&&finalTime
end if
end
This handler not only calculates the time in seconds and creates a string based on that, but also checks the "score" member to make sure that an update is necessary. Because every sprite that uses this behavior will attempt to update the score, and the movie is probably moving at many frames per second, the timer member is not usually in need of an update. Because changing a text member takes time, make sure that the time, in seconds, is different before setting the member to a new value. The code for the timer can also be found in the example movie in the script member named "Drag, Drop and Match Game Behavior w/Timer". Be sure to turn off script auto coloring before opening the movie so that you can see the changes in red. Creative Screen LayoutA simple way to make something different out of this game, without doing any additional coding, is to change the scenario from two columns of items, to more of a collage of images. For instance, the background can be a forest with all sorts of animals: a monkey hanging from a tree, a tiger on the ground, a bird on a branch, and fish in a pond. Then, the moveable sprites are the words "monkey", "tiger", "bird", and "fish". The player, probably a young child for this game, would have to match the words to the animals. RandomnessOne final idea for this game is to add a bit of randomness to the screen layout. You could have the items shuffle on the screen before the game begins. This would place the items in different spots every time the user plays. There are many ways to achieve this. One way is to have an additional behavior placed on the item sprites. This behavior seeks out another sprite with the same behavior and swaps screen positions with it. However, it would maintain the same Score position, so the game knows which items match up with which. Here is a quick randomizing behavior:
on beginSprite me
-- loop and determine all of the other sprites that
-- share this behavior
spriteList = []
repeat with i = 1 to the lastChannel
s = sendSprite(i,#getSpriteNumber)
if voidP(s) then next repeat
add spriteList, s
end repeat
-- pick a random sprite from the list
randomItem = random(spriteList.count)
s = spriteList[randomItem]
-- swap positions with that sprite
newpos = sprite(s).loc
sprite(s).loc = sprite(me.spriteNum).loc
sprite(me.spriteNum).loc = newpos
end
-- return my sprite number to anyone that asks
on getSpriteNumber me
return me.spriteNum
end
This behavior is not perfect. Some of the shuffling techniques we will use in card games later on get more into proper randomization like this. This behavior, for one, has the flaw that it cannot contact sprites further down in the Score from itself because the sendSprite command won't work on sprites that have not yet run their on beginSprite handler. However, for the purposes of this game, it works quite well. | |