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

73 lines
3 KiB
Text

-- Facing and turning sprites in a Forge game: a sheet drawn facing right only is mirrored by
-- the engine while its instance faces left (the runner beside it has frames drawn both ways and
-- is not), a sheet entity with an rz draws its frame turned, and clips play at a volume of their
-- own under the game's.
dofile("Forge/AuthorCompile.singe")
local font = fontLoad("Singe/FreeSansBold.ttf", 18)
fontSelect(font)
fontQuality(FONT_QUALITY_BLENDED)
dofile(authorBuild("testScripts/author/tail.game", singeGetDataPath() .. "facing.singe"))
local gameUpdate = onOverlayUpdate
local frames = 0
local shots = 0
function onOverlayUpdate()
local runner = authorEntity("runner")
local mirror = authorEntity("mirror")
local tilted = authorEntity("tilted")
frames = frames + 1
if frames == 2 then
authorKeyDown(0, SCANCODE.RIGHT.value)
elseif frames == 30 then
authorKeyUp(0, SCANCODE.RIGHT.value)
authorKeyDown(0, SCANCODE.LEFT.value)
elseif frames == 40 then
-- The playSound action with a volume, and the sound behaviour's, both under the master.
authorMidi(0x90, 60, 100)
authorBehaviourEvent(mirror, "hit")
local channel = soundPlay(soundLoad("testScripts/crackle.wav"), 0, 20)
soundSetChannelVolume(channel, 50)
soundSetVolume(40)
debugPrint("FACING a clip on channel " .. channel .. " at its own volume under a master of " .. soundGetVolume())
end
local r = gameUpdate()
colorForeground(255, 255, 255, 255)
fontPrint(12, 450, string.format("facing: runner %s, mirror %s%s, tilted %d degrees", tostring(runner.vars.facing), tostring(mirror.vars.facing), authorMirrored(mirror) and " (mirrored)" or "", tilted.vars.angle or 0))
if (shots == 0 and frames == 20) or (shots == 1 and frames == 55) then
shots = shots + 1
singeScreenshot()
end
if frames == 20 then
debugPrint(string.format("FACING going right: runner mirrored %s, mirror mirrored %s", tostring(authorMirrored(runner)), tostring(authorMirrored(mirror))))
if authorMirrored(runner) or authorMirrored(mirror) then
debugPrint("FACING FAIL nothing should be mirrored while facing right")
end
debugPrint(string.format("FACING the tilted sheet has an image of its own: %s, turned %d", tostring(tilted.ownSprite ~= nil), tilted.ownAngle or -1))
if (tilted.ownSprite == nil) or (tilted.ownAngle ~= 30) then
debugPrint("FACING FAIL the sheet entity with rz 30 should draw a turned frame")
end
elseif frames == 55 then
debugPrint(string.format("FACING going left: runner mirrored %s (drawn %s), mirror mirrored %s", tostring(authorMirrored(runner)), tostring(runner.drawnFacing), tostring(authorMirrored(mirror))))
if authorMirrored(runner) or not authorMirrored(mirror) then
debugPrint("FACING FAIL the sheet without left frames should be mirrored, the one with them not")
end
if mirror.ownSprite == nil then
debugPrint("FACING FAIL the mirrored instance should draw from an image of its own")
end
debugPrint("FACING RESULT done")
end
if frames > 70 then
singeQuit()
end
return r
end