0,]']±>Sï}WÿÍu§ðp8·d%qy)6o;]ÉA¦ösï÷ôôô”°ÂVl†3 224 then knight.x = 224 end if knight.y > 120 then knight.y = 120 end for i, dragon in ipairs(dragons) do dragon.x = dragon.x + dragon.speedX dragon.y = dragon.y + dragon.speedY if dragon.x <= 0 or dragon.x >= 224 then dragon.speedX = -dragon.speedX end if dragon.y <= 0 or dragon.y >= 120 then dragon.speedY = -dragon.speedY end if checkCollision(knight, dragon) then game.lost = true game.musicPlayed = false end end if checkCollision(knight, princess) then if game.level < 3 then game.level = game.level + 1 loadLevel(game.level) else game.gameComplete = true game.musicPlayed = false end end end game.timer = game.timer + 1 end function draw() spr(princess.sprite, princess.x, princess.y, 0, 1, 0, 0, 2, 2) for i, dragon in ipairs(dragons) do spr(4, dragon.x, dragon.y, 0, 1, 0, 0, 2, 2) end spr(knight.sprite, knight.x, knight.y, 0, 1, 0, 0, 2, 2) if game.gameComplete then if not game.musicPlayed then music(1, false, false) game.musicPlayed = true end local bounce = 0 if (game.timer % 20) < 10 then bounce = -3 end local color = 11 if (game.timer % 10) < 5 then color = 15 end print("YOU WIN!", 80, 40 + bounce, color) print("Congratulations!", 60, 65, 10) print("* * * * * * * *", 55, 80, 11) print("Press X to play again", 45, 95, 6) if btnp(5) then resetGame() end elseif game.lost then if not game.musicPlayed then music(0, false, false) game.musicPlayed = true end print("CAUGHT BY DRAGON!", 50, 50, 8) print("Press X to retry", 60, 70, 10) if btnp(5) then resetGame() end else print("LEVEL: " .. game.level .. "/3", 5, 5, 11) print("Use ARROW KEYS to move", 70, 5, 10) print("Avoid the dragons!", 80, 18, 8) print("Save the princess!", 80, 31, 10) end end function loadLevel(lvl) local level = levels[lvl] dragons = {} for i, d in ipairs(level.dragons) do table.insert(dragons, { x = d.x, y = d.y, speedX = d.speedX, speedY = d.speedY, sprite = 4, size = 16 }) end princess.x = level.princessX princess.y = level.princessY knight.x = 20 knight.y = 100 game.won = false game.lost = false game.musicPlayed = false end function checkCollision(a, b) local size = 16 return a.x < b.x + size and a.x + size > b.x and a.y < b.y + size and a.y + size > b.y end function resetGame() game.level = 1 knight.x = 20 knight.y = 100 princess.x = 200 princess.y = 100 loadLevel(1) game.won = false game.lost = false game.gameComplete = false game.musicPlayed = false music(-1, false, false) end loadLevel(1)