Note About This Book: Advanced Lingo For Games was written by Gary Rosenzweig in 2000 for users of Macromedia Director 7. It is presented here for free on an as-is basis, with no updating. Most of the information and code here can be used in the most recent version of Director. The book has been reproduced from the final editing files archived in 2000, and not the final proof galleys. So some minor differences between this version and the printed version my exist. The entire contents of this book are Copyright 2000, Gary Rosenzweig. No part may be reproduced or copied without written permission. The text here is provided for individual use only.
Want to thank me for making this book available for free? Just buy Special Edition Using Macromedia Director MX and we'll call it even!

Advanced Lingo For Games
by Gary Rosenzweig


Chapter 13 Section 2

Game Overview

The main aspects of a trivia game are the display of the question and the interface to let the user answer. There are many ways to do this of course, but for our example, we will use questions with a choice of four answers. So a sample screen will look something like Figure 13.1.

Figure 13.1
Each turn in the trivia game consists of a question and four possible answers.

The Question Database

The hardest part of making a trivia game is actually not the code, it's coming up with the trivia questions themselves. It sounds easy enough to come up with a dozen or so, but you need at least a few hundred to make a decent trivia game. However, if you are making a short, educational questions and answers game, you may be fine with only a dozen questions.

The questions should be plain text and in a format that makes it easy for a non-programmer to create them. This way, you can do all the work of making the trivia game, and someone else, or a whole group of people, can make the questions. In the sample game on the CD-ROM, the questions are stored in a text member, with one question per line. Here is an example:


What is the fastest animal on Earth?;Spotted Leopard,Cheetah,Giant Turtle,Llama;2

The format of each line starts with the question, followed by a semicolon. Then there are the four answers, each separated by a comma. Finally, there is another semicolon and then a number that represents the position of the correct answer.

Screen Layout

Looking at Figure 13.1, shown previously, you can see the basic screen layout. There is the question above the four answers. Next to each answer is a button. When the question appears, the player must decide which answer is correct and click its button.

The question is a text member and so are each of the four answers. The button next to each answer is a bitmap member.

Buzzing In

In addition to the four buttons on the screen, the player will also be able to use the keyboard to answer the questions. Each button is mapped to a different key on the keyboard. Because the buttons shown earlier in Figure 13.1 are labeled "A" through "D", those same keys are used.

It's the responsibility of the frame behavior to handle keyboard messages. However, we'll use the button behaviors to map the keys to the buttons. To do this, we make the frame behavior pass on the key presses to the sprite behaviors, which will then determine if one matches a button.

Time Running Out

To make the game more exciting, a timing element is involved. When the player is first asked the question, they can earn 1,000 points by immediately answering correctly. However, with each frame loop that goes by, the amount of potential points they can earn decreases by one. So, if they take one second to answer, and the movie is playing at 15 frames per second, they will only get 985 points. This adds a sense of urgency to the game.

Penalties

So what if the player gets the wrong answer? Instead of just scoring zero points and moving on, they are penalized. If they answer incorrectly, they will have 100 fewer potential points. So a player that takes one second to answer, but gets it wrong, and then takes another second to try another answer, and gets it right, will score 870 points. This is because they lost 15 points waiting the first second, then they lost 100 points with a wrong answer, and then they lost another 15 points waiting another second. 1,000[ms]15[ms]100[ms]15 = 870.

Disappearing Answers

In addition to losing points when the player guesses wrong, they will also see that answer's button removed from the screen. This prevents them from choosing the same wrong answer twice. It also helps them think more clearly about the remaining answers.

Special Effects

We'll need sounds for both right and wrong answers. We'll also want to put a little thought into the answer buttons on the screen. Because they are the primary interface through which the user interacts with the game, they should behave somewhat nicely, with a down state and proper button behavior.