------------------------------------------------------------------------------ -- Imports ------------------------------------------------------------------------------ local love = require 'love' local make_class = require 'src.utils.classes' local GameState = require 'src.gstates.gstate' local Fader = require 'src.graphics.fader' local Sprite = require 'src.graphics.sprite' local Cursor = require 'src.ui.cursor' local SoundEffect = require 'src.sound.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 sprites and buttons. self.background = Sprite('imgs/cpu.png') -- 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.background:load() 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.background:draw() self.cursor:draw() self.fade:draw() end function MainMenu:unload() self.background: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