71 lines
4 KiB
Text
71 lines
4 KiB
Text
-- Hypseus parity, stage 6: the sprite sheet rotation pair, the source rectangle blit, the frame
|
|
-- count getter, the two in-memory loaders, the overlay opacity, controllerHowMany and the music
|
|
-- family with its own gain, over an mp3 so the built-in decoder is exercised.
|
|
dofile("Singe/Framework.singe")
|
|
local font = fontLoad("Singe/FreeSansBold.ttf", 14)
|
|
local arrows = spriteLoadFrames(4, "testScripts/arrows.png")
|
|
local sheet = spriteLoad("testScripts/arrows.png") -- The same file as one wide still.
|
|
local bytes = io.open("testScripts/arrows.png", "rb"):read("a")
|
|
local copied = spriteLoadData(bytes) -- The same image, from a Lua string.
|
|
local wave = io.open("testScripts/tone.ogg", "rb"):read("a")
|
|
local effect = soundLoadData(wave) -- A sound from a Lua string.
|
|
local tune = musicLoad("testScripts/tune.mp3") -- 6 seconds of 330 Hz, mp3.
|
|
local frames = 0
|
|
local step = 0
|
|
local note = "start"
|
|
local said = ""
|
|
|
|
local steps = {
|
|
{ "spriteRotateFrame(arrows, 0, 1)", function() spriteRotateFrame(arrows, 0, 1) end },
|
|
{ "spriteRotateFrame(arrows, 45, 2)", function() spriteRotateFrame(arrows, 45, 2) end },
|
|
{ "spriteRotateFrame(arrows, 135, 3)", function() spriteRotateFrame(arrows, 135, 3) end },
|
|
{ "spriteScale(arrows, 2) then 225, 4", function() spriteScale(arrows, 2) spriteRotateFrame(arrows, 225, 4) end },
|
|
{ "out of range frame draws frame 1", function() spriteScale(arrows, 1) spriteRotateFrame(arrows, 90, 99) end },
|
|
{ "setOverlayOpacity(96)", function() setOverlayOpacity(96) end },
|
|
{ "setOverlayOpacity(255)", function() setOverlayOpacity(255) end },
|
|
{ "musicPlay(tune, -1) at volume 128", function() said = "musicSetVolume returned " .. musicSetVolume(128) musicPlay(tune, -1) end },
|
|
{ "musicSetVolume(16), sound unmoved", function() said = "musicSetVolume returned " .. musicSetVolume(16) end },
|
|
{ "soundSetVolume(8), music unmoved", function() soundSetVolume(8) soundPlay(effect) end },
|
|
{ "musicPause()", function() musicPause() end },
|
|
{ "musicResume()", function() musicResume() end },
|
|
{ "musicStop(tune, 250) with a fade", function() musicStop(tune, 250) end },
|
|
{ "musicPlay(tune) once through", function() musicPlay(tune) end },
|
|
{ "musicStop() and musicUnload(tune)", function() musicStop() musicUnload(tune) end },
|
|
}
|
|
|
|
fontSelect(font)
|
|
overlaySetResolution(640, 480) -- Room for the rotated frames at twice their size.
|
|
discPlay()
|
|
soundSetVolume(40)
|
|
spriteRotateFrame(arrows, 0, 1) -- There is a frame to draw before the first step runs.
|
|
|
|
function onOverlayUpdate()
|
|
frames = frames + 1
|
|
overlayClear()
|
|
overlayBox(1, 1, overlayGetWidth() - 2, overlayGetHeight() - 2)
|
|
-- The rotated frame, centred on its point, beside the same frame drawn flat by spriteDrawFrame.
|
|
spriteDrawRotatedFrame(arrows, 90, 200)
|
|
spriteDrawRotatedFrame(arrows, 240, 200, 1.5)
|
|
spriteDrawRotatedFrame(arrows, 400, 200, 2, 0.75)
|
|
spriteDrawFrame(arrows, 520, 176, 1)
|
|
-- spriteDrawGrid takes a rectangle out of the wide sheet: frames 3 and 2, and a quarter of one.
|
|
spriteDrawGrid(sheet, 40, 330, 96, 0, 48, 48)
|
|
spriteDrawGrid(sheet, 120, 330, 48, 0, 48, 48)
|
|
spriteDrawGrid(sheet, 200, 330, 12, 12, 24, 24)
|
|
-- The sprite built from bytes draws exactly as the one built from the file.
|
|
spriteDrawGrid(copied, 280, 330, 0, 0, 48, 48)
|
|
fontPrint(8, 6, string.format("frames sheet=%d still=%d data=%d controllers %d", spriteGetFrames(arrows), spriteGetFrames(sheet), spriteGetFrames(copied), controllerHowMany()))
|
|
fontPrint(8, 24, string.format("sound %d music playing %s %s", soundGetVolume(), tostring(musicIsPlaying()), said))
|
|
fontPrint(8, 42, string.format("step %d/%d %s", step, #steps, note))
|
|
if (frames % 20) == 1 and step < #steps then
|
|
step = step + 1
|
|
note = steps[step][1]
|
|
steps[step][2]()
|
|
elseif (frames % 20) == 11 then
|
|
singeScreenshot()
|
|
end
|
|
if frames == ((#steps + 1) * 20) then
|
|
singeQuit()
|
|
end
|
|
return OVERLAY_UPDATED
|
|
end
|