Rocket-Bytes/Source/Musicbox.lua

93 lines
3.2 KiB
Lua
Raw Normal View History

2022-06-28 23:30:32 +00:00
paused = false
playbackRate = 1.0
local timeRate = true
songTitle = "AAA"
2022-07-17 01:37:12 +00:00
local number = math.random(1000,9999)
2022-06-28 23:30:32 +00:00
local imgDither = playdate.graphics.image.new("gfx/dither")
local imgCover = playdate.graphics.image.new("gfx/cover1bit")
assert(imgDither)
assert(imgCover)
2022-06-20 05:56:43 +00:00
function updateBox()
2022-06-28 23:30:32 +00:00
playdate.graphics.clear()
processStars(-10,-10)
2022-06-20 05:56:43 +00:00
local change, aChange = playdate.getCrankChange()
if paused then
2022-06-27 06:21:44 +00:00
if change<0 then change = 0 end
2022-06-20 05:56:43 +00:00
song:setRate(change*0.03)
2022-06-28 23:30:32 +00:00
if not playdate.isCrankDocked() then
playdate.graphics.drawText(math.floor((change*0.03)*100).."%", 200 - playdate.graphics.getTextSize(math.floor((change*0.03)*100).."%")/ 2,210)
end
2022-06-20 05:56:43 +00:00
else
2022-06-28 23:30:32 +00:00
playbackRate += change*0.0005
if playbackRate < 0.2 then playbackRate = 0.2 elseif playbackRate > 3 then playbackRate = 3 end
if not playdate.isCrankDocked() or math.floor(playbackRate*100) ~= 100 then
playdate.graphics.drawText(math.floor(playbackRate * 100).."%", 200 - playdate.graphics.getTextSize(math.floor(playbackRate * 100).."%")/ 2,210)
end
2022-06-20 05:56:43 +00:00
song:setRate(playbackRate)
end
if playdate.buttonJustPressed(playdate.kButtonA) then
2022-06-28 23:30:32 +00:00
if paused == true then
paused = false
else
paused = true
end
2022-06-20 05:56:43 +00:00
playbackRate = 1.0
end
2022-06-28 23:30:32 +00:00
if paused then playdate.graphics.setPattern(imgDither) end
playdate.graphics.setLineWidth(10)
playdate.graphics.drawLine(0,235,(song:getOffset()/song:getLength())*400,235)
playdate.graphics.setColor(playdate.graphics.kColorWhite)
playdate.graphics.setLineWidth(2)
playdate.graphics.drawLine(0,19,400,19)
local time = playdate.getTime()
2024-03-08 01:10:56 +00:00
local displayTime = time.minute
if time.minute < 10 then
displayTime = "0"..time.minute
end
2022-06-28 23:30:32 +00:00
if timeRate == true then
local prefix = " AM"
2023-03-11 05:41:36 +00:00
if time.hour > 11 then prefix = " PM" end
if time.hour == 0 then time.hour = 24 end
local tt = (time.hour % 12)
if tt == 0 then tt = 12 end
2024-03-08 01:10:56 +00:00
playdate.graphics.drawText(tt..":"..displayTime..prefix,0,0)
2022-06-28 23:30:32 +00:00
else
2024-03-08 01:10:56 +00:00
playdate.graphics.drawText(time.hour..":"..displayTime,0,0)
2022-06-28 23:30:32 +00:00
end
playdate.graphics.drawText(math.ceil(playdate.getBatteryPercentage()).."%",400-playdate.graphics.getTextSize(math.ceil(playdate.getBatteryPercentage()).."%"),0)
imgCover:draw(200-67,30)
playdate.graphics.drawText(songTitle, 200 - playdate.graphics.getTextSize(songTitle)/2,180)
if math.floor(song:getOffset()) < math.floor(song:getLength()) then playdate.graphics.drawText(math.floor(song:getOffset()*100)/100,1,210) else playdate.graphics.drawText(math.floor(song:getLength()),1,210) end
2023-03-11 05:41:36 +00:00
playdate.graphics.drawText(math.floor(song:getLength()).."S",398- playdate.graphics.getTextSize(tostring(math.floor(song:getLength()))),210)
2022-06-28 23:30:32 +00:00
if playdate.buttonJustPressed(playdate.kButtonUp) then
if timeRate == true then timeRate = false else timeRate = true end
end
if playdate.buttonJustPressed(playdate.kButtonLeft) then
song:setOffset(0)
end
if playdate.buttonJustPressed(playdate.kButtonB) then
paused = false
playbackRate = 1.0
2022-06-20 05:56:43 +00:00
createMenu(songlist)
song:stop()
end
processExplosions()
2022-06-20 05:56:43 +00:00
end