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 9 Section 2

Game Overview

The Lingo code at the heart of this game takes mouse clicks and records them as hits or misses. The cursor becomes a gun sight, and the mouse button becomes the trigger.

The rest of the code concerns itself mostly with the movement of the targets. A good shooting gallery should have targets that move in all sorts of different ways, at different speeds, and pop out at different times.

Figure 9.1 shows one way that a shooting gallery game can be set up. It resembles a carnival shooting gallery. Ducks move across the bottom of the screen and up and down the sides. Three ducks near the bottom pop up occasionally, and three ducks behind the block in the center rotate around, popping their heads up like clockwork.

Figure 9.1
This shooting gallery game is set up like a carnival booth.

Another way to set up the game that is more challenging is to have all the ducks hide behind objects, occasionally peeking out with great irregularity. Figure 9.2 shows what this could look like. The three ducks on either side and the two ducks at the bottom appear every once and a while, at random. The player has to keep guessing where the next one will appear.

Figure 9.2
A shooting gallery game where all the targets hide and appear at random.

Types of Animation

The games shown in the two previous figures actually contain six different types of movement. Instead of creating six different behaviors, we'll create one behavior that handles them all.

The first two types of animation are a simple vertical and a simple horizontal movement. In the first case, the target moves up a certain number of pixels and then back down. The second has the target moving first left and then back to the right.

The next animation makes the target move in a circle of a certain radius. It should be able to move both clockwise and counter-clockwise.

The fourth animation shrinks the target vertically, holding the bottom at the same position on the screen. This causes the target to appear as if it is falling backwards, like it was hinged at the bottom.

The last two animation types allow the target to move continuously across the screen or up or down it. The difference between these and the first two animations is that the targets move until they cross the screen, and then appear again on the other side.

For all these types of animations, we should be able to vary the speed. For some, we should be able to change the distance traveled. For the circular movement, we need to be able to change the radius of the circle.

We should also be able to change the starting point for each animation. So, for instance, we can tell the target where in the circle to start in the case of a circular animation.

Random Appearances

If targets appear at regular intervals during the game, then the player only has to wait, cursor positioned at the right spot, and click at the right time.

To avoid this, there should be an element of randomness in the game. So, between animations, the targets should pause for a random length of time.

The pause should occur, of course, at a time when then target is out of harm's way. The behavior should allow us to set a value that determines how often the target begins an animated sequence.

Limited Ammunition

For a game like this we should keep score. For the score to mean something, we need to limit the playing time.

One way to do this is to have a timer so that the user has to hit as many targets as quickly as they can. Another way is to limit the number of shots that the player has.

For this example, we will only allow a limited number of shots. The score is then determined by the number of shots that actually hit targets.

Screen Elements

Only a few simple screen elements are required for this example game. However, you will want to have much more elaborate artwork for the game you create.

The first thing you need is a target. Or, if you prefer, many different types of targets. In the example game, I used a simple duck silhouette.

In addition, you need background art, as well as foreground art. The latter is important because it will be used as objects that the targets can hide behind. In the example game I just used simple blocks.

Point Values

Not every target should offer the same level of difficulty. Some will move faster and appear less frequently.

Our target behavior should allow us to set point values for each individual target. These will be the points awarded to the player when he or she hits the target.

Special Effects

The most important special effect here is the cursor. Because this is a shooting game, the cursor should reflect what you would see when looking through a gun sight.

We also need a little "blast" graphic to appear on the screen when the user takes a shot. This graphic appears only when a shot misses. Both the shot graphic and the cursor appear in figure 9.6.

Figure 9.6
The Cast window shows the bullseye cursor and a small graphic to briefly mark where a shot has been fired.

However, there should also be a screen reaction when the user hits. In that case, we will simply swap out the sprite's member with a new graphic. This will also signal to the player that he or she has already hit the target and should not attempt to do so again.

Of course, sound effects are a good addition to this game. A gunshot sound is an easy one, but you can also use sounds to reflect the targets. You can use different shot sounds for a hit or a miss.