-
Notifications
You must be signed in to change notification settings - Fork 8
/
manStage.lua
329 lines (267 loc) · 5.13 KB
/
manStage.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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
------------------ Man Stage ---------------------
-- Man animation frames
local M1 = 1
local M2 = 2
local M3 = 3
local M4 = 4
local M5 = 5
local M6 = 6
local M7 = 7
local M8 = 8
-- Man x coordinates
local X0 = 72
local X1 = 76
local X2 = 80
local X3 = 84
local X4 = 88
local X5 = 92
local X6 = 96
local X7 = 100
local X8 = 104
-- Man y coordinates
local Y1 = (F0 + ANT_HEIGHT - 16)
local Y2 = (Y1 - 10)
local Y3 = (Y2 - 8)
local Y4 = (Y3 - 6)
local Y5 = (Y3 - 4)
-- Man loop left animation
local loopLeftData =
{
X8, Y1, M2,
X7, Y2, M3,
X6, Y3, M4,
X5, Y4, M5,
X4, Y5, M6,
X3, Y4, M7,
X2, Y3, M8,
X1, Y2, M3,
X0, Y1, M2,
X0, Y1, M1
}
-- Man loop right animation
local loopRightData =
{
X0, Y1, M2,
X1, Y2, M3,
X2, Y3, M8,
X3, Y4, M7,
X4, Y5, M6,
X5, Y4, M5,
X6, Y3, M4,
X7, Y2, M3,
X8, Y1, M2,
X8, Y1, M1
}
-- Length of loop data arrays
local LOOP_STEPS = 30
-- Man actions
local LLT = 0 -- loop left
local LRT = 2 -- loop right
local WLT = 4 -- slide left
local WRT = 6 -- slide right
local SPR = 8 -- spray
local PAS = 10 -- pause
-- Man action array
local actions =
{
LLT, PAS, SPR, WRT, WLT, SPR, LRT, PAS, SPR, LLT,
WRT, SPR, PAS, LLT, LRT, SPR, WLT, LRT, PAS, SPR
}
man = {}
local spray = {}
--
function man.init()
if ant.x > 0 then
ant.slide()
return false
end
man.x = X8
man.y = Y1
man.frame = 1
man.loopCounter = 1
man.actionCounter = 1
man.action = 1
man.delay = 0
man.images =
{
globalImages.man1,
globalImages.man2,
globalImages.man3,
globalImages.man4,
globalImages.man5,
globalImages.man6,
globalImages.man7,
globalImages.man8
}
man.rightImages =
{
globalImages.manRight1,
globalImages.manRight2
}
man.leftImages =
{
globalImages.manLeft1,
globalImages.manLeft2
}
man.jumpSound = love.audio.newSource("assets/ManJump.wav" , "static")
man.spraySound = love.audio.newSource("assets/Shoot.wav" , "static")
spray.image = globalImages.spray
spray.x = 0
spray.y = 0
sprites.man = createSprite(man.images[1], man.x, man.y, 1)
man.setNext()
return true
end
--
function man.update()
ant.move3()
--print("f "..man.frame..", x "..man.x..", y "..man.y)
sprites.man.image = man.images[man.frame]
sprites.man.x = man.x
sprites.man.y = man.y
updateSprite(sprites.man, man.images[man.frame], man.x, man.y)
man.move()
local done = (ant.x == (128-16))
if done then
game.win = true
end
return done
end
--
function man.finish()
-- Beep(2);
-- Delay(2);
-- Beep(4);
-- Delay(4);
-- Beep(8);
-- Delay(3);
sprites.man = nil
end
--
function man.move()
if man.action == LLT then
man.loopLeft()
elseif man.action == LRT then
man.loopRight()
elseif man.action == WLT then
man.walkLeft()
elseif man.action == WRT then
man.walkRight()
elseif man.action == SPR then
man.pushSpray()
else
if man.delay > 0 then
man.delay = man.delay - 1
else
man.setNext()
end
end
end
--
function man.setNext()
man.loopCounter = 1
man.frame = 1
man.action = actions[man.actionCounter]
man.actionCounter = man.actionCounter + 1
if man.actionCounter > 20 then
man.actionCounter = 1
end
if man.action == SPR then
spray.x = man.x - 16
spray.y = man.y
sprites.spray = createSprite(spray.image, spray.x, spray.y, 1)
love.audio.play(man.spraySound)
elseif man.action == PAS then
man.delay = 5
end
end
--
function man.walkRight()
man.y = Y1
man.frame = man.frame + 1
if man.frame > 2 then
man.frame = 1
end
man.x = man.x + 4
if man.x == X8 then
sprites.man.image = man.images[1]
else
sprites.man.image = man.rightImages[man.frame]
end
sprites.man.x = man.x
sprites.man.y = man.y
if man.x == X8 then
man.setNext()
end
end
--
function man.walkLeft()
man.y = Y1
man.frame = man.frame + 1
if man.frame > 2 then
man.frame = 1
end
man.x = man.x - 4
if man.x == X0 then
sprites.man.image = man.images[1]
else
sprites.man.image = man.leftImages[man.frame]
end
sprites.man.x = man.x
sprites.man.y = man.y
if man.x == X0 then
man.setNext()
end
end
--
function man.loopLeft()
--print("loop left")
local x = loopLeftData[man.loopCounter + 0]
local y = loopLeftData[man.loopCounter + 1]
local frame = loopLeftData[man.loopCounter + 2]
-- Update sprite
sprites.man.x = x
sprites.man.y = y
sprites.man.image = man.images[frame]
man.x = x
man.y = y
man.frame = frame
--print("f "..man.frame..", x "..man.x..", y "..man.y)
if man.loopCounter == 1 then
love.audio.play(man.jumpSound)
end
man.loopCounter = man.loopCounter + 3
if man.loopCounter > LOOP_STEPS then
man.setNext()
end
end
--
function man.loopRight()
local x = loopRightData[man.loopCounter + 0]
local y = loopRightData[man.loopCounter + 1]
local frame = loopRightData[man.loopCounter + 2]
-- Update sprite
sprites.man.x = x
sprites.man.y = y
sprites.man.image = man.images[frame]
man.x = x
man.y = y
man.frame = frame
if man.loopCounter == 1 then
love.audio.play(man.jumpSound)
end
man.loopCounter = man.loopCounter + 3
if man.loopCounter > LOOP_STEPS then
man.setNext()
end
end
--
function man.pushSpray()
spray.x = spray.x - 4
if spray.x > -16 and sprites.spray ~= nil then
sprites.spray.x = spray.x
else
sprites.spray = nil
man.setNext()
end
end