CS333 Lab P2-2:
Distributed Multiplayer Games
Goals of this lab:
- Write a distributed "Air Hockey" game.
- Learn about some of the difficulties of real-time interaction in an
asynchronous distributed system.
Introduction:
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.
- The puck glides on a frictionless surface.
- The puck, walls, and paddles do not deform, so they do not
absorb any energy on impact.
- The paddles are considered to be stationary objects when the
puck hits them.
- In a two-player game, each player's paddle is constrained to the 1/3
of the playing field in front of his/her goal.
In a four-player game (extra credit), each paddle is
constrained to half of that area (1/6 of the field).
Once your game is running, you may want to work on dropping some of
these assumptions.
Directions:
Read over the entire assignment before starting.
Then, follow the instructions step by step.
- 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.
- The position of the puck after time t has elapsed,
assuming it has not hit anything.
- The new motion vector for the puck after it hits a wall.
(Walls are perfectly straight, so they are perfect reflectors.)
- 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.
- A boolean function that determines whether or not the puck has
collided with a wall.
- A boolean function that determines whether or not the puck has
entered the goal.
- A boolean function that determines whether or not the puck has
collided with a paddle.
- 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.
- 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.
- 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.
- Doubles (optional): Modify your game to allow four players
at a time, two per team.
- 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:
- Clean up and print out your code. (Don't turn it in, but
save it for your code/design review.)
- 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.