-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathswitchAnimState.lua
69 lines (57 loc) · 1.59 KB
/
switchAnimState.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
local State = require("state")
local Animation = require("anim")
local SwitchAnimState = {}
SwitchAnimState.__index = SwitchAnimState
setmetatable(SwitchAnimState, State)
SwitchAnimState.SINK_TIME = 1
SwitchAnimState.RAISE_TIME = 1
SwitchAnimState.TOTAL_TIME = SwitchAnimState.SINK_TIME + SwitchAnimState.RAISE_TIME
function SwitchAnimState.create(oldsubs, newsubs)
local self = setmetatable(State.create(), SwitchAnimState)
self.oldsubs = oldsubs
self.newsubs = newsubs
self.oldanims = {}
self.newanims = {}
for i=1,4 do
self.oldanims[i] = Animation.create(ResMgr.getImage("sub_sink".. oldsubs[i].player ..".png"),
48, 48, 0, 0, self.SINK_TIME/12, 12)
self.newanims[i] = Animation.create(ResMgr.getImage("sub_raise".. newsubs[i].player ..".png"),
48, 48, 0, 0, self.RAISE_TIME/8, 8)
self.oldanims[i].mode = 2
self.newanims[i].mode = 2
end
self.time = 0
return self
end
function SwitchAnimState:update(dt)
self.time = self.time + dt
if self.time < SwitchAnimState.SINK_TIME then
for i=1,4 do
self.oldanims[i]:update(dt)
end
elseif self.time < SwitchAnimState.TOTAL_TIME then
for i=1,4 do
self.newanims[i]:update(dt)
end
else
popState()
end
end
function SwitchAnimState:draw()
love.graphics.push()
love.graphics.translate(121, 8)
if self.time < SwitchAnimState.SINK_TIME then
for i=1,4 do
self.oldanims[i]:draw(self.oldsubs[i].x*48, self.oldsubs[i].y*48)
end
else
for i=1,4 do
self.newanims[i]:draw(self.newsubs[i].x*48, self.newsubs[i].y*48)
end
end
love.graphics.pop()
end
function SwitchAnimState:isTransparent()
return true
end
return SwitchAnimState