-- Forge tutorial 3, "Sprites and sound": the hero from the kit's sheet, mirrored as it turns, -- coins that spin, a jump with a sound on the press, and music. Continues from tutorial 2. TUTORIAL = { number = 3, name = "03-sprites", tag = "TUTORIAL3" } dofile("testScripts/tutorialDrive.singe") local frames = 0 local stage = 0 local game = nil tutorialBegin("02-platformer") local function lightType(name) local names = {} local from, to = 1, 1 for typeName in pairs(FORGE.game.types) do names[#names + 1] = typeName end table.sort(names) for at, typeName in ipairs(names) do if typeName == FORGE.typeName then from = at end if typeName == name then to = at end end for _ = 1, math.abs(to - from) do key((to > from) and SCANCODE.DOWN or SCANCODE.UP) end end -- Walks the rules with the arrows to a rule, and to one of its parts. local function ruleGo(index, part) local guard = 0 while ((FORGE.rule ~= index) or (FORGE.part ~= (part or 0))) and (guard < 60) do local past = (FORGE.rule > index) or ((FORGE.rule == index) and (FORGE.part > (part or 0))) key(past and SCANCODE.UP or SCANCODE.DOWN) guard = guard + 1 end end local function step() if stage == 1 then -- The hero from the sheet, with frames stepped by state. key(SCANCODE.MAIN_2) lightType("hero") form("look", "sprite") form("look.file", "hero.png") form("look.frames", 8) form("behaviours", "platformer, frames") form("frames.fps", 10) form("frames.states", "idle=1-1, walk=2-5, jump=6-6, fall=7-7") tutorialShot("heroType") elseif stage == 2 then lightType("coin") form("behaviours", "trigger, spin") form("spin.rate", 180) tutorialShot("coinSpin") elseif stage == 3 then -- The jump rule: a press rather than a hold, and a sound. key(SCANCODE.MAIN_3) ruleGo(3, 1) key(SCANCODE.DELETE) key(SCANCODE.C) pick("keyPressed") form("key", "SPACE") key(SCANCODE.T) pick("playSound") form("file", "jump.wav") tutorialShot("jumpRule") elseif stage == 4 then key(SCANCODE.N) form("note", "Music") key(SCANCODE.E) pick("roomStart") key(SCANCODE.T) pick("playMusic") form("file", "loop.ogg") tutorialShot("music") elseif stage == 5 then key(SCANCODE.S) local built = tutorialEnd() local mine = onOverlayUpdate dofile(built) game = onOverlayUpdate onOverlayUpdate = mine authorKeyDown(0, SCANCODE.RIGHT.value) elseif stage == 7 then authorKeyUp(0, SCANCODE.RIGHT.value) authorKeyDown(0, SCANCODE.LEFT.value) elseif stage == 8 then tutorialShot("playing") local hero = authorEntity("hero") debugPrint(string.format("%s the hero faces %s in state %s on frame %s, mirrored %s", TUTORIAL.tag, tostring(hero.vars.facing), tostring(hero.vars.state), tostring(hero.vars.frame), tostring(authorMirrored(hero)))) if (hero.vars.facing ~= "left") or not authorMirrored(hero) then debugPrint(TUTORIAL.tag .. " FAIL the hero should face left, mirrored") end elseif stage == 9 then debugPrint(TUTORIAL.tag .. " RESULT done") singeQuit() end end function onOverlayUpdate() frames = frames + 1 if frames % 12 == 0 and stage < 9 then stage = stage + 1 step() end if game ~= nil then return game() end forgeDraw(nil, nil) return OVERLAY_UPDATED end