singe/testScripts/scene76.singe
2026-09-14 14:20:17 -05:00

49 lines
1.6 KiB
Text

-- A space shooter (FORGE.md's catalogue): a ship under thrust with no gravity, bolts fired
-- forward, rocks coming at it broken by collision rules, and a camera behind.
dofile("Forge/AuthorCompile.singe")
local font = fontLoad("Singe/FreeSansBold.ttf", 18)
fontSelect(font)
fontQuality(FONT_QUALITY_BLENDED)
dofile(authorBuild("testScripts/author/space.game", singeGetDataPath() .. "space.singe"))
local gameUpdate = onOverlayUpdate
local frames = 0
local shots = 0
local startZ = nil
local maxBolts = 0
local GIVE_UP = 40
function onOverlayUpdate()
local t = authorTime()
local ship = authorEntity("ship")
local sx, sy, sz = authorPosition(ship)
frames = frames + 1
startZ = startZ or sz
if frames == 3 then
authorKeyDown(0, SCANCODE.UP.value)
authorKeyDown(0, SCANCODE.SPACE.value)
end
maxBolts = math.max(maxBolts, authorCount("bolt"))
local r = gameUpdate()
colorForeground(255, 255, 255, 255)
fontPrint(12, 450, string.format("authored space, %.1fs, ship z %.1f, bolts %d, rocks %d, broken %d", t, sz, authorCount("bolt"), authorCount("rock"), AUTHOR_VARS.rocks))
if (shots == 0 and t > 2) or (shots == 1 and AUTHOR_VARS.rocks > 0) then
shots = shots + 1
singeScreenshot()
end
if (AUTHOR_VARS.rocks >= 3) or (t > GIVE_UP) then
debugPrint(string.format("SPACE RESULT broken=%d movedForward=%.1f maxBolts=%d after=%.1fs", AUTHOR_VARS.rocks, startZ - sz, maxBolts, t))
if AUTHOR_VARS.rocks < 1 then debugPrint("SPACE FAIL no rock was broken") end
if startZ - sz < 3 then debugPrint("SPACE FAIL the thrust did not move the ship") end
singeQuit()
end
return r
end