Added intro game state and placeholder assets.
This commit is contained in:
@@ -5,6 +5,7 @@
|
||||
local love = require 'love'
|
||||
local make_class = require 'src.classes'
|
||||
local GameState = require 'src.gstate'
|
||||
local Fader = require 'src.fader'
|
||||
|
||||
|
||||
------------------------------------------------------------------------------
|
||||
@@ -19,37 +20,83 @@ local Intro = make_class(GameState)
|
||||
------------------------------------------------------------------------------
|
||||
|
||||
function Intro:_init(name, index)
|
||||
-- Call super-class constructor.
|
||||
GameState._init(self, name, index)
|
||||
|
||||
-- Attribute definitions
|
||||
self.skip = false
|
||||
self.fade = Fader()
|
||||
self.stage = 0
|
||||
self.timer = 0
|
||||
end
|
||||
|
||||
|
||||
function Intro:load()
|
||||
self.background = love.graphics.newImage('imgs/cpu.png')
|
||||
self.splash = love.graphics.newImage('imgs/splash.png')
|
||||
self.author = love.graphics.newImage('imgs/wally.png')
|
||||
self.title = love.graphics.newImage('imgs/title.png')
|
||||
self.splash_snd = love.audio.newSource('snd/jachiev.wav')
|
||||
self.author_snd = love.audio.newSource('snd/alang.wav')
|
||||
self.title_snd = love.audio.newSource('snd/ablhole.wav')
|
||||
self.valid = true
|
||||
|
||||
self.splash_snd:play()
|
||||
end
|
||||
|
||||
|
||||
function Intro:update(_)
|
||||
if not self.skip then return self.index else return 0 end
|
||||
function Intro:update(dt)
|
||||
local total_time
|
||||
|
||||
if self.stage == 0 then
|
||||
total_time = 4.5
|
||||
elseif self.stage == 1 then
|
||||
total_time = 3.0
|
||||
else
|
||||
total_time = 8.0
|
||||
end
|
||||
|
||||
if self.fade.done then
|
||||
self.timer = self.timer + dt
|
||||
end
|
||||
|
||||
if self.timer >= total_time then
|
||||
self.fade:fade_out(
|
||||
function ()
|
||||
self.stage = self.stage + 1
|
||||
|
||||
if self.stage == 1 then
|
||||
self.author_snd:play()
|
||||
elseif self.stage == 2 then
|
||||
self.title_snd:play()
|
||||
end
|
||||
|
||||
self.fade:fade_in()
|
||||
end
|
||||
)
|
||||
self.timer = 0.0
|
||||
end
|
||||
|
||||
self.fade:update(dt)
|
||||
|
||||
if not self.skip and self.stage < 3 then return self.index else return 2 end
|
||||
end
|
||||
|
||||
|
||||
function Intro:draw()
|
||||
if self.valid then
|
||||
love.graphics.draw(self.background, 0, 0)
|
||||
love.graphics.print(string.format('OS: %s', love.system.getOS()), 5, 5)
|
||||
love.graphics.print(string.format('Love version: %s', love.getVersion()), 5, 15)
|
||||
love.graphics.print(string.format('Memory usage: %s KiB', love.system.getMemUsage()), 5, 25)
|
||||
if self.stage == 0 then love.graphics.draw(self.splash, 0, 0)
|
||||
elseif self.stage == 1 then love.graphics.draw(self.author, 0, 0)
|
||||
elseif self.stage == 2 then love.graphics.draw(self.title, 0, 0) end
|
||||
end
|
||||
|
||||
self.fade:draw()
|
||||
end
|
||||
|
||||
|
||||
function Intro:unload()
|
||||
self.background = nil
|
||||
self.splash = nil
|
||||
self.author = nil
|
||||
self.title = nil
|
||||
self.splash_snd = nil
|
||||
self.author_snd = nil
|
||||
self.title_snd = nil
|
||||
self.valid = false
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user