setup()
setup() runs once when the sketch starts. Here we prepare the canvas, initialize all game variables, and generate the first level. This is where you define the visual style (pixelated), prepare the character system, and launch into the start screen.
function setup() {
createCanvas(windowWidth, windowHeight);
pixelDensity(1);
noSmooth();
textFont('monospace');
textAlign(CENTER, CENTER);
createLevel(currentLevel);
generateBackgroundTiles();
initCharacterRoster();
resetGame();
}
Line-by-line explanation (9 lines)
🔧 Subcomponents:
createCanvas(windowWidth, windowHeight);
Creates the game canvas that fills the entire window
pixelDensity(1);
noSmooth();
Makes sure retro pixel art doesn't blur on high-DPI screens
initCharacterRoster();
Creates all 10 unique character skins with randomized abilities and costs
createCanvas(windowWidth, windowHeight);- Creates a canvas sized to fit the entire window, making the game responsive
pixelDensity(1);- Ensures pixel art stays sharp by disabling high-DPI scaling
noSmooth();- Prevents p5 from smoothing (anti-aliasing) pixel edges—keeping the blocky retro style
textFont('monospace');- Sets all text to monospace so the HUD looks pixelated and consistent
textAlign(CENTER, CENTER);- Centers text at the point you draw it—makes positioning easier
createLevel(currentLevel);- Generates all platforms, hazards, coins, and the goal for the current level
generateBackgroundTiles();- Creates a parallax background of random decorative tiles that move at half camera speed
initCharacterRoster();- Creates 10 characters by pairing each skin template with a shuffled ability, setting ownership and prices
resetGame();- Places the player at the starting position with zero velocity and resets jump counts