setup()
setup() runs once at the start and initializes all variables and object properties. The catcher object stores x, y, width, and height so we can check collisions with falling droplets using AABB bounding-box math. figureGroundY is a global constant that ensures all figures and ground vehicles share the same standing level, creating visual coherence.
function setup() {
createCanvas(windowWidth, windowHeight);
textSize(32);
textAlign(CENTER, CENTER);
rectMode(CENTER);
ellipseMode(CENTER);
catcher = {
x: width / 2,
y: height - catcherHeight / 2 - 20,
width: catcherWidth,
height: catcherHeight
};
figureGroundY = height - 50;
policeCarY = figureGroundY - policeCarHeight / 2 - 10;
fireTruckY = figureGroundY - fireTruckHeight / 2 - 10;
towTruckY = figureGroundY - towTruckHeight / 2 - 10;
}
Line-by-line explanation (8 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates a canvas that fills the entire window, setting the stage for all drawings
catcher = { x: width / 2, y: height - catcherHeight / 2 - 20, width: catcherWidth, height: catcherHeight };
Creates the basket object at the bottom-center of the canvas with width and height properties for collision detection
figureGroundY = height - 50;
Establishes a consistent Y position where all walking figures and ground vehicles stand
createCanvas(windowWidth, windowHeight);- Creates a full-window canvas that will hold all game drawings
textSize(32);- Sets the default text size for emoji drawing (32 pixels)
textAlign(CENTER, CENTER);- Aligns all text (including emojis) to their center point rather than top-left, making positioning easier
rectMode(CENTER);- Positions all rectangles from their center, not their corner—essential for vehicles and figures
ellipseMode(CENTER);- Positions all circles and ellipses from their center—consistent with rect mode
catcher = { x: width / 2, y: height - catcherHeight / 2 - 20, width: catcherWidth, height: catcherHeight };- Creates the catcher object with x, y, width, and height properties; positioned at bottom-center with padding
figureGroundY = height - 50;- Defines a single Y position 50 pixels from the bottom where all figures and ground vehicles stand
policeCarY = figureGroundY - policeCarHeight / 2 - 10;- Positions police cars slightly above the ground level for visual alignment