-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathescapeState.lua
211 lines (181 loc) · 5.57 KB
/
escapeState.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
local State = require("state")
local EventScoreState = require("eventScoreState")
local Animation = require("anim")
local EscapeState = {}
EscapeState.__index = EscapeState
setmetatable(EscapeState, State)
EscapeState.STATE_GAME = 0
EscapeState.STATE_SHAKE = 1
EscapeState.STATE_OVER = 2
EscapeState.TIME_SCALE = 3
EscapeState.DURATION = 6
EscapeState.WARNING_TIME = 2
function EscapeState.create(parent, scores)
local self = setmetatable(State.create(), EscapeState)
self.inputs = parent.inputs
self.bots = parent.bots
self.scores = scores
self.state = EscapeState.STATE_GAME
self.barTop = 33+56
self.barBottom = 33+318
self.barLength = 263
self.greenTop = 213
self.greenBottom = 233
self.time = 0
self.cursorPos = 0
self.marker_pos = {}
self.escaped = nil
self.offsetx = 0
self.clicked = {false, false, false, false}
self.markers = {}
self.bg = ResMgr.getImage("escape_bg.png")
self.frame = ResMgr.getImage("minigame_frame.png")
self.mouth_top = ResMgr.getImage("escape_mouth_top.png")
self.mouth_closed = ResMgr.getImage("escape_mouth_closed.png")
self.mouth_closed_lines = ResMgr.getImage("escape_mouth_closed_lines.png")
self.cursor = ResMgr.getImage("escape_cursor.png")
self.markers = ResMgr.getImage("escape_markers.png")
self.ducks = ResMgr.getImage("escape_ducks.png")
self.ghosts = ResMgr.getImage("escape_ghosts.png")
self.buttonAnim = Animation.create(ResMgr.getImage("small_button_anim.png"), 44, 38, 0, 0, 0.2, 2)
self.tearAnim = Animation.create(ResMgr.getImage("teardrop.png"), 9, 16, 0, 0, 0.3, 2)
self.duck_quads = {}
self.ghost_quads = {}
self.marker_quads = {}
for i=1,4 do
self.duck_quads[i] = love.graphics.newQuad((i-1)*52, 0, 52, 47, 208, 47)
self.ghost_quads[i] = love.graphics.newQuad((i-1)*50, 0, 50, 72, 200, 72)
self.marker_quads[i] = love.graphics.newQuad((i-1)*8, 0, 8, 15, 32, 15)
end
return self
end
function EscapeState:enter()
MusicMgr.playMinigame()
for i=1,4 do
if self.bots[i] then
self.bots[i]:escapeEnter()
end
end
end
function EscapeState:update(dt)
self.time = self.time + dt
self.buttonAnim:update(dt)
self.tearAnim:update(dt)
if self.state == EscapeState.STATE_GAME then
self.cursorPos = 1 - (math.cos(self.time*EscapeState.TIME_SCALE) / 2 + 0.5)
local allDead = true
for i=1,4 do
if self.bots[i] then
self.bots[i]:escapeUpdate(dt)
if self.bots[i]:wasClicked() then
self.inputs[i].clicked = true
end
self.bots[i]:clear()
end
if self.clicked[i] == false and self.inputs[i]:wasClicked() then
if self:isGreen() then
playSound("squeek")
self.escaped = i
self.state = EscapeState.STATE_SHAKE
self.time = 0
break
else
playSound("fail")
self.clicked[i] = true
self.marker_pos[i] = self:getCursorY()
end
end
if self.clicked[i] == false then
allDead = false
end
end
if self.time > EscapeState.DURATION then
self.state = EscapeState.STATE_OVER
playSound("slam")
self.time = 0
elseif self.time > EscapeState.DURATION-EscapeState.WARNING_TIME then
self.offsetx = math.sign(math.cos(self.time*30))*6
end
if allDead == true then
self.state = EscapeState.STATE_SHAKE
self.time = 0
end
elseif self.state == EscapeState.STATE_SHAKE then
self.offsetx = math.sign(math.cos(self.time*30))*6
if self.time > 1 then
self.time = 0
self.state = EscapeState.STATE_OVER
playSound("slam")
if self.escaped then
playSound("escape")
end
end
elseif self.state == EscapeState.STATE_OVER then
if self.time >= 2 then
self.time = 2
local deltas = {0, 0, 0, 0}
if self.escaped then
deltas[self.escaped] = rules.escapeprize
end
pushState(EventScoreState.create(self, self.scores, deltas))
end
end
end
function EscapeState:draw()
love.graphics.draw(self.bg, 63, 54)
love.graphics.draw(self.frame, 42, 33)
setScissor(63, 54, 573, 333)
love.graphics.draw(self.cursor, 548, self:getCursorY()-5)
for i=1,4 do
if self.clicked[i] then
love.graphics.draw(self.markers, self.marker_quads[i], 588, self.marker_pos[i]-10)
end
end
if self.state == EscapeState.STATE_GAME then
for i=1,4 do
love.graphics.draw(self.ducks, self.duck_quads[i], 180+(i-1)*53, 298)
if self.clicked[i] and self.escaped ~= i then
self.tearAnim:draw(213+(i-1)*53, 329)
end
end
self.buttonAnim:draw(501, 202)
love.graphics.draw(self.mouth_top, 64+self.offsetx, 66)
elseif self.state == EscapeState.STATE_SHAKE then
for i=1,4 do
love.graphics.draw(self.ducks, self.duck_quads[i], 180+(i-1)*53, 298)
if self.clicked[i] and self.escaped ~= i then
self.tearAnim:draw(213+(i-1)*53, 329)
end
end
love.graphics.draw(self.mouth_top, 64+self.offsetx, 66)
elseif self.state == EscapeState.STATE_OVER then
if self.time < 0.2 then
love.graphics.draw(self.mouth_closed_lines, 63, 54)
else
love.graphics.draw(self.mouth_closed, 63, 54)
end
for i=1,4 do
if self.escaped == i then
love.graphics.draw(self.ducks, self.duck_quads[i], 206+(i-1)*53-self.time*250, 340-self.time*250, -6*self.time, 1+self.time, 1+self.time, 26, 42)
else
if self.time > 1 then
love.graphics.setColor(255, 255, 255, (2-self.time)*255)
end
love.graphics.draw(self.ghosts, self.ghost_quads[i], 181+(i-1)*53, 305-self.time*140)
love.graphics.setColor(255,255,255,255)
end
end
end
setScissor()
end
function EscapeState:isTransparent()
return true
end
function EscapeState:getCursorY()
return self.barTop + self.cursorPos * self.barLength
end
function EscapeState:isGreen()
local cursorY = self:getCursorY()
return cursorY >= self.greenTop and cursorY <= self.greenBottom
end
return EscapeState