touchControls
object
Tracks whether the on-screen left, right, and jump touch buttons are currently pressed, shared between input handling and rendering.
let touchControls = { left: false, right: false, jump: false };
isTouchDevice
boolean
Detected once in setup() to decide whether to render on-screen touch buttons.
let isTouchDevice = false;
TILE_SIZE
number
The pixel width/height of every square tile in the world grid.
const TILE_SIZE = 32;
WORLD_WIDTH
number
How many tile columns wide the entire generated world is.
const WORLD_WIDTH = 200;
WORLD_HEIGHT
number
How many tile rows tall the world is, from sky to bedrock.
const WORLD_HEIGHT = 60;
UI_BAR_H
number
The height in pixels of the bottom UI bar that holds the hotbar and touch controls.
const UI_BAR_H = 60;
Block ID constants (AIR, GRASS, DIRT, STONE, WOOD, LEAVES)
number
Named numeric IDs used throughout world, inventory, and drawing code instead of magic numbers, making the code far more readable.
const AIR = 0; const GRASS = 1; // ...etc
world
array
The main 2D array (world[x][y]) storing which block ID occupies every tile position in the game.
let world;
player
object
Stores the player's position, size, velocity, and ground-contact state used by physics and rendering.
let player = { x: 0, y: 0, w: 22, h: 32, vx: 0, vy: 0, onGround: false };
cameraX
number
The horizontal pixel offset used to convert world coordinates to screen coordinates for scrolling.
let cameraX = 0;
cameraY
number
The vertical pixel offset used to convert world coordinates to screen coordinates for scrolling.
let cameraY = 0;
inventory
array
The five block types available in the hotbar, in slot order.
let inventory = [DIRT, STONE, WOOD, LEAVES, GRASS];
selectedIndex
number
Which hotbar slot (0-4) is currently active and will be placed when the player taps an empty tile.
let selectedIndex = 0;
GRAVITY
number
Constant downward acceleration applied to the player's vertical velocity every frame.
const GRAVITY = 0.8;
MOVE_SPEED
number
Constant horizontal speed the player moves at while a direction is held.
const MOVE_SPEED = 3;
JUMP_SPEED
number
The upward velocity applied the instant the player jumps.
const JUMP_SPEED = 12;
audioInitialized
boolean
Tracks whether the browser's AudioContext has been unlocked by a user gesture yet, gating all sound playback.
let audioInitialized = false;