ROAD_WIDTH
number
The width of the playable road area in pixels. Controls the total horizontal space available.
const ROAD_WIDTH = 400;
LANE_WIDTH
number
The width of each individual lane, calculated as ROAD_WIDTH / 3. Used for positioning cars and drawing lane markers.
const LANE_WIDTH = ROAD_WIDTH / 3;
CAR_WIDTH
number
The width of a car in pixels. Used for drawing and collision detection.
const CAR_WIDTH = 50;
CAR_HEIGHT
number
The height of a car in pixels. Used for drawing and collision detection.
const CAR_HEIGHT = 80;
PLAYER_MAX_SPEED
number
The maximum forward speed the player car can accelerate to. Limits gameplay difficulty.
const PLAYER_MAX_SPEED = 10;
PLAYER_ACCELERATION
number
How much the player car's speed increases per frame when accelerating. Controls responsiveness.
const PLAYER_ACCELERATION = 0.2;
PLAYER_BRAKING
number
How much the player car's speed decreases per frame when braking.
const PLAYER_BRAKING = 0.4;
PLAYER_FRICTION
number
How much the player car slows down passively each frame when no pedals are pressed.
const PLAYER_FRICTION = 0.1;
PLAYER_STEERING_SPEED
number
How many pixels the car moves left or right per frame when steering, scaled by speed.
const PLAYER_STEERING_SPEED = 0.1;
OBSTACLE_SPEED_MULTIPLIER
number
A factor (0.8) that scales obstacle speed to the player's speed, ensuring they are slightly slower by default.
const OBSTACLE_SPEED_MULTIPLIER = 0.8;
OBSTACLE_SPAWN_INTERVAL
number
The minimum number of frames between obstacle spawns. Smaller values increase difficulty.
const OBSTACLE_SPAWN_INTERVAL = 100;
OBSTACLE_MIN_GAP
number
The minimum vertical distance (in pixels) between obstacles to prevent them from stacking.
const OBSTACLE_MIN_GAP = 200;
SCORE_INCREMENT_INTERVAL
number
The number of frames between each score increment. Controls how fast the player's score increases.
const SCORE_INCREMENT_INTERVAL = 60;
playerCar
object
An instance of the Car class representing the player-controlled blue car.
let playerCar = new Car(200, 300, true);
obstacles
array
An array of Car objects representing all active red obstacle cars on the road.
let obstacles = [];
roadScrollY
number
Tracks the vertical scroll position of the road's lane markings, enabling smooth animation.
let roadScrollY = 0;
score
number
The player's current score, incremented every SCORE_INCREMENT_INTERVAL frames.
let score = 0;
gameState
string
A string that tracks the current game state: 'menu', 'playing', or 'gameOver'.
let gameState = 'menu';
lastObstacleSpawnFrame
number
Records the frameCount when the last obstacle was spawned, used to throttle spawning rate.
let lastObstacleSpawnFrame = 0;
lastScoreIncrementFrame
number
Records the frameCount when the score was last incremented, used to throttle score updates.
let lastScoreIncrementFrame = 0;