2025-10-05 02:26:39 -04:00
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
-- Imports
|
|
|
|
|
------------------------------------------------------------------------------
|
|
|
|
|
|
|
|
|
|
local love = require 'love'
|
|
|
|
|
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')
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:load()
|
|
|
|
|
-- Load sprites.
|
2025-10-05 15:24:48 -04:00
|
|
|
self.background:load()
|
2025-10-05 02:26:39 -04:00
|
|
|
self.cursor:load()
|
|
|
|
|
|
|
|
|
|
-- Load sound effects and start playing the background music
|
|
|
|
|
self.bgm:load()
|
|
|
|
|
self.bgm:play()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:update(dt)
|
|
|
|
|
-- Update the fader.
|
|
|
|
|
self.fade:update(dt)
|
|
|
|
|
|
|
|
|
|
-- 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
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:draw()
|
2025-10-05 15:24:48 -04:00
|
|
|
self.background:draw()
|
2025-10-05 02:26:39 -04:00
|
|
|
self.cursor:draw()
|
|
|
|
|
self.fade:draw()
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function MainMenu:unload()
|
2025-10-05 15:24:48 -04:00
|
|
|
self.background:unload()
|
2025-10-05 02:26:39 -04:00
|
|
|
self.cursor:unload()
|
|
|
|
|
self.bgm:unload()
|
|
|
|
|
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
|