ROAD_WIDTH
number
Defines the pixel width of the playable road area; the road is divided into three equal lanes.
const ROAD_WIDTH = 400;
LANE_WIDTH
number
The width of each individual lane; calculated as ROAD_WIDTH / 3 so lane markings and spawning are consistent.
const LANE_WIDTH = ROAD_WIDTH / 3;
CAR_WIDTH
number
The pixel width of cars; used for drawing boxes and collision detection.
const CAR_WIDTH = 50;
CAR_HEIGHT
number
The pixel height of cars; used for drawing boxes and collision detection.
const CAR_HEIGHT = 80;
CAR_DEPTH
number
The Z-axis thickness of 3D car boxes; makes them appear as solid blocks in 3D space rather than flat squares.
const CAR_DEPTH = 40;
PLAYER_MAX_SPEED
number
The maximum speed the player car can accelerate to; prevents runaway speed and keeps the game playable.
const PLAYER_MAX_SPEED = 10;
PLAYER_ACCELERATION
number
How much the player's speed increases per frame when holding the up arrow; controls how quickly the car speeds up.
const PLAYER_ACCELERATION = 0.2;
PLAYER_STEERING_SPEED
number
How many pixels the car steers left or right per frame when holding arrow keys; controls steering responsiveness.
const PLAYER_STEERING_SPEED = 0.1;
OBSTACLE_SPAWN_INTERVAL
number
Number of frames to wait between spawning new obstacle cars; controls difficulty by setting obstacle frequency.
const OBSTACLE_SPAWN_INTERVAL = 100;
OBSTACLE_MIN_GAP
number
Minimum vertical pixel distance between spawned obstacles; prevents them from spawning too close together.
const OBSTACLE_MIN_GAP = 200;
playerCar
object (Car instance)
The player's blue car object; updated each frame with input and checked for collisions.
let playerCar;
obstacles
array of Car objects
Array of all active red obstacle cars currently on the road; checked for collisions and removed when off-screen.
let obstacles = [];
roadScrollY
number
Vertical offset for animating the lane markings; incremented by player speed to create scrolling effect.
let roadScrollY = 0;
score
number
The player's current score; incremented every SCORE_INCREMENT_INTERVAL frames and displayed in the HUD.
let score = 0;
gameState
string
Current game state: 'menu' (title screen), 'playing' (active game), or 'gameOver' (crash); controls which UI and game logic runs.
let gameState = 'menu';
CAMERA_TILT
number (radians)
The rotateX angle that tilts the camera forward; creates perspective effect making road recede into distance.
const CAMERA_TILT = Math.PI / 6;
uiFont
p5.Font object
Loaded font used for rendering text in WEBGL mode; ensures crisp, readable menu and HUD text.
let uiFont;