87 lines
2.1 KiB
Lua
87 lines
2.1 KiB
Lua
|
|
------------------------------------------------------------------------------
|
||
|
|
-- Imports
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
|
||
|
|
local love = require 'love'
|
||
|
|
local make_class = require 'src.utils.classes'
|
||
|
|
local GameState = require 'src.gstates.gstate'
|
||
|
|
local Fader = require 'src.utils.fader'
|
||
|
|
local Cursor = require 'src.ui.cursor'
|
||
|
|
local SoundEffect = require 'src.utils.sfx'
|
||
|
|
|
||
|
|
|
||
|
|
------------------------------------------------------------------------------
|
||
|
|
-- 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()
|
||
|
|
|
||
|
|
-- 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.
|
||
|
|
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()
|
||
|
|
self.cursor:draw()
|
||
|
|
self.fade:draw()
|
||
|
|
end
|
||
|
|
|
||
|
|
|
||
|
|
function MainMenu:unload()
|
||
|
|
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
|