Hardware Reference
In-Depth Information
The first thing to do in the
server program is to define the
variables. They're grouped here
by those needed for keeping
track of clients, versus those
needed for managing the
graphics of the game play.
8
// include the net library:
import processing.net.*;
// variables for keeping track of clients:
int port = 8080; // the port the server listens on
Server myServer; // the server object
ArrayList playerList = new ArrayList(); // list of clients
// variables for keeping track of the game play and graphics:
int ballSize = 10; // the size of the ball
int ballDirectionV = 2; // the ball's horizontal direction
// left is negative, right is positive
int ballDirectionH = 2; // the ball's vertical direction
// up is negative, down is positive
int ballPosV, ballPosH; // the ball's horizontal and vertical
// positions
boolean ballInMotion = false; // whether or not the ball should be moving
int topScore, bottomScore; // scores for the top team and the bottom teams
int paddleHeight = 10; // vertical dimension of the paddles
int paddleWidth = 80; // horizontal dimension of the paddles
int nextTopPaddleV; // paddle positions for the next player
// to be created
int nextBottomPaddleV;
boolean gameOver = false; // whether or not a game is in progress
long delayCounter; // a counter for the delay after
// a game is over
long gameOverDelay = 4000; // pause after each game
long pointDelay = 2000; // pause after each point
 
Search WWH ::




Custom Search