Started sketchign the game state.

This commit is contained in:
2026-09-20 01:07:04 -04:00
parent d69768c649
commit 8875e31097
4 changed files with 50 additions and 77 deletions
Binary file not shown.

After

Width:  |  Height:  |  Size: 50 KiB

+41 -75
View File
@@ -2,11 +2,14 @@
-- Imports -- Imports
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local love = require 'love'
local assets = require 'src.utils.asstmngr'
local make_class = require 'src.utils.classes' local make_class = require 'src.utils.classes'
local GameState = require 'src.gstates.gstate' local GameState = require 'src.gstates.gstate'
local Sprite = require 'src.graphics.sprite' local Sprite = require 'src.graphics.sprite'
local Fader = require 'src.graphics.fader' local Fader = require 'src.graphics.fader'
local SoundEffect = require 'src.sound.sfx' local SoundEffect = require 'src.sound.sfx'
local Cursor = require 'src.ui.cursor'
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
-- Class definitions -- Class definitions
@@ -21,107 +24,70 @@ local Game = make_class(GameState)
function Game:_init(name, index) function Game:_init(name, index)
GameState._init(self, name, index) GameState._init(self, name, index)
self.skip = false
self.fade = Fader() self.fade = Fader()
self.stage = 0
self.timer = 0
self.splash = Sprite('imgs/splash.png') self.bckg = Sprite('imgs/kitchen.png')
self.author = Sprite('imgs/wally.png') self.quit_snd = SoundEffect('snd/byebye.wav')
self.title = Sprite('imgs/title.png')
self.splash_snd = SoundEffect('snd/jachiev.wav') -- Create a mouse cursor object at the current mouse position.
self.author_snd = SoundEffect('snd/alang.wav') local mx, my = love.mouse.getPosition()
self.title_snd = SoundEffect('snd/ablhole.wav') self.cursor = Cursor(mx, my)
end
assets:register(self.name, self.cursor)
assets:register(self.name, self.bckg)
assets:register(self.name, self.quit_snd)
function Game:load() self.quit = false
-- Load all assets.
self.splash:load()
self.author:load()
self.title:load()
self.splash_snd:load()
self.author_snd:load()
self.title_snd:load()
-- Play the initial sound effect.
self.splash_snd:play()
end end
function Game:update(dt) function Game:update(dt)
local total_time if self.all_loaded then
-- Set time to wait for each intro stage.
if self.stage == 0 then
total_time = 6.5
elseif self.stage == 1 then
total_time = 5.0
else
total_time = 8.0
end
-- Start counting the stage time when the fade in is done.
if self.fade.done then
self.timer = self.timer + dt
end
-- Check if it's time to change stage.
if self.timer >= total_time then
self.fade:fade_out(
function ()
-- Change the stage and play the corresponding sound.
self.stage = self.stage + 1
if self.stage == 1 then
self.author_snd:play()
elseif self.stage == 2 then
self.title_snd:play()
end
-- Request a fade in.
self.fade:fade_in()
end
)
-- Reset the stage timer.
self.timer = 0.0
end
-- Update the fader. -- Update the fader.
self.fade:update(dt) self.fade:update(dt)
-- Move on to the next game state if the user skipped the intro or all stages are complete. -- Move on to the next game state if the user skipped the intro or all stages are complete.
if not self.skip and self.stage < 3 then return self.index else return 2 end if self.quit then
return -1
else
return self.index
end
else
local done = true
assets:update(self.name)
self.all_loaded = assets:done(self.name) and done
return self.index
end
end end
function Game:draw() function Game:draw()
-- If there is data to draw, then draw the current stage's backdrop. if self.all_loaded then
if self.stage == 0 then self.splash:draw() self.bckg:draw()
elseif self.stage == 1 then self.author:draw() self.cursor:draw()
elseif self.stage == 2 then self.title:draw() end
-- Draw the fader if needed.
self.fade:draw() self.fade:draw()
else
assets:draw()
end
end end
function Game:unload() function Game:unload()
-- Null all assets so they can be claimed by the GC. assets:unload(self.name)
self.splash:unload()
self.author:unload()
self.title:unload()
self.splash_snd:unload()
self.author_snd:unload()
self.title_snd:unload()
end end
function Game:keypressed(_) function Game:mousemoved(x, y, dx, dy)
self.cursor:mousemoved(x, y, dx, dy)
end
function Game:keypressed(key)
-- Skip the intro on any key press. -- Skip the intro on any key press.
self.skip = true if key == "escape" then
self.quit = true
self.quit_snd:play()
end
end end
+5
View File
@@ -166,6 +166,11 @@ function Menu:mousereleased(x, y, btn)
end end
function Menu:unload()
assets:unload(self.name)
end
function Menu:IsCursorInGameBtn(x, y) function Menu:IsCursorInGameBtn(x, y)
return x >= 224 and x <= 224 + 89 and y >= 131 and y <= 131 + 30 return x >= 224 and x <= 224 + 89 and y >= 131 and y <= 131 + 30
end end
+2
View File
@@ -3,6 +3,7 @@
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
local Menu = require 'src.gstates.menu' local Menu = require 'src.gstates.menu'
local Game = require 'src.gstates.game'
------------------------------------------------------------------------------ ------------------------------------------------------------------------------
@@ -12,6 +13,7 @@ local Menu = require 'src.gstates.menu'
-- Table of all valid game states. -- Table of all valid game states.
local states = { local states = {
Menu('menu', 1), Menu('menu', 1),
Game('game', 2),
} }