COLS
number
Width of the game grid in tiles (20)
const COLS = 20;
ROWS
number
Height of the game grid in tiles (14)
const ROWS = 14;
TILE_EMPTY
string
Character representing an empty tile (space)
const TILE_EMPTY = ' ';
TILE_BLOCK
string
Character representing a solid block/brick (#)
const TILE_BLOCK = '#';
TILE_LADDER
string
Character representing a climbable ladder (H)
const TILE_LADDER = 'H';
TILE_GOLD
string
Character representing a gold coin (.)
const TILE_GOLD = '.';
TILE_HOLE
string
Character representing a dug hole (O)
const TILE_HOLE = 'O';
MOVE_SPEED
number
Player movement animation speed (0.15 per frame)
const MOVE_SPEED = 0.15;
ENEMY_SPEED
number
Enemy movement animation speed (0.08 per frame, slower than player)
const ENEMY_SPEED = 0.08;
ENEMY_PAUSE
number
Frames enemies pause between moves (8 frames)
const ENEMY_PAUSE = 8;
HOLE_DURATION
number
Frames a dug hole stays open before closing (240 frames = 4 seconds)
const HOLE_DURATION = 240;
START_LIVES
number
Number of lives the player starts with (3)
const START_LIVES = 3;
SCORE_PER_GOLD
number
Points awarded for collecting one gold coin (100)
const SCORE_PER_GOLD = 100;
LEVEL_CLEAR_BONUS
number
Points awarded for completing a level (500)
const LEVEL_CLEAR_BONUS = 500;
TIME_BONUS_PER_SECOND
number
Points per second remaining for time bonus (5)
const TIME_BONUS_PER_SECOND = 5;
levelTemplate
array
2D level layout as array of strings, editable in the level editor
const levelTemplate = ["####################", ...]
level
array
Current level as 2D array of tile characters
let level = [];
player
object
The player entity with position, movement, and animation properties
let player = null;
enemies
array
Array of all enemy entities in the current level
let enemies = [];
holes
array
Array of all active holes with their timers
let holes = [];
goldTotal
number
Total number of gold coins in the current level
let goldTotal = 0;
goldCollected
number
Number of gold coins the player has collected so far
let goldCollected = 0;
tileSize
number
Pixel size of each grid tile (calculated based on screen size)
let tileSize;
offsetX
number
Horizontal pixel offset to center the game grid on screen
let offsetX;
offsetY
number
Vertical pixel offset to center the game grid on screen
let offsetY;
gameState
string
Current game state: 'playing', 'won', or 'gameover'
let gameState = 'playing';
lives
number
Number of lives the player currently has remaining
let lives = START_LIVES;
score
number
Player's current score
let score = 0;
levelStartFrame
number
Frame number when the current level started (for timer)
let levelStartFrame = 0;
lastLevelTimeSec
number
Elapsed seconds when the level ended (for display)
let lastLevelTimeSec = 0;
controls
object
Current input state with left, right, up, down boolean properties
let controls = { left: false, right: false, up: false, down: false };
buttons
array
Array of all on-screen UIButton objects
let buttons = [];
audioCtx
object
Web Audio API AudioContext for sound synthesis
let audioCtx = null;
masterGain
object
Web Audio API GainNode controlling overall volume
let masterGain = null;
editorVisible
boolean
Whether the level editor overlay is currently visible
let editorVisible = false;