-- Forge milestone 4, genre one: racing. The car is driven by held keys, the rival drives the -- track of points on its own, a checkpoint is a trigger the car enters, and a lap is two of them. dofile("Forge/AuthorCompile.singe") local font = fontLoad("Singe/FreeSansBold.ttf", 18) fontSelect(font) fontQuality(FONT_QUALITY_BLENDED) dofile(authorBuild("testScripts/author/racing.game", singeGetDataPath() .. "racing.singe")) local gameUpdate = onOverlayUpdate local frames = 0 local shots = 0 local topSpeed = 0 local rivalStart = nil local GIVE_UP = 40 function onOverlayUpdate() local t = authorTime() local car = authorEntity("car") local rival = authorEntity("rival") local cx, cy, cz = authorPosition(car) local rx, ry, rz = authorPosition(rival) frames = frames + 1 rivalStart = rivalStart or rz if frames == 2 then authorKeyDown(0, SCANCODE.UP.value) end topSpeed = math.max(topSpeed, car.vars.speed or 0) local r = gameUpdate() colorForeground(255, 255, 255, 255) fontPrint(12, 450, string.format("authored racing, %.1fs, car z %.1f speed %.1f, rival z %.1f, gate %d, laps %d", t, cz, car.vars.speed or 0, rz, AUTHOR_VARS.next, AUTHOR_VARS.laps)) if (shots == 0 and t > 1) or (shots == 1 and AUTHOR_VARS.next == 2) or (shots == 2 and AUTHOR_VARS.laps > 0) then shots = shots + 1 singeScreenshot() end if (AUTHOR_VARS.laps > 0 and t > 1) or (t > GIVE_UP) then debugPrint(string.format("RACE RESULT laps=%d next=%d topSpeed=%.1f carZ=%.1f rivalMoved=%.1f after=%.1fs", AUTHOR_VARS.laps, AUTHOR_VARS.next, topSpeed, cz, rivalStart - rz, t)) if topSpeed < 3 then debugPrint("RACE FAIL the car never got going") end if AUTHOR_VARS.laps < 1 then debugPrint("RACE FAIL no lap was completed") end if rivalStart - rz < 5 then debugPrint("RACE FAIL the rival did not drive") end local hz = authorField(authorEntity("hover"), "z") debugPrint(string.format("RACE the hovercraft under thrust is at z %.1f (from 10); the hinged bar is at y %.1f", hz, authorField(authorEntity("bar"), "y"))) if hz > 8 then debugPrint("RACE FAIL the thrust did not move the hovercraft") end singeQuit() end return r end