Write JavaScript in the editor to control the hero in a dynamic world. Define an update()
function that runs every 100ms when you click "Run Code." Use "Stop" to pause.
console.log("move 5");
– Sets x-velocity (no cooldown).console.log("jump 0.05");
– Jumping force (0.5s cooldown).console.log("attack sword");
– Sword attack (1s cooldown).console.log("attack bow");
– Fires arrow (2s cooldown).console.log("attack bomb");
– Throws bomb (3s cooldown).console.log("heal 20");
– Heals hero (5s cooldown, requires potion).Create continuous logic:
function update() { if (hero.position.x < portal.position.x) console.log("move 5"); if (enemies.length > 0 && hero.inventory.potions > 0 && hero.health < 50) console.log("heal 20"); }
Key variables:
hero
– Hero body (.health
, .inventory
, .abilities
).enemies
– Array of enemies (incl. boss).items
– Array of collectibles.portal
– Exit portal body.obstacles
– Array of hazards.engine
, world
– Matter.js instances.Health: 100 | Score: 0 | Potions: 0
Cooldowns: Jump: Ready | Sword: Ready | Bow: Ready | Bomb: Ready | Heal: Ready