CS333 Lab P2-2:
Distributed Multiplayer Games

Goals of this lab:


In this lab, you will write a distributed game that uses interactive computer graphics to allow two people to play "air hockey" across a network. Recall that the game air hockey is played with a circular puck that glides on a cushion of air and (typically two) circular paddles. Each player uses a paddle to protect his/her goals and to direct the puck into the opponent's goal. Each goal scores one point.

Your air hockey game will have a Playground module for each player and a centralized game controller that will handle interactions among the players. The player modules will communicate their paddle positions to the game controller, which will compute the position of the puck and the current score. You will start by implementing a two-player game. Although your game will have players across the network, the implementation will not be "fully distributed" because there will be a centralized module (the game controller) responsible for the interactions among them. After you write your game, you should think about what kinds of problems would need to be solved in order to distribute the functionality of the game controler.

In order to simplify the implementation, we will make the following assumptions that will allow the puck to travel at a constant velocity.

Once your game is running, you may want to work on dropping some of these assumptions.


Read over the entire assignment before starting. Then, follow the instructions step by step.

  1. Air Hockey Physics: Suppose that the puck has center x,y and radius r and is moving along vector v, and suppose that the boundary (walls) of the playing field is given by a rectangle (x1,y1,x2,y2) with goals occupying the middle third of each end of the field. Given the above assuptions, write equations (and then procedures) for the following.
    1. The position of the puck after time t has elapsed, assuming it has not hit anything.
    2. The new motion vector for the puck after it hits a wall. (Walls are perfectly straight, so they are perfect reflectors.)
    3. The new motion vector for the puck after it hits a paddle with center px,py and radius pr. We've done this one for you.
    4. A boolean function that determines whether or not the puck has collided with a wall.
    5. A boolean function that determines whether or not the puck has entered the goal.
    6. A boolean function that determines whether or not the puck has collided with a paddle.

  2. The Game Controller: The main task of this assignment is to write the game controller. Your controller should have the following entries in its presentation.
    the playing field: upper left corner
    externally writable
    the playing field: lower right corner
    externally writable
    puck position
    the x,y position of the puck, externally readable
    puck radius
    the size of the puck, externally writable
    player1 position
    the x,y position of player1's paddle, externally writable
    player2 position
    the x,y position of player2's paddle, externally writable
    paddle radius
    the size of the paddles, externally writable
    The game controller has a main loop that, based on the laws of physics you considered above, is responsible for continuously updating the position of the puck (on the basis of the positions of the paddles) and keeping track of the score of each player. EUPHORIA updates the drawing about 15 times per second, so your loop should contain a PGsleep of about 0.04 seconds to allow for calculation time. At the beginning, each player has zero points and the puck is at the center of the field, moving in a random direction. After each point is scored, the new score is printed. Then, there is a brief delay and the puck is returned to the center of the field and it begins moving in a new random direction. After either player reaches 10 points, the game starts over again.

  3. The Players: Using EUPHORIA, construct the playing field, the puck, the goals, and the paddles. Use the built-in constraint mechanism to restrict the paddles to the appropriate regions of the playing field, set the sizes of the puck and paddles, etc. Publish the required sizes and positions of the objects for use by the controller and the other player. Assume that both players use the same set-up in Euphoria.

  4. The Configuration: Bring up two instances of Euphoria on different displays. Let one of these be player1 and the other be player2. Let each player get the puck position from the controller. Connect player1's paddle position to the controller and to the paddle1 position in player2's display. Similarly, connect player2's paddle position to the game controller and to the paddle2 position in player1's display.

  5. Doubles (optional): Modify your game to allow four players at a time, two per team.

  6. Tournament (optional): First, obtain and read the handles supplement to the Playground manual. Using handles, add a tournament module that will manage a ladder of at least 8 players in singles play. The tournament module will match up players, look at the final score, and then match up players based on the outcome of each game.
Have fun!

To receive credit for this lab, you should:

  1. Clean up and print out your code. (Don't turn it in, but save it for your code/design review.)

  2. Turn in a Project Evaluation Form near the beginning of class on the day you want to do your demonstration and code/design review. You should be prepared to demonstrate your working application, explain your design and code, and answer questions.