setup()
setup() runs exactly once when the sketch starts. It is the perfect place to initialize your canvas, set up fonts and colors, and create any starting values your game needs.
function setup() {
// Create a canvas with the same dimensions as your Pygame screen
createCanvas(900, 600);
// Set the font, size, and alignment for the UI text
textFont("Arial"); // Using Arial, a common system font, similar to Pygame's default
textSize(20);
textAlign(LEFT, TOP);
// Initialize gustX to be off-screen to the right
gustX = width;
}
Line-by-line explanation (5 lines)
createCanvas(900, 600);- Creates the game window that is 900 pixels wide and 600 pixels tall—all drawing happens on this canvas
textFont("Arial");- Sets the font for all text drawn later (money, rebirths, instructions) to Arial, a clean readable typeface
textSize(20);- Sets the size of all text to 20 pixels tall so it's readable on the dark background
textAlign(LEFT, TOP);- Anchors text to its top-left corner, making it easier to position text starting at specific coordinates
gustX = width;- Initializes gustX (the gust's horizontal position) to the right edge of the canvas, ready to sweep left when triggered