fpv/source/scenes/Assemble.lua

269 lines
7.4 KiB
Lua
Raw Permalink Normal View History

2024-06-04 21:21:40 +03:00
Assemble = {}
class("Assemble").extends(BaseScene)
local scene = Assemble
local font = Graphics.font.new('assets/fonts/Mini Sans 2X')
2024-06-10 01:50:27 +03:00
local fontMed = Graphics.font.new('assets/fonts/onyx_9')
2024-06-04 21:21:40 +03:00
local allButtons = { "A", "B", "DOWN", "LEFT", "RIGHT", "UP" }
function scene:popCode(button)
2024-06-12 01:22:12 +03:00
if #scene.code == 0 then
return
end
2024-06-10 01:50:27 +03:00
scene.menuConfirmSound:stop()
2024-06-04 21:21:40 +03:00
if scene.tickTimer.paused then
scene.droneParts = scene:loadDrone(1, #scene.code)
scene.tickTimer:start()
scene.progressBar:setVisible(true)
end
if button == scene.code[1] then
table.remove(scene.code, 1)
scene.tickTimer:reset()
scene.dronePartIndex = scene.dronePartIndex + 1
2024-06-10 01:50:27 +03:00
local particle = ParticlePoly(200, 185)
2024-06-04 21:21:40 +03:00
particle:setThickness(2)
particle:setSize(1, 2)
particle:setSpeed(1, 3)
particle:setColour(Graphics.kColorXOR)
particle:add(5)
2024-06-10 01:50:27 +03:00
scene.dY = 5
scene.menuConfirmSound:play(1)
2024-06-04 21:21:40 +03:00
else
self.buttonTimeout = self.buttonTimeout - 5
scene.code[1] = scene:randomButton()
screenShake(100, 5)
end
end
scene.inputHandler = {
2024-06-12 01:22:12 +03:00
AButtonDown = function()
if #scene.code == 0 then
scene.menuConfirmSound:play(1)
Noble.transition(Game, nil, Noble.Transition.SpotlightMask)
else
scene:popCode("A")
end
end,
2024-06-04 21:21:40 +03:00
BButtonDown = function() scene:popCode("B") end,
downButtonDown = function() scene:popCode("DOWN") end,
leftButtonDown = function() scene:popCode("LEFT") end,
rightButtonDown = function() scene:popCode("RIGHT") end,
upButtonDown = function() scene:popCode("UP") end,
}
function scene:randomButton()
local button = allButtons[math.random(1, #allButtons)]
return button
end
function scene:drawBackground()
end
local screwDriver = Graphics.image.new('assets/sprites/assemble/sd.png')
2024-06-10 01:50:27 +03:00
local solder = Graphics.image.new('assets/images/solder.png')
2024-06-04 21:21:40 +03:00
function scene:loadButtons()
local buttons = {}
for i = 1, #allButtons do
local image = Graphics.image.new('assets/sprites/buttons/' .. allButtons[i] .. '.png')
buttons[allButtons[i]] = image
end
return buttons
end
function scene:loadDrone(id, parts)
local drone = {}
for i = 1, parts do
local image = Graphics.image.new('assets/sprites/assemble/' .. id .. '/' .. i .. '.png')
if image ~= nil then
table.insert(drone, image)
end
end
return drone
end
function scene:setValues()
scene.code = {}
2024-06-14 20:50:55 +03:00
for i = 1, 9 do
2024-06-04 21:21:40 +03:00
table.insert(scene.code, scene:randomButton())
end
2024-06-10 01:50:27 +03:00
scene.difficulty = Noble.Settings.get("difficulty")
2024-06-04 21:21:40 +03:00
scene.buttons = scene:loadButtons()
scene.droneParts = {}
scene.dronePartIndex = 0
2024-06-10 01:50:27 +03:00
scene.dY = 5
scene.buttonTimeout = 100
scene.timeToClick = DifficultySettings[scene.difficulty].assebleTime
scene.menuConfirmSound = playdate.sound.fileplayer.new("assets/audio/confirm")
2024-06-12 01:22:12 +03:00
scene.musicEnabled = Noble.Settings.get("music")
scene.levelAudio = playdate.sound.fileplayer.new("assets/audio/assemble")
scene.levelAudio:setVolume(0.7)
2024-06-04 21:21:40 +03:00
end
function scene:init()
scene.super.init(self)
scene:setValues()
2024-06-10 01:50:27 +03:00
scene.progressBar = ProgressBar(200, 175, 50, 5)
2024-06-04 21:21:40 +03:00
scene.progressBar:set(self.buttonTimeout)
scene.progressBar:setVisible(false)
2024-06-10 01:50:27 +03:00
scene.tickTimer = playdate.timer.new(scene.timeToClick, self.buttonTimeout, 0, playdate.easingFunctions.linear)
2024-06-04 21:21:40 +03:00
scene.tickTimer.updateCallback = function(timer)
scene.buttonTimeout = timer.value
scene.progressBar:set(scene.buttonTimeout)
end
scene.tickTimer.timerEndedCallback = function()
scene.buttonTimeout = 0
end
scene.tickTimer:pause()
end
function scene:start()
scene.super.start(self)
self.optionsMenu:addMenuItem("Main Menu", function() Noble.transition(Menu) end)
2024-06-12 01:22:12 +03:00
Noble.showFPS = false
2024-06-04 21:21:40 +03:00
end
function scene:enter()
scene.super.enter(self)
2024-06-12 01:22:12 +03:00
scene.buttonTimeout = 100
Noble.Input.setHandler(scene.inputHandler)
if scene.musicEnabled then
scene.levelAudio:play(0)
end
2024-06-14 20:33:09 +03:00
local text =
[[The drone is assembled and operational. We are ready for the mission.
An enemy tank is confirmed in the field. It threatens our advance.
Your task: eliminate the target. Clear the path for our assault units.
This operation is crucial. Execute with precision. Command out.]]
self.dialogue = pdDialogueBox(text, 390, 46)
-- self.dialogue:setPadding(4)
2024-06-04 21:21:40 +03:00
end
function round(number)
local formatted = string.format("%.2f", number)
return formatted
end
2024-06-10 01:50:27 +03:00
local elapsedTime = 0
2024-06-04 21:21:40 +03:00
function scene:update()
scene.super.update(self)
2024-06-14 20:33:09 +03:00
2024-06-10 01:50:27 +03:00
elapsedTime = elapsedTime + 1 / playdate.display.getRefreshRate()
2024-06-14 20:33:09 +03:00
local sddy = 0
local sdy = 0
local sddx = 0
2024-06-10 01:50:27 +03:00
2024-06-14 20:33:09 +03:00
if #scene.code == 0 then
if self.dialogue.enabled ~= true then
Noble.Input.setHandler(self.dialogue:getInputHandlers())
function self.dialogue:onClose()
Noble.Transition.setDefaultProperties(Noble.Transition.SpotlightMask, {
x = 325,
y = 95,
xEnd = 96,
yEnd = 100,
invert = false
})
scene.menuConfirmSound:play(1)
Noble.transition(Game, nil, Noble.Transition.SpotlightMask)
end
self.dialogue:enable()
return
else
scene.droneParts[#scene.droneParts]:draw(100, 20)
local dy = 1 * math.sin(10 * elapsedTime)
2024-06-10 01:50:27 +03:00
2024-06-14 20:33:09 +03:00
self.dialogue:update()
self.dialogue:draw(5, 186 + dy)
end
2024-06-04 21:21:40 +03:00
self.progressBar:remove()
self.tickTimer:remove()
2024-06-14 20:33:09 +03:00
end
if #scene.code ~= 0 then -- TODO: this is a hack. no, it's not. it's a SHIT. Why i am do this? What i do with my life?
sddy = 4 * math.sin(10 * elapsedTime)
sdy = 4 * math.sin(7 * elapsedTime)
sddx = 2 * math.cos(5 * elapsedTime)
end
screwDriver:draw(300 + sddx, 100 + sddy)
solder:draw(0, 100 + sdy)
if #scene.code == 0 then
2024-06-04 21:21:40 +03:00
return
end
2024-06-14 20:33:09 +03:00
if scene.tickTimer.paused then
Noble.Text.draw("Assemble the drone!", 200, 110, Noble.Text.ALIGN_CENTER, false, font)
end
2024-06-04 21:21:40 +03:00
if scene.buttonTimeout <= 0 then
2024-06-14 20:33:09 +03:00
Noble.Text.draw("Fuck!", 200, 110, Noble.Text.ALIGN_CENTER, false, font)
2024-06-04 21:21:40 +03:00
self.progressBar:remove()
self.tickTimer:remove()
screenShake(100, 5)
2024-06-10 01:50:27 +03:00
Noble.Input.setEnabled(false)
2024-06-04 21:21:40 +03:00
return
end
if scene.droneParts ~= nil and scene.dronePartIndex ~= nil and scene.dronePartIndex > 0 and #scene.droneParts > 0 then
scene.droneParts[scene.dronePartIndex]:draw(100, 20)
end
2024-06-10 01:50:27 +03:00
Graphics.drawLine(180, 185, 192, 185)
Graphics.drawLine(208, 185, 220, 185)
if scene.dY > 0 then
scene.dY = self.dY - 0.5
end
2024-06-04 21:21:40 +03:00
for i = 1, #scene.code do
local button = scene.buttons[scene.code[i]]
local first = 1
if #scene.code == 1 then
first = 0
end
local t = (i - 1) / (#scene.code - first)
local opaque = playdate.math.lerp(1, 0.3, t) --TODO: not the best solution
2024-06-10 01:50:27 +03:00
local y = 185 + ((i - 1) * 16) - 8 + scene.dY
button:drawFaded(192, y, opaque, playdate.graphics.image.kDitherTypeBayer2x2)
2024-06-04 21:21:40 +03:00
end
end
function scene:exit()
scene.super.exit(self)
2024-06-12 01:22:12 +03:00
scene.levelAudio:stop()
2024-06-04 21:21:40 +03:00
Noble.showFPS = false
end
function scene:finish()
scene.super.finish(self)
playdate.display.setScale(1)
end