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

Game Overview

The example movie on the CD-ROM does not offer many options. The puzzle matrix is locked in at 15[ts]15, and specific methods are used to both select and mark words that are found. Even with these assumptions in the code, the game contains two fairly lengthy behaviors.

Lets take a look at what elements go into this game. Figure 16.1 shows the Stage with a game in progress. You can see several words that have already been found, as well as one in the process of being selected.

Figure 16.1
Letters that are grayed out are in words that have been found, and words are highlighted as the user is connecting the letters to find them.

The Matrix

The main playing element here is a matrix of letters. This matrix is a text member with 15 rows of 15 characters each. Actually, each row contains 30 characters, with a space after each letter to widen the grid.

The characters use a monospaced, or fixed-width, font, so they all line up regardless of which characters are chosen. The height of the lines in the member is also altered so that the height of a line and the width of two characters are exactly the same. This makes for a nice, square matrix of letters.

The Word List

Next to the matrix is a list of words that can be found. This list is a non-interactive part of the game. It simply starts off containing all the hidden words, and shrinks as words are removed from it. The user doesn't click on it or anything.

Selecting a Word

In a pencil and paper version of word search, a player selects a word by circling it in the matrix. To translate that action into something that can be done with a mouse is tricky, but can be accomplished with a line sprite.

Line sprites are made by drawing a line on the Stage with the line tool. Lines are defined by their rectangle on the Stage, and whether the line is drawn from the upper left to the bottom right of the rectangle, or the upper right to the bottom left. We will use Lingo to set both of these properties of the line, as well as an extra-wide line width.

This line appears underneath the matrix sprite, which uses the "background transparent" ink. The line uses a shade of gray to stand out from the white background, while at the same time, allow the black letters to stand out from it.

Marking Words

Although the line serves as a way to highlight the word that the player is indicating, another method is used to mark words that have been previously found. The method is to change the color of letters in the matrix.

Populating the Matrix

A lot of the game code is involved with the initial populating of the matrix. Each word is randomly laid into the matrix. However, as it fills up, there are fewer and fewer spaces to fit each word. We have to watch for the case where the matrix fills up before the list of words is exhausted.

The manner in which the words are placed into the puzzle is also important. A simple word search game has words laid in horizontally and vertically. However, a more complex game has them diagonally as well. We are going to go one step further and have the words sometimes appear backwards. This gives us a total of eight ways in which a word can appear in the matrix: horizontally, vertically, diagonally down, and diagonally up. Then, of course, the words could be backwards in each of these placements, which gives us a total of eight ways.