| ACG home | SaneDraw home | Instructor home | learning resources home | class home | handouts index |
Outline of the third phase of the project
After completing the layout and logic of the game, we need to add the basic "niceties" that will make it usable.
Edit the initialization movie script created in the previous session to support the new features we will add now.
Add a button to scramble the gamepieces.
Add a button to reset the pieces to their correct locations.
Add a text cast member with help on how to use the game, and a button to show and hide this info.
Add another text cast member with the credits for the game, and a matching show / hide button.
Import sounds for the various gameplay events.
Modify the scripts to play the sounds at the appropriate time.
Run and test the movie. When done, use the Afterburner Xtra to convert the movie to Shockwave for Director format.
If you have the Shockwave plugin properly installed in your browser, you can see a working example of this third version of the puzzle. You can also download an editable copy of the original Director movie (Director 5 for Macintosh format, Stuffed and BinHexed, 60,485 bytes).
After the movie is up on the screen, you may need to again position and size the stage:
File-->Preferences-->General, uncheck "Centered".
Modify-->Movie-->Properties, enter 240 x 240 for the size, 0 and 20 for the location.
Edit the Initialization movie script
The Initialization script is the cast member that contains the 'on startMovie' handler. If you have trouble locating it, you can ask Director to find it for you:
Use the Edit-->Find-->Handler command to display
a list of the handlers in the current movie. Double-click on the
startMovie
entry (there should be only one) to open the script
window with
the initialization movie script.
Edit the text so that the entire script reads:
---------- Puzzle 03 -- phase 3 of the Puzzle project ------------ --------- Copyright 1996 by Sandro Corsi (corsi@ibm.net) --------- --The scripts in this movie assume that the cast members with the --images of the gamepieces are arranged sequentially at the --beginning of the internal cast. The cast member for the missing --piece (an unfilled, unstroked box shape) is the last gamepiece --cast member. --It is also assumed that the gamepiece sprites are arranged --sequentially in the score, after any mumber of sprites used --to create the background of the gameboard. The sprite for the --missing piece comes right after the gamepiece sprites. ------------------------------------------------------------------ on startMovie --------------- declare global variables --------------- -- game size specifications global gNumberOfSquares, gSquaresPerRow -- Squares (= available positions for gamepieces) global gSquareList, gSquareChannelStart, gHoleColumn, gHoleRow -- how extensively should the gamepieces be scrambled global gScrambleRepeats -- names of sound cast memebers global gFrameSnd, gNoMoveSnd, gMoveSndList -- sprite numbers of help and credits text global gHelpSprite, gCreditsSprite --------------- initialize global variables --------------- put 16 into gNumberOfSquares -- total available Squares put 4 into gSquaresPerRow -- how many Squares wide is each row put [] into gSquareList -- list of child objects representing Squares put 2 into gSquareChannelStart -- first channel containing Square sprite put 20 into gScrambleRepeats -- number of random moves when scrambling put "Metal" into gNoMoveSnd -- sound for click on piece that can't move put "Penalty" into gFrameSnd -- sound for click on gameboard frame -- sounds chosen at random for clicks on gamepieces that can move put ["Gabing","Pavel","Swhish","Whip"] into gMoveSndList put 47 into gHelpSprite -- channel for help text puppetSprite gHelpSprite, TRUE -- put help text under script control set the visible of sprite gHelpSprite to FALSE -- initially hidden put 48 into gCreditsSprite -- channel for credits text puppetSprite gCreditsSprite, TRUE -- put credits text under script control set the visible of sprite gCreditsSprite to FALSE -- initially hidden -- initialize missing gamepiece position to be the last Square put (gNumberOfSquares-1) mod gSquaresPerRow+1 into gHoleColumn put (gNumberOfSquares-1)/gSquaresPerRow+1 into gHoleRow --------------- create Square objects --------------- repeat with SquarePosition = 1 to gNumberOfSquares append gSquareList, new(script "SquareParentScript", SquarePosition) end repeat updateStage -- force redraw end
Press <Enter> (on the numeric keypad) to close and recompile the script. If any errors are reported, double-check your spelling.
Create button to scramble the gamepieces
Since we want to keep file size as small as possible, consider creating a small design that can be enlarged on the stage. Also, it is possible to colorize 1-bit castmembers and create a colorful effect with very little memory use.
Use your favorite method to create a blank new bitmap cast member (e.g., Window-->Paint, then click the '+' button)
Use the painting tools to create an icon for the scrambled gameboard. Keep your design simple so it will work at a small size and with few colors.
Experiment with lower bit depths (=fewer colors, smaller file size):
Drag the cast member to the score, in a frame 1 channel after the game piece cells (the exact channel number does not matter in this case). Reposition and/or resize the button on the stage so that it does not block the view of game pieces.
Experiment with colorizing your button (this works best at 1 or 2 bits):
Select the button in the cast window, then click on the script button at the top-right of the window to attach a script to the cast member. The Script window will open with a blank new script. Enter the following:
on mouseUp global gSquareList, gScrambleRepeats repeat with counter = 1 to gScrambleRepeats -- invoke the move handler for randomly selected square movePiece getAt(gSquareList, random(count(gSquareList))) end repeat end
Verify and close the script.
Create button to reset the gamepieces
This button will be very similar to the previous one. You could duplicate the 'Scramble' cast member (use Edit-->Duplicate), then make the necessary modifications.
Follow the directions above for the creation of this button's bitmap cast member, or modify the copy of the previous button.
When done, attach to the new cast member the following script (if you started from a copy of another cast member, make sure to delete the old script first):
on mouseUp global gSquareList, gNumberOfSquares, gSquaresPerRow global gHoleColumn, gHoleRow repeat with counter= 1 to count(gSquareList) -- invoke the setPicture handler for each square with -- the default cast member number setPicture getAt(gSquareList, counter), counter end repeat -- initialize missing gamepiece position to be the last Square put (gNumberOfSquares-1) mod gSquaresPerRow+1 into gHoleColumn put (gNumberOfSquares-1)/gSquaresPerRow+1 into gHoleRow end
Verify and close the script.
Drag the cast member to an available channel after the game piece cells in frame 1 of the score (the exact channel again is unimportant). Reposition/resize the button on the stage as needed.
Create button and text to display help
This step requires both a bitmap cast member for the button, and a text cast member for the help display. Note that the text sprite must be in a specific channel for the scripts to work:
Follow the previous instructions to create the bitmap cast member for the button. The icon for the button should indicate that a help message will be displayed (the most widely used symbol for this is a question mark).
Attach the following script to the new cast member:
on mouseUp global gHelpSprite set the visible of sprite gHelpSprite to not the visible of sprite gHelpSprite end
Notice that there are only four lines in this script. The third one is rather long and it may have wrapped if the web browser's window is not wide enough--make sure it is entered as a single line in Director.
on mouseUp global gHelpSprite set the visible of sprite gHelpSprite to FALSE -- hide me end
Drag the new text cast member to channel 47, frame 1 of the score.
gHelpSprite
global in the
startMovie
handler.
While the text sprite is still selected on the stage, drag its handles to resize it (or use Modify-->Sprite-->Properties and enter the desired size and location).
Drag the bitmap cast member for the button to the score, after the game piece cells in frame 1 (any channel will do). Reposition/resize the button on the stage as needed.
Create button and text to display credits
The starting point for these two elements can be duplicates of the previous two, though the text cast member in this case will likely be smaller.
Follow the directions above for the bitmap cast member for the button. This time the icon should indicate that info about the author of the game will be provided (in HyperCard, this is often done with a speech balloon icon).
Attach the following script to the new bitmap cast member:
on mouseUp global gCreditsSprite set the visible of sprite gCreditsSprite to not the visible of sprite gCreditsSprite end
Notice again that there are only four lines in this script. The third one may wrap on multiple lines if the web browser's window is not wide enough--make sure it is entered as a single line in Director.
Attach the following script to the new text cast member:
on mouseUp global gCreditsSprite set the visible of sprite gCreditsSprite to FALSE -- hide me end
Drag the new text cast member to channel 48, frame 1 of the score.
gCreditsSprite
global in the
startMovie
handler.
Drag/resize as needed on the stage. To allow for simpler scripts, make sure that the new sprite does not overlap the help sprite.
Import sounds to highlight game events
Director for Macintosh will import sounds of types AIFF and System 7 'snd ' (only the 'snd ' resources can be in compressed format, and only for Macintosh playback).
File-->Import. In the dialog, uncheck 'Linked',
and make sure that the 'Show' pop-up menus indicates 'All Files' or 'Sounds'.
Find and select the file containing the sound you want to use, and click
'Import'.
The new sound appears in the cast window. Select its name in the Cast Member Name field at the top of the window, then use Edit-->Copy Text.
In the on startMovie
handler, find the global
variable that corresponds to the event highlighted by this sound, and change
its value by pasting in the name of the sound.
gFrameSnd
holds the name of the sound played when the
user clicks on the frame of the game board.
gNoMoveSnd
plays when the user clicks on a game piece that
cannot move.
gMoveSndList
is a list of sound names, one of which is
selected
randomly to play when the user clicks on a game piece that can move.
Repeat the process for additional sounds.
Modify scripts to play imported sounds
No new handlers are needed, but two of the existing ones must be modified to replace plain beeps with the sounds you imported.
Find the click
handler in
SquareParentScript
(again, you can use the
Edit-->Find-->Handler command).
Edit the text so that the entire handler reads:
on click me global gNoMoveSnd, gMoveSndList if pieceCanMove(me) then -- play a randomly selected sound puppetSound getAt(gMoveSndList, random(count(gMoveSndList))) -- invoke the move handler for this same object movePiece me else puppetSound gNoMoveSnd -- bad choice end if end
Note that the other handlers in this script need not be changed.
Find the gameClick
handler in the gameplay
movie script.
Edit the text so that the entire handler reads:
on gameClick whichSprite --this handler responds to user input based on the part --of the game board clicked global gSquareChannelStart, gSquareList global gFrameSnd if whichSprite < gSquareChannelStart then puppetSound gFrameSnd -- that's the frame of the gameboard! else --find which Square location was clicked put whichSprite - gSquareChannelStart + 1 into position --tell the Square to respond to the click click getAt(gSquareList, position) end if end
Use the Afterburner Xtra to convert to Shockwave for Director format
The cmmands used in this step of the project will only be available if the Shockwave XTras are properly installed.
Xtras-->Shockwave for Audio Settings. In the dialog,
choose the following settings, then click
'OK':
File-->Save and Compact.
Xtras-->Afterburner. You will be prompted for a filename: type it in, then click 'Save'.
The file created by Afterburner can be referenced from an HTML Web page using the following tag:
<EMBED SRC="somename.dcr" HEIGHT="heightInPixels" WIDTH="widthInPixels">
where the actual name and size of your movie replace the italicized placeholders.
Copyright by Sandro Corsi. Last modified 17 OCT 96.