A Crash Course
in Game Design and Production
Questions and Answers
Question: I've heard of "masking" before, but I don't understand its use. What is the mask? How is the masking color important/used?
Answer:For our purposes, masking is removing anything in the sprite we don't want to draw on screen. Remember that the sprite image is rectangular, but pacman, say, is round. We don't want to draw a big black rectangle with pacman in it on top of the background, we want to draw only the pacman-shaped part, and leave the background around him intact. If we drew the whole rectangular image, it would cover up the dots in the maze, as well as the bonus objects, and ghosts. Here's an example of masking:
when the sprites are drawn overlapping each other, the unwanted area (in red) covers up the background, as well as portions of the other sprites. We don't see the dot in Snacky's mouth, nor the one above and below Pinky. If our masking color is black, as in the bottom middle image, it looks better, but snacky is still cut off by Inky and Inky is cut off by Pinky, and you still can't see the covered dots. In our Sprite Draw routine, we will look for any pixels in the sprite that are the masking color, in this case red, color 0 in the palette, and not draw them. The way we'll do that is by replacing the red pixels with whatever color is in the background in that position. Depending on what's being drawn when, that may include parts of other sprites that were drawn previously. In the Bottom-Right image, Snacky was drawn first, then Inky, Pinky, and Clyde. So Snacky has a dot in his mouth, and Inky is overlapping Snacky, and Clyde is overlapping Inky properly. Also the dots above and below Pinky can be seen.
The actual color you use for the masking color isn't important, but it's position in the palette is. Every sprite should use the SAME masking color in the same position in the palette. I usually use color 0 in the palette - the first one. I usually set the masking color to bright red (or bright green, or some arbitrary bright color I'm not using for the art) and fill in all the "black" space around my sprites with it, so I know what will be masked out. To make the contact sheet for Snack easier on the eyes so you can see the art, I remapped the masking color to black again.
Question: How do you anticipate the frames/second for animations? This is important because if you can only display four frames/sec it will require a different "animation set" of sprites than if the framerate is 10/sec.
Answer: In our game, we will be increasing the frame rate slightly each level, so it gets faster and faster as you play, the animations will play faster and faster as we go. This is all controlled by a speed throttle in the game, so no matter what computer speed you're playing on, it will run at the same speed. Our starting rate is around 25 frames per second. You can use the same animation set for all speeds. For example, the Info Bar at the bottom of the screen is only 4 frames, and it changes every 10 frames or so. I have a counter that keeps track of what frame I'm on, and I check it every frame and only update the animation when it's time to do so. One easy way to do this is to count by fractions. Euphoria rounds down to the nearest integer when doing sequence indexing, so if say Bar is frame 1 of yoru animation, Bar is frame 2...Bar is frame 4, you can say a=a+.2, draw Bar[a] and it will appear to change only every 5 frames. It draws frame 1 on frames 1-4, when a=1.0,1.2,1.4,1.6,1.8, and then draws frame 2 when a=2.0,2.2,2.4,2.6,2.8
I'm doing this for the InfoBar, as well as for the animated logo, and the energizers, which cycle half as fast as the game clock. Flashing faster than that tends to give people seizures, so I'm refraining from going all out on that!
usually draw an animation that looks good and then adjust the
animation timing to the game clock. Snacky has 6 frames to open and
close his mouth - Pacman had only 3! His death animation is 10 frames
and it's timed to finish when the death sound effect is done. Most of
the game messages - Logo, Game Over, Get Ready!, etc, are all 10
Question:3. I'm used to being able to press a turn key before a turn and having "Snacky" turn. It's basically a one-keystroke buffer, so if Snacky is traveling leftward on the screen and he's approaching an intersection where he can go upward, I want to be able to press the up arrow key prior to his arriving at that spot and having it register so that he turns upward at the intersection. The buffer can maybe be timed, so the keystroke is only valid for half a second or something, but this, IIRC, is standard Pacman user-interface behavior.
Answer: I think I'm clearing the keyboard too often, so the controls are slightly sluggish. I play Pacman and MsPacman on an emulator very frequently, and the keyboard controls on that perform similarly. I actually only check the keyboard when snacky can make a valid direction change - every 10 frames horizontally and every 8 frames vertically, but the key reader should hold the keypress that long.