setup()
setup() runs exactly once when the sketch loads. Use it to initialize the canvas, create objects, and set up the world state.
function setup() {
createCanvas(windowWidth, windowHeight);
textFont('monospace');
player = new Player(120, height / 2);
createZones();
lastOGSpawn = millis();
}
Line-by-line explanation (5 lines)
createCanvas(windowWidth, windowHeight);- Creates a full-screen canvas that fills the entire browser window—windowWidth and windowHeight are p5.js variables that auto-update on window resize.
textFont('monospace');- Sets all future text to monospace font, giving the game a retro coding aesthetic that matches the HUD display.
player = new Player(120, height / 2);- Creates the player character object positioned at x=120 (in the left zone) and vertically centered; stores it in the global player variable so other functions can access it.
createZones();- Calls the function that divides the canvas into nine colored rarity zones, setting up spawn points and requirements for each creature type.
lastOGSpawn = millis();- Records the current time in milliseconds so the code can track when OG creatures were last spawned and enforce their rare 10-minute spawn interval.