your-own-drum/recorder.lua

32 lines
621 B
Lua

--Record demos.
local love = love
local recorder = {}
recorder.isLoaded = false
local i = 0
local function Reset()
i = 0
end
function recorder.Update( ddx, ddy )
local byte = 0
if ddx > 0.5 then byte = byte + 1 end
if ddy > 0.5 then byte = byte + 2 end
if ddx < -0.5 then byte = byte + 4 end
if ddy < -0.5 then byte = byte + 8 end
i = i + 1
recorder[i] = string.char( byte )
end
function recorder.Load( )
local s = love.filesystem.read( "demo" )
recorder.isLoaded = true
end
function recorder.Save( )
assert( love.filesystem.write( "demo", table.concat( recorder ) ) )
end
return recorder