-
Notifications
You must be signed in to change notification settings - Fork 0
/
animation.lua
507 lines (460 loc) · 15.1 KB
/
animation.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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
animation = class("animation")
--[[ TRIGGERS:
mapload when the map is loaded
timepassed:time when <time> ms have passed
playerxgreater:x when a player's x is greater than x
playerxless:x when a player's x is less than x
playerygreater:x when a player's y is greater than y
playeryless:x when a player's y is less than y
animationtrigger:i when animationtrigger with ID i is triggered
--]]
--[[ CONDITIONS:
noprevsublevel doesn't if the level was changed from another sublevel (Mario goes through pipe, lands in 1-1_1, prevsublevel was _0, no trigger.)
worldequals:i only triggers if current world is i
levelequals:i only triggers if current level is i
sublevelequals:i only triggers if current sublevel is i
requirecoins:i requires i coins to trigger (will not remove coins)
--]]
--[[ ACTIONS:
disablecontrols[:player] disables player input and hides the portal line
enablecontrols[:player] enables player input and shows portal line
sleep:time waits for <time> secs
setcamerax:x sets the camera xscroll to <x>
setcameray:y sets the camera yscroll to <y>
pancameratox:x:time pans the camera horizontally over <time> secs to <x>
pancameratoy:y:time pans the camera vertically over <time> secs to <y>
disablescroll disables autoscroll
enablescroll enables autoscroll
disablexscroll disables horizontal autoscroll
enablexscroll enables horizontal autoscroll
disableyscroll disables vertical autoscroll
enableyscroll enables vertical autoscroll
setx[:player]:x sets the x-position of player(s)
sety[:player]:y sets the y-position of player(s)
playerwalk[:player]:direction makes players walk into the given <direction>
playeranimationstop[:player] stops whatever animation the player is in
disableanimation disables this animation from triggering
enableanimation enables this animation to trigger
playerjump[:player] makes players jump (as high as possible)
playerstopjump[:player] makes players abort the jump (for small jumps)
dialogbox:text[:speaker] creates a dialogbox with <text> and <speaker>
removedialogbox removes the dialogbox
playmusic:i plays music <i>
screenshake:power makes the screen shake with <power>
addcoins:coins adds <coins> coins
addpoints:points adds <points> points
changebackgroundcolor:r:g:b changes background color ro rgb
killplayer[:player] kills player(s)
changetime:time changes the time left to <time>
loadlevel:world:level:sublevel starts level <world>-<level>_<sublevel>
disableplayeraim:player disables mouse or joystick aiming for <player>
enableplayeraim:player enables mouse or joystick aiming for <player>
closeportals[:player] closes portals for <player>
makeplayerlook:player:angle makes players aim in direction of <angle>, starting at right and going CCW, should probably be used in connection with "disableplayeraim" because it's just once
makeplayerfireportal:player:i makes a player shoot one of their portal
enableportalgun:player enable portal gun of player
disableportalgun:player disable portal gun of player
--]]
--[[ FES:
(--DOC)
TRIGGER whenboolis whenever a boolean is true #def #imp
CONDITION ifbool only if a boolean is true (can be inverted) #def #imp
ACTION dotobool set and/or flip a boolean (three modes of one action) #undef #unimp
]]--
function animation:init(path, name)
self.filepath = path
self.name = name
self.raw = love.filesystem.read(self.filepath)
self:decode(self.raw)
self.firstupdate = true
self.running = false
self.sleep = 0
self.enabled = true
end
function animation:decode(s)
self.triggers = {}
self.conditions = {}
self.actions = {}
local animationjson = JSON:decode(s)
for i, v in pairs(animationjson.triggers) do
self:addtrigger(v)
end
for i, v in pairs(animationjson.conditions) do
self:addcondition(v)
end
for i, v in pairs(animationjson.actions) do
self:addaction(v)
end
end
function animation:addtrigger(v)
table.insert(self.triggers, {unpack(v)})
if v[1] == "mapload" then
elseif v[1] == "timepassed" then
self.timer = 0
elseif v[1] == "playerx" then
elseif v[1] == "animationtrigger" then
if not animationtriggerfuncs[v[2] ] then
animationtriggerfuncs[v[2] ] = {}
end
table.insert(animationtriggerfuncs[v[2] ], self)
end
end
function animation:addcondition(v)
table.insert(self.conditions, {unpack(v)})
end
function animation:addaction(v)
table.insert(self.actions, {unpack(v)})
end
function animation:update(dt)
--check my triggers for triggering, yo
for i, v in pairs(self.triggers) do
if v[1] == "mapload" then
if self.firstupdate then
self:trigger()
end
elseif v[1] == "timepassed" then
self.timer = self.timer + dt
if self.timer >= tonumber(v[2]) and self.timer - dt < tonumber(v[2]) then
self:trigger()
end
elseif v[1] == "playerxgreater" then
local trig = false
for i = 1, players do
if objects["player"][i].x+objects["player"][i].width/2 > tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playerxless" then
local trig = false
for i = 1, players do
if objects["player"][i].x+objects["player"][i].width/2 < tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playerygreater" then
local trig = false
for i = 1, players do
if objects["player"][i].y+objects["player"][i].height/2 > tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "playeryless" then
local trig = false
for i = 1, players do
if objects["player"][i].y+objects["player"][i].height/2 < tonumber(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "whenboolis" then
if globoolSH(v[2],"check") then
self:trigger()
end
end
end
self.firstupdate = false
if self.running then
if self.sleep > 0 then
self.sleep = math.max(0, self.sleep - dt)
end
while self.sleep == 0 and self.currentaction <= #self.actions do
local v = self.actions[self.currentaction]
if v[1] == "disablecontrols" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].controlsenabled = false
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.controlsenabled = false
end
end
elseif v[1] == "enablecontrols" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].controlsenabled = true
end
else
local p = objects["player"][tonumber(string.sub(v[2], -1))]
if p then
p.controlsenabled = true
end
end
elseif v[1] == "sleep" then
self.sleep = tonumber(v[2])
elseif v[1] == "setcamerax" then
xscroll = tonumber(v[2])
elseif v[1] == "setcameray" then
yscroll = tonumber(v[2])
elseif v[1] == "pancameratox" then
autoscroll = false
cameraxpan(tonumber(v[2]), tonumber(v[3]))
elseif v[1] == "pancameratoy" then
autoscroll = false
cameraypan(tonumber(v[2]), tonumber(v[3]))
elseif v[1] == "disablescroll" then
autoscroll = false
elseif v[1] == "enablescroll" then
autoscroll = true
elseif v[1] == "disablexscroll" then
autoscrollx = false
elseif v[1] == "enablexscroll" then
autoscrollx = true
elseif v[1] == "disableyscroll" then
autoscrolly = false
elseif v[1] == "enableyscroll" then
autoscrolly = true
elseif v[1] == "setx" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].x = tonumber(v[3])
end
else
if objects["player"][tonumber(string.sub(v[3], -1))] then
objects["player"][tonumber(string.sub(v[3], -1))].x = tonumber(v[4])
end
end
elseif v[1] == "sety" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].y = tonumber(v[3])
end
else
if objects["player"][tonumber(string.sub(v[3], -1))] then
objects["player"][tonumber(string.sub(v[3], -1))].y = tonumber(v[4])
end
end
elseif v[1] == "playerwalk" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:animationwalk(v[3])
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:animationwalk(v[3])
end
end
elseif v[1] == "playeranimationstop" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:stopanimation()
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:stopanimation()
end
end
elseif v[1] == "disableanimation" then
self.enabled = false
elseif v[1] == "enableanimation" then
self.enabled = true
elseif v[1] == "playerjump" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:jump(true)
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:jump(true)
end
end
elseif v[1] == "playerstopjump" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:stopjump(true)
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:stopjump()
end
end
elseif v[1] == "dialogbox" then
createdialogbox(v[2], v[3])
elseif v[1] == "removedialogbox" then
dialogboxes = {}
elseif v[1] == "playmusic" then
love.audio.stop()
if v[2] then
if musicname then
music:stop(musicname)
end
musicname = v[2]
playmusic()
end
elseif v[1] == "screenshake" then
earthquake = tonumber(v[2]) or 1
elseif v[1] == "addcoins" then
collectcoin(nil, nil, tonumber(v[2]) or 1)
elseif v[1] == "addpoints" then
addpoints(tonumber(v[2]) or 1)
elseif v[1] == "changebackgroundcolor" then
love.graphics.setBackgroundColor(tonumber(v[2]) or 255, tonumber(v[3]) or 255, tonumber(v[4]) or 255)
elseif v[1] == "killplayer" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:die("script")
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:die("script")
end
end
elseif v[1] == "changetime" then
mariotime = (tonumber(v[2]) or 400)
elseif v[1] == "loadlevel" then
love.audio.stop()
marioworld = tonumber(v[2]) or marioworld
mariolevel = tonumber(v[3]) or mariolevel
mariosublevel = tonumber(v[4]) or mariosublevel
levelscreen_load("next")
elseif v[1] == "disableplayeraim" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disableaiming = true
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].disableaiming = true
end
end
elseif v[1] == "enableplayeraim" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].disableaiming = false
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].disableaiming = false
end
end
elseif v[1] == "closeportals" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i]:removeportals()
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))]:removeportals()
end
end
elseif v[1] == "makeplayerlook" then
local ang = math.mod(math.mod(tonumber(v[3]), 360)+360, 360)
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].pointingangle = math.rad(ang)-math.pi/2
end
else
if objects["player"][tonumber(string.sub(v[2], -1))] then
objects["player"][tonumber(string.sub(v[2], -1))].pointingangle = math.rad(ang)-math.pi/2
end
end
elseif v[1] == "makeplayerfireportal" then
if tonumber(v[3]) == 1 or tonumber(v[3]) == 2 then
if v[2] == "everyone" then
for i = 1, players do
local sourcex = objects["player"][i].x+6/16
local sourcey = objects["player"][i].y+6/16
local direction = objects["player"][i].pointingangle
shootportal(i, 1, sourcex, sourcey, direction)
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
local sourcex = objects["player"][i].x+6/16
local sourcey = objects["player"][i].y+6/16
local direction = objects["player"][i].pointingangle
shootportal(i, 1, sourcex, sourcey, direction)
end
end
end
elseif v[1] == "disableportalgun" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].portalgundisabled = true
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
objects["player"][i].portalgundisabled = true
end
end
elseif v[1] == "enableportalgun" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].portalgundisabled = false
end
else
local i = tonumber(string.sub(v[2], -1))
if objects["player"][i] then
objects["player"][i].portalgundisabled = false
end
end
elseif v[1] == "dotobool" then
globoolSH(v[2],v[3])
end
self.currentaction = self.currentaction + 1
end
if self.currentaction > #self.actions then
self.running = false
end
end
end
function animation:trigger()
if self.enabled then
--check conditions
local pass = true
for i, v in pairs(self.conditions) do
if v[1] == "noprevsublevel" then
if prevsublevel then
pass = false
break
end
elseif v[1] == "sublevelequals" then
print(mariosublevel)
if (v[2] == "main" and (tonumber(mariosublevel) ~= 0)) or (v[2] ~= "main" and tonumber(v[2]) ~= tonumber(mariosublevel)) then
pass = false
break
end
elseif v[1] == "levelequals" then
if tonumber(v[2]) ~= tonumber(mariolevel) then
pass = false
break
end
elseif v[1] == "worldequals" then
if tonumber(v[2]) ~= tonumber(marioworld) then
pass = false
break
end
elseif v[1] == "requirecoins" then
if mariocoincount < tonumber(v[2]) then
pass = false
break
end
elseif v[1] == "ifbool" then
if globoolSH(v[2], "check") ~= v[3] then
pass = false
break
end
end
end
if pass then
self.running = true
self.currentaction = 1
self.sleep = 0
end
end
end
function animation:draw()
end