2025-10-05 02:26:39 -04:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- Imports
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local love = require 'love'
|
2025-10-05 17:47:17 -04:00
|
|
|
local assets = require 'src.utils.asstmngr'
|
2025-10-05 02:26:39 -04:00
|
|
|
local make_class = require 'src.utils.classes'
|
|
|
|
|
local GameState = require 'src.gstates.gstate'
|
2025-10-05 15:24:48 -04:00
|
|
|
local Fader = require 'src.graphics.fader'
|
|
|
|
|
local Sprite = require 'src.graphics.sprite'
|
2025-10-05 02:26:39 -04:00
|
|
|
local Cursor = require 'src.ui.cursor'
|
2025-10-05 15:24:48 -04:00
|
|
|
local SoundEffect = require 'src.sound.sfx'
|
2025-10-05 02:26:39 -04:00
|
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- Class definitions
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local MainMenu = make_class(GameState)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- Class methods
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
function MainMenu:_init(name, index)
|
|
|
|
|
GameState._init(self, name, index)
|
|
|
|
|
self.skip = false
|
|
|
|
|
self.fade = Fader()
|
|
|
|
|
|
2025-10-05 15:24:48 -04:00
|
|
|
-- Create sprites and buttons.
|
|
|
|
|
self.background = Sprite('imgs/cpu.png')
|
|
|
|
|
|
2025-10-05 02:26:39 -04:00
|
|
|
-- Create a mouse cursor object at the current mouse position.
|
|
|
|
|
local mx, my = love.mouse.getPosition()
|
|
|
|
|
self.cursor = Cursor(mx, my)
|
|
|
|
|
|
|
|
|
|
-- Create sound effects.
|
|
|
|
|
self.bgm = SoundEffect('bgm/eskisky.wav')
|
|
|
|
|
|
2025-10-05 17:47:17 -04:00
|
|
|
-- Register all assets.
|
|
|
|
|
assets:register(self.name, self.background)
|
|
|
|
|
assets:register(self.name, self.cursor)
|
|
|
|
|
assets:register(self.name, self.bgm)
|
2025-10-05 02:26:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:update(dt)
|
2025-10-05 17:47:17 -04:00
|
|
|
if assets:done(self.name) then
|
|
|
|
|
if not self.bgm:isPlaying() then self.bgm:play() end
|
2025-10-05 02:26:39 -04:00
|
|
|
|
2025-10-05 17:47:17 -04:00
|
|
|
-- Update the fader.
|
|
|
|
|
self.fade:update(dt)
|
2025-10-05 02:26:39 -04:00
|
|
|
|
2025-10-05 17:47:17 -04:00
|
|
|
-- Move on to the next game state if the user skipped the intro or all stages are complete.
|
|
|
|
|
if not self.skip then return self.index else return -1 end
|
|
|
|
|
else
|
|
|
|
|
assets:update(self.name)
|
|
|
|
|
end
|
2025-10-05 02:26:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
2025-10-05 17:47:17 -04:00
|
|
|
function MainMenu:draw()
|
|
|
|
|
if assets:done(self.name) then
|
|
|
|
|
self.background:draw()
|
|
|
|
|
self.cursor:draw()
|
|
|
|
|
self.fade:draw()
|
|
|
|
|
else
|
|
|
|
|
assets:draw()
|
|
|
|
|
end
|
2025-10-05 02:26:39 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:keypressed(key)
|
|
|
|
|
-- Skip the intro on any key press.
|
|
|
|
|
if key == "escape" then
|
|
|
|
|
self.skip = true
|
|
|
|
|
end
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:mousemoved(x, y, dx, dy)
|
|
|
|
|
self.cursor:mousemoved(x, y, dx, dy)
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- Module return
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
return MainMenu
|