setup()
setup() runs exactly once when the sketch loads. Use it to initialize your game world—canvas size, starting variables, and object pools like shops. This is where you prepare everything the game needs before the draw loop begins.
function setup() {
createCanvas(800, 600); // Standard p5 canvas size
noSmooth(); // Keep pixel art sharp if using images
// Initialize shop items (consumables/temporary buffs)
shopItems.push(new ShopItem("Small Potion", "Restores 20 HP to player.", 10, "heal", 20));
shopItems.push(new ShopItem("Attack Elixir", "Boosts player attack by 5 for battle.", 15, "attack_boost", 5));
shopItems.push(new ShopItem("Large Potion", "Restores 50 HP to player.", 25, "heal", 50));
shopItems.push(new ShopItem("Defense Brew", "Boosts player defense by 3 for battle.", 20, "defense_boost", 3));
// Initialize ability shop items (permanent abilities)
// Each ability is specific to a species and replaces the character's current ability
abilityShopItems.push(new AbilityShopItem("Inferno Roar", "Dragon's Flame: Stronger Fire Breath.", 50, "Inferno Roar", "Dragon"));
abilityShopItems.push(new AbilityShopItem("Divine Shield", "Unicorn's Blessing: Heals & temp DEF boost.", 60, "Divine Shield", "Unicorn"));
abilityShopItems.push(new AbilityShopItem("Sky Razor", "Griffin's Fury: More defense ignored, higher crit chance.", 70, "Sky Razor", "Griffin"));
abilityShopItems.push(new AbilityShopItem("Solar Flare", "Phoenix's Fire: AoE damage & minor heal.", 80, "Solar Flare", "Phoenix"));
}
Line-by-line explanation (4 lines)
🔧 Subcomponents:
createCanvas(800, 600);
Creates an 800x600 pixel canvas where all game drawing happens
shopItems.push(new ShopItem("Small Potion", "Restores 20 HP to player.", 10, "heal", 20));
Populates the consumable shop with four buyable items: healing potions and stat-boost elixirs
abilityShopItems.push(new AbilityShopItem("Inferno Roar", "Dragon's Flame: Stronger Fire Breath.", 50, "Inferno Roar", "Dragon"));
Adds four permanent ability upgrades to the shop, one for each character species
createCanvas(800, 600);- Creates the game window—all p5.js drawing happens on this 800×600 pixel canvas
noSmooth();- Disables anti-aliasing so pixel art and shapes appear sharp and crisp instead of blurry
shopItems.push(new ShopItem("Small Potion", "Restores 20 HP to player.", 10, "heal", 20));- Creates a new consumable item and adds it to the shop array—players can buy potions to restore health during battle
abilityShopItems.push(new AbilityShopItem("Inferno Roar", "Dragon's Flame: Stronger Fire Breath.", 50, "Inferno Roar", "Dragon"));- Creates a permanent ability upgrade specific to the Dragon species and adds it to the ability shop—once bought, it replaces the character's current ability permanently