-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathcountdownState.lua
51 lines (41 loc) · 1.37 KB
/
countdownState.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
local State = require("state")
local CountdownState = {}
CountdownState.__index = CountdownState
setmetatable(CountdownState, State)
function CountdownState.create(speed,start)
local self = setmetatable(State.create(), CountdownState)
self.speed = speed or 2
self.time = start or 0
self.img = ResMgr.getImage("321go.png")
self.quads = {}
self.quads[0] = love.graphics.newQuad(0, 0, 100, 128, 600, 128)
self.quads[1] = love.graphics.newQuad(100, 0, 100, 128, 600, 128)
self.quads[2] = love.graphics.newQuad(200, 0, 100, 128, 600, 128)
self.quads[3] = love.graphics.newQuad(300, 0, 300, 128, 600, 128)
return self
end
function CountdownState:update(dt)
self.time = self.time + dt*self.speed
if self.time > 4 then
popState()
end
end
function CountdownState:draw()
if self.time == 0 then return end
if self.time < 3 then
local quad = math.floor(self.time)
love.graphics.setColor(0, 0, 0, 128)
love.graphics.draw(self.img, self.quads[quad], (WIDTH-100)/2, 176)
love.graphics.setColor(255,255,255,255)
love.graphics.draw(self.img, self.quads[quad], (WIDTH-100)/2, 168)
else
love.graphics.setColor(0, 0, 0, 128)
love.graphics.draw(self.img, self.quads[3], (WIDTH-300)/2, 176)
love.graphics.setColor(255,255,255,255)
love.graphics.draw(self.img, self.quads[3], (WIDTH-300)/2, 168)
end
end
function CountdownState:isTransparent()
return true
end
return CountdownState