fpv/source/scenes/DroneCardSelector.lua

119 lines
3.0 KiB
Lua
Raw Normal View History

2024-06-12 01:22:12 +03:00
DroneCardSelector = {}
class("DroneCardSelector").extends(BaseScene)
local scene = DroneCardSelector
local fontMed = Graphics.font.new('assets/fonts/onyx_9')
local elapsedTime = 0
scene.inputHandler = {
AButtonDown = function()
if Drones[scene.menuIndex].locked == true then
return
end
2024-06-12 01:22:12 +03:00
scene.menuConfirmSound:play(1)
Noble.transition(Assemble)
end,
BButtonDown = function() end,
downButtonDown = function()
end,
leftButtonDown = function()
if scene.menuIndex <= 1 then
return
end
scene.menuSelSound:play(1)
scene.targetX = scene.targetX + 355
scene.menuIndex = scene.menuIndex - 1
scene.paginator:set(scene.menuIndex)
end,
rightButtonDown = function()
if scene.menuIndex >= 4 then
return
end
scene.menuSelSound:play(1)
scene.targetX = scene.targetX - 355
scene.menuIndex = scene.menuIndex + 1
scene.paginator:set(scene.menuIndex)
end,
upButtonDown = function()
end,
}
function scene:setValues()
self.menuIndex = 1
self.aKey = Graphics.image.new("assets/sprites/buttons/A")
scene.menuConfirmSound = playdate.sound.fileplayer.new("assets/audio/confirm")
scene.menuSelSound = playdate.sound.fileplayer.new("assets/audio/menu_select")
scene.menuSelSound:setVolume(0.5)
scene.currentX = 0
scene.targetX = 0
end
function scene:init()
scene.super.init(self)
scene:setValues()
end
function scene:start()
scene.super.start(self)
self.optionsMenu:addMenuItem("Main Menu", function() Noble.transition(Menu) end)
Noble.showFPS = false
end
function scene:enter()
scene.super.enter(self)
scene.cards = {
DroneCard(0, 0, Drones[1]),
DroneCard(0, 0, Drones[2]),
DroneCard(0, 0, Drones[3]),
DroneCard(0, 0, Drones[4]),
}
scene.paginator = PageSprite(200, 207)
end
function scene:update()
scene.super.update(self)
if scene.cards == nil then
print("scene.cards is nil")
return
end
elapsedTime = elapsedTime + 1 / playdate.display.getRefreshRate()
local dy = 2 * math.sin(20 * elapsedTime)
local speed = 40
if math.abs(scene.targetX - scene.currentX) < speed then
scene.currentX = scene.targetX
else
scene.currentX = scene.currentX + speed * ((scene.targetX > scene.currentX) and 1 or -1)
end
local x = 0
for i = 1, 4 do
x = 29 + (339 + 16) * (i - 1)
scene.cards[i]:moveTo(x + scene.currentX, 25)
end
if Drones[scene.menuIndex].locked == false then
self.aKey:draw(315, 207 + dy)
Noble.Text.draw("Assemble", 333, 210, Noble.Text.ALIGN_LEFT, false, fontMed)
end
scene.paginator:moveTo(200, 207)
end
function scene:exit()
scene.super.exit(self)
for i = 1, 4 do
scene.cards[i]:remove()
end
Noble.showFPS = false
end
function scene:finish()
scene.super.finish(self)
playdate.display.setScale(1)
end