player
object
Stores the player character's position (x, y), size (w, h), and movement speed. Updated every frame based on input.
let player = { x: 100, y: 200, w: 30, h: 30, speed: 3.2 };
playerStartX, playerStartY
number
Global variables storing the player's starting position. Used to reset the player at the beginning of each loop.
let playerStartX = margin; let playerStartY = midY;
ghosts
array
Array of ghost objects. Each ghost has a recorded path (array of positions) and a unique color. Ghosts replay every frame.
let ghosts = []; // Later: ghosts.push({ path: [...], color: {r, g, b} });
currentPath
array
Array of positions recorded during the current loop. When time runs out, this becomes a new ghost.
let currentPath = []; // Later: currentPath[0] = {x, y};
loopDuration
number
The number of seconds per loop (10). Controls how long the player has before resetting.
let loopDuration = 10;
loopStartTime
number
Millisecond timestamp when the current loop began. Used to calculate the countdown timer.
let loopStartTime = millis();
loopFrame
number
Frame index within the current loop (0 to ~600 at 60fps). Used to index into ghost paths.
let loopFrame = 0;
currentLoopNumber
number
Counter tracking which loop the player is on. Displayed in the HUD.
let currentLoopNumber = 1;
timeLeft
number
Remaining seconds in the current loop. Calculated real-time from loopStartTime.
let timeLeft = loopDuration;
gameState
string
Current game state: 'PLAYING', 'WIN', or 'LOSE'. Controls which update and overlay functions run.
let gameState = 'PLAYING';
plates
array
Array of pressure plate objects. Each plate has position (x, y) and size (w, h). Player and ghosts pressing plates open doors.
let plates = []; // Later: plates.push({ x: ..., y: ..., w: 70, h: 25 });
doors
array
Array of door objects. Each door has position, size, and a plateIndex linking it to a plate. Closed doors block movement.
let doors = []; // Later: doors.push({ x: ..., y: ..., w: 30, h: doorHeight, plateIndex: 0 });
exitZone
object
The goal area at the far right. Reaching it transitions gameState to WIN.
let exitZone = { x: ..., y: ..., w: 80, h: 80 };
lasers
array
Array of lethal laser objects. Touching any laser transitions gameState to LOSE.
let lasers = []; // Later: lasers.push({ x: ..., y: ..., w: 10, h: ... });
evilGhost
object
The sinister enemy ghost that chases the player at a fixed speed. Collision ends the game.
let evilGhost = { x: width * 0.8, y: height * 0.25, size: 28, speed: 1.6 };