Many changes all around. Started main menu.

Added Drawable, Sprite and SoundEffect classes.
Added comments to Fader class.
This commit is contained in:
2025-10-05 02:26:39 -04:00
parent fe8944b526
commit 7f8d79e00f
12 changed files with 395 additions and 66 deletions

86
src/gstates/menu.lua Normal file
View File

@@ -0,0 +1,86 @@
------------------------------------------------------------------------------
-- 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