-- Forge tutorial 1, "Ten minutes": the chooser, a new game, the four panels, one typed change, -- save, and play. The pictures in docs/Forge.adoc come from here, and the description the keys -- make is checked against the one the book ships (Forge/tutorials/01-tenMinutes.game). TUTORIAL = { number = 1, name = "01-tenMinutes", tag = "TUTORIAL1" } dofile("testScripts/tutorialDrive.singe") local frames = 0 local stage = 0 local built = nil local game = nil local function step() if stage == 1 then -- The chooser, as Forge opens. FORGE.chooser.manual = forgeChooserManual() forgeChooserScan() tutorialShot("chooser") elseif stage == 2 then -- New game is the last entry; ENTER opens it. FORGE.chooser.at = #FORGE.chooser.files forgeChooserKey(SCANCODE.RETURN.value) if FORGE.game == nil then debugPrint(TUTORIAL.tag .. " FAIL New game did not open") end -- The scene keeps its own copy under the tutorial's name, so the check at the end can find it. forgeSave() authorCopy(FORGE.path, TUTORIAL_OUT .. TUTORIAL.name .. ".game") forgeClose() tutorialBegin(nil) tutorialShot("entities") elseif stage == 3 then panel("types") tutorialShot("types") elseif stage == 4 then panel("rules") tutorialShot("rules") elseif stage == 5 then -- Back to the entities, the hero selected by a press on it, and its x typed. panel("entities") selectEntity("hero") form("x", 200) tutorialShot("moved") if forgeRoom().entities[FORGE.selected].x ~= 200 then debugPrint(TUTORIAL.tag .. " FAIL the hero's x did not take") end elseif stage == 6 then -- The hero's colour and speed, in the types panel. panel("types") FORGE.typeName = "hero" forgeRefresh() form("look.r", 90) form("look.b", 240) form("platformer.speed", 260) tutorialShot("recoloured") elseif stage == 7 then key(SCANCODE.S) tutorialShot("saved") built = tutorialEnd() -- The built game installs its own callbacks; the scene keeps its frame loop and calls -- the game's from it. local mine = onOverlayUpdate dofile(built) game = onOverlayUpdate onOverlayUpdate = mine authorKeyDown(0, SCANCODE.RIGHT.value) elseif stage == 9 then tutorialShot("playing") elseif stage == 10 then debugPrint(TUTORIAL.tag .. " RESULT done") singeQuit() end end function onOverlayUpdate() frames = frames + 1 if frames % 12 == 0 and stage < 10 then stage = stage + 1 step() end if game ~= nil then return game() end if FORGE.game == nil then forgeChooserDraw() else forgeDraw(nil, nil) end return OVERLAY_UPDATED end