court
object
Stores the court's geometric properties (left/right bounds, ground level, net position and size)
let court = {};
player1
object
Stores Player 1's position (x, y), dimensions (w, h), and other properties
player1 = { x: 200, y: 400, w: 20, h: 80 };
player2
object
Stores Player 2's position (x, y), dimensions (w, h), and other properties
player2 = { x: 600, y: 400, w: 20, h: 80 };
ball
object
Stores the ball's position (x, y), velocity (vx, vy), and radius
ball = { x: 400, y: 200, vx: 0, vy: 0, radius: 10 };
playerWidth
number
Width of each player paddle, scaled to screen size
playerWidth = 20;
playerHeight
number
Height of each player paddle, scaled to screen size
playerHeight = 80;
playerSpeed
number
Pixels per frame that a player moves when A/D or arrow keys are held
playerSpeed = 5;
ballRadius
number
The tennis ball's radius, scaled to screen size
ballRadius = 10;
gravity
number
Constant downward acceleration applied to the ball each frame
gravity = 0.3;
serveSpeedX
number
Horizontal velocity given to the ball when served
serveSpeedX = 8;
serveSpeedY
number
Upward velocity given to the ball when served
serveSpeedY = 12;
shotSpeedMin
number
Minimum horizontal speed for a rally shot
shotSpeedMin = 6;
shotSpeedMax
number
Maximum horizontal speed for a rally shot
shotSpeedMax = 9;
shotUpSpeedMin
number
Minimum upward speed for a rally shot
shotUpSpeedMin = 10;
shotUpSpeedMax
number
Maximum upward speed for a rally shot
shotUpSpeedMax = 13;
p1Score
number
Player 1's current score (0 to maxScore)
p1Score = 3;
p2Score
number
Player 2's current score (0 to maxScore)
p2Score = 2;
maxScore
number
First player to reach this score wins the match
const maxScore = 5;
server
number
Index of the player currently serving (1 or 2)
server = 1;
lastHitter
number
Index of the player who last hit the ball (0 = none yet, 1 or 2 = player index)
lastHitter = 1;
gameState
string
Current game mode: 'serve' (waiting for serve), 'rally' (ball in play), or 'gameOver' (match finished)
gameState = 'rally';