64 lines
2.1 KiB
Text
64 lines
2.1 KiB
Text
-- Forge milestone 2, genre two: the 3D platformer. A character on the controller moving
|
|
-- relative to a following camera, a jump onto a ledge, and a prize that is a trigger. Driven by
|
|
-- what the hero is doing, as scene52 drives the 2D one.
|
|
dofile("Forge/AuthorCompile.singe")
|
|
|
|
local font = fontLoad("Singe/FreeSansBold.ttf", 18)
|
|
|
|
fontSelect(font)
|
|
fontQuality(FONT_QUALITY_BLENDED)
|
|
|
|
dofile(authorBuild("testScripts/author/platformer3d.game", singeGetDataPath() .. "platformer3d.singe"))
|
|
|
|
local gameUpdate = onOverlayUpdate
|
|
local frames = 0
|
|
local shots = 0
|
|
local jumped = false
|
|
local won = 0
|
|
local GIVE_UP = 25
|
|
|
|
|
|
function onOverlayUpdate()
|
|
local t = authorTime()
|
|
local hero = authorEntity("hero")
|
|
local hx, hy, hz = authorPosition(hero)
|
|
|
|
frames = frames + 1
|
|
if frames == 2 then
|
|
authorKeyDown(0, SCANCODE.RIGHT.value)
|
|
end
|
|
-- Jump once the ledge is near and there is ground underfoot.
|
|
if (not jumped) and (hx > 3.2) and authorOnGround(hero) then
|
|
authorKeyDown(0, SCANCODE.SPACE.value)
|
|
jumped = true
|
|
elseif jumped then
|
|
authorKeyUp(0, SCANCODE.SPACE.value)
|
|
end
|
|
-- Past the prize, turn back so the ledge is not overshot for good.
|
|
if hx > 7.5 then
|
|
authorKeyUp(0, SCANCODE.RIGHT.value)
|
|
authorKeyDown(0, SCANCODE.LEFT.value)
|
|
elseif hx < 5 and jumped and AUTHOR_VARS.won == nil then
|
|
authorKeyUp(0, SCANCODE.LEFT.value)
|
|
authorKeyDown(0, SCANCODE.RIGHT.value)
|
|
end
|
|
|
|
local r = gameUpdate()
|
|
|
|
colorForeground(255, 255, 255, 255)
|
|
fontPrint(12, 450, string.format("authored 3D platformer, %.1fs, hero %.1f %.1f %.1f, state %s, score %d", t, hx, hy, hz, hero.vars.state, AUTHOR_VARS.score))
|
|
if (shots == 0 and t > 0.5) or (shots == 1 and jumped and not authorOnGround(hero)) or (shots == 2 and won > 0) then
|
|
shots = shots + 1
|
|
singeScreenshot()
|
|
end
|
|
if AUTHOR_VARS.won and won == 0 then
|
|
won = t
|
|
end
|
|
if (won > 0 and t > won + 0.5) or (t > GIVE_UP) then
|
|
debugPrint(string.format("PLATFORM3D RESULT score=%d won=%s hero=%.1f,%.1f after=%.1fs", AUTHOR_VARS.score, tostring(AUTHOR_VARS.won), hx, hy, t))
|
|
if not AUTHOR_VARS.won then debugPrint("PLATFORM3D FAIL the prize was never taken") end
|
|
singeQuit()
|
|
end
|
|
|
|
return r
|
|
end
|