-- Forge milestone 3, genre one: the adventure in a painted room. Walk areas baked to a -- navigation mesh, hotspots, verbs and the sentence line, the parser, an inventory, a dialogue -- whose choice changes the world, a cut-scene into a second room, and a save and load. Driven the -- way a player drives it: a verb, a click on a hotspot, a typed line, a numbered choice. dofile("Forge/AuthorCompile.singe") local font = fontLoad("Singe/FreeSansBold.ttf", 16) fontSelect(font) fontQuality(FONT_QUALITY_BLENDED) dofile(authorBuild("testScripts/author/adventure2d.game", singeGetDataPath() .. "adventure2d.singe")) local gameUpdate = onOverlayUpdate local frames = 0 local stage = 0 local shots = 0 local said = {} local GIVE_UP = 90 local realSay = authorSay function authorSay(text, seconds) said[#said + 1] = tostring(text) return realSay(text, seconds) end local function clickOn(verb, id) local target = authorEntity(id) local bx, by, bw, bh = authorBounds(target) authorSetVerb(verb) authorSetPointer(1, bx + bw / 2, by + bh / 2, true) authorSwitchDown(SWITCH_BUTTON3) authorSwitchUp(SWITCH_BUTTON3) end local function lastSaid() return said[#said] or "(nothing)" end -- Each stage waits for the game to settle -- no sequence running, no line up, nobody walking -- -- or for a dialogue to offer its choices, before the next. local function idle() local hero = authorEntity("hero") if authorChoices() ~= nil then return true end return (not authorBusy()) and ((hero == nil) or not hero.walking) end local steps = { function() debugPrint("ADV the hall has a navigation mesh: " .. tostring(authorRoomNav() ~= nil) .. "; verb is " .. tostring(AUTHOR_VARS.verb)) clickOn("look", "door") end, function() debugPrint("ADV look at the door said: " .. lastSaid()) clickOn("take", "key") end, function() debugPrint("ADV took the key: has it " .. tostring(authorHas("key")) .. ", key gone " .. tostring(authorEntity("key") == nil) .. ", hero at " .. math.floor(authorX(authorEntity("hero"))) .. "," .. math.floor(authorY(authorEntity("hero")))) clickOn("open", "door") end, function() debugPrint("ADV the guard objects: " .. lastSaid()) clickOn("talk", "guard") end, function() -- The dialogue is up: the first choice, then the one the key allows. debugPrint("ADV the guard says: " .. lastSaid()) authorKeyDown(0, SCANCODE.MAIN_1.value) end, function() debugPrint("ADV and then: " .. lastSaid()) authorKeyDown(0, SCANCODE.MAIN_1.value) end, function() debugPrint("ADV allowed now: " .. tostring(AUTHOR_VARS.allowed) .. "; last line: " .. lastSaid()) authorSaid("look at the door") end, function() debugPrint("ADV typed 'look at the door': " .. lastSaid()) authorSaid("frobnicate the key") end, function() debugPrint("ADV typed nonsense: " .. lastSaid()) clickOn("open", "door") end, function() debugPrint("ADV after the door: room " .. AUTHOR_ROOM.name .. ", score " .. AUTHOR_VARS.score .. ", outside " .. tostring(AUTHOR_VARS.outside)) authorSaveGame(1) authorRestart() debugPrint("ADV restarted: room " .. AUTHOR_ROOM.name .. ", score " .. AUTHOR_VARS.score) authorLoadGame(1) debugPrint("ADV loaded: room " .. AUTHOR_ROOM.name .. ", score " .. AUTHOR_VARS.score .. ", has key " .. tostring(authorHas("key"))) end, function() if AUTHOR_ROOM.name == "yard" and AUTHOR_VARS.score == 3 and authorHas("key") then debugPrint("ADV RESULT done") else debugPrint("ADV FAIL room " .. AUTHOR_ROOM.name .. " score " .. AUTHOR_VARS.score) end singeQuit() end } local waited = 0 function onOverlayUpdate() local t = authorTime() frames = frames + 1 -- Move on when the game is idle for a moment, or after a while regardless. if idle() then waited = waited + 1 else waited = 0 end if (stage < #steps) and ((waited > 12) or (frames == 20)) then stage = stage + 1 waited = 0 steps[stage]() end local r = gameUpdate() colorForeground(255, 255, 255, 255) fontPrint(300, 450, string.format("adventure, stage %d, %.1fs", stage, t)) if (shots == 0 and stage == 2) or (shots == 1 and stage == 5) or (shots == 2 and stage == 10) then shots = shots + 1 singeScreenshot() end if t > GIVE_UP then debugPrint("ADV FAIL gave up at stage " .. stage) singeQuit() end return r end