ExperimentalGear/scripts/titlescreen/pages/splash/kshootmaniapage.lua

74 lines
1.8 KiB
Lua

require "common.globals"
require "common.class"
local Dim = require "common.dimensions"
local Image = require "api.image"
local AudioSample = require "api.audiosample"
local Page = require "api.page.page"
---@class KShootManiaPage : Page
---@field logo_img Image
---@field splash_sample AudioSample
---@field _timer number
---@field _sample_played boolean
local KShootManiaPage = {
__name = "KShootManiaPage",
BACKGROUND_COLOR = {182, 0, 20},
LOGO_PATH = "titlescreen/splash/ksm.png",
SAMPLE_PATH = "titlescreen/splash/splash1.wav",
TIMEOUT = 3.0
}
---Create a new KShootManiaPage instance
---@param params? KShootManiaPage
function KShootManiaPage.new(params)
local self = CreateInstance(KShootManiaPage, params, Page)
self.logo_img = Image.new(self.LOGO_PATH)
self.splash_sample = AudioSample.new({path = self.SAMPLE_PATH})
self._timer = 0.0
self._sample_played = false
return self
end
function KShootManiaPage:init()
self._timer = 0.0
self._sample_played = false
Page.init(self)
end
function KShootManiaPage:drawBackground(deltaTime)
gfx.BeginPath()
gfx.FillColor(table.unpack(self.BACKGROUND_COLOR))
gfx.Rect(0, 0, Dim.design.width, Dim.design.height)
gfx.Fill()
end
function KShootManiaPage:drawContent(deltaTime)
local x = (Dim.design.width - self.logo_img.width) / 2
local y = (Dim.design.height - self.logo_img.height) / 2
self.logo_img:setPosition(x, y)
self.logo_img:render()
end
function KShootManiaPage:render(deltaTime)
if not self._sample_played then
self.splash_sample:play()
self._sample_played = true
end
Page.render(self, deltaTime)
if self._timer > self.TIMEOUT then
self:onInvalidation()
end
self._timer = self._timer + deltaTime
end
return KShootManiaPage