| CS306 | Processing Systems and Structures | Lockwood, Spring 2002 | Vanessa Clark, Sam Gross, Crystal Miller |
This program creates a juggling simulation game that allows the user to toss and catch three balls as long as the rules of juggling are maintained. The rules of juggling are as follows: there must always be more balls in the air than in the hands. The game begins with one ball in a hand and two balls in the air. From there, the user must use the keyboard keys to toss a ball from either hand. A unique aspect to this game is that the user can hold the toss key down longer to make the balls toss higher. However, the hand must return from the toss motion before the balls in the air fall past it. If a ball drops or a hand catches more than one ball, the game ends. Otherwise, play continues. The user can select various backgrounds of the game, as well as different faces of the juggler.
Key Guide
"f" key - changes juggler's face
"b" key - changes game background
"z" key - left hand toss
"/" key - right hand toss
"+" key - increase game speed
"-" key - decrease game speed
"n" key - new game
"q" key - quit
There are a few challenging aspects of this program. First, it requires directly handling input from the keyboard using an interrupt service routine, instead of using an external library routine for this purpose. Also, it requires continuously updating the screen since the positions of many objects in the game can change without user intervention. The program will also have to make use of the laws of physics to calculate the trajectories of the balls as they are thrown from one hand to the other.
First of all, there is a keyboard handler that reads from the keyboard how long a key is pressed down. UpdateScreen, the procedure that calls all the other procedures in the program is run periodically to display the current state of the game. It calculates the velocities of the objects in the game, including the balls and arms and determines where to display them on the screen. The arms move in the same pattern when they throw each ball, but the balls move in a different (calculated) position depending on how long the key was pressed. The graphics used will be .bmp format and be displayed using mode 13h.
Used to draw these objects: background, leftArm, rightArm, ballOne, ballTwo, ballThree, face
This procedure contains a local integer variable that keeps track of which face is currently displayed, and increments this number (that corresponds to a pointer to an image) and changes the face variable accordingly.
This procedure contains a local integer variable that keeps track of which background is currently displayed, and increments this number (that corresponds to a pointer to an image) and changes the backgroundImage variable accordingly.
According to which key has been pressed (AH), this procedure writes to the appropriate left/rightHandState variable the constant "throwing." It also updates left/rightThrowStrength with a number calculated from speed and number of repeats (AL) appropriate for use by UpdateScreen.
This procedure updates the positions and velocities of the moving objects in the game according to the laws of physics. It also detects whether the user has lost the game due to dropping a ball or catching two and handles that case appropriately. It also updates the value of ballState and leftHandState or rightHandState if a ball is thrown or has been caught.
Calls drawObject as appropriate to draw all game objects on the screen (face, background, balls, hands). If game is over (gameState == gameOver), a frown face will be drawn.
Sets the value of all position, velocity, gameState, left/rightHandState. Calls updateState and updateScreen in a loop until game is over.
The keyboard handler, which is installed when the program is loaded and uninstalled when it is exited, handles requests from INT 9 (IRQ 1, keyboard) and causes the game to respond appropriately.