-
Notifications
You must be signed in to change notification settings - Fork 17
/
animation.lua
548 lines (499 loc) · 17.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
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
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
TRIGGER whenintis whenever an integer is {>,<,=} a value
CONDITION ifbool only if a boolean is true (can be inverted) #def #imp
CONDITION ifint if an integer is {>,<,+} a value
ACTION dotobool set and/or flip a boolean (three modes of one action) #def #imp
ACTION dotoint add, subtact, or set a boolean
ACTION dotoallbool do to ALL booleans with prefix ___
ACTION dotoallint do to ALL integers with prefix ___
]]--
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 >= self:decodenuminput(v[2]) and self.timer - dt < self:decodenuminput(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 > self:decodenuminput(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 < self:decodenuminput(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 > self:decodenuminput(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 < self:decodenuminput(v[2]) then
trig = true
end
end
if trig then
self:trigger()
end
elseif v[1] == "whenboolis" then
if tostring(globoolSH(v[2],"check")) == v[3] then
self:trigger()
end
elseif v[1] == "whenintis" then
if globintCH(v[2],v[3],self:decodenuminput(v[4])) 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"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))]
if p then
p.controlsenabled = true
end
end
elseif v[1] == "sleep" then
self.sleep = self:decodenuminput(v[2])
elseif v[1] == "setcamerax" then
xscroll = self:decodenuminput(v[2])
elseif v[1] == "setcameray" then
yscroll = self:decodenuminput(v[2])
elseif v[1] == "pancameratox" then
autoscroll = false
cameraxpan(self:decodenuminput(v[2]), self:decodenuminput(v[3]))
elseif v[1] == "pancameratoy" then
autoscroll = false
cameraypan(self:decodenuminput(v[2]), self:decodenuminput(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 = self:decodenuminput(v[3])
end
else
if objects["player"][self:decodenuminput(string.sub(v[3], -1))] then
objects["player"][self:decodenuminput(string.sub(v[3], -1))].x = self:decodenuminput(v[4])
end
end
elseif v[1] == "sety" then
if v[2] == "everyone" then
for i = 1, players do
objects["player"][i].y = self:decodenuminput(v[3])
end
else
if objects["player"][self:decodenuminput(string.sub(v[3], -1))] then
objects["player"][self:decodenuminput(string.sub(v[3], -1))].y = self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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] == "playsound" then
playsound(v[2])
elseif v[1] == "screenshake" then
earthquake = self:decodenuminput(v[2]) or 1
elseif v[1] == "addcoins" then
collectcoin(nil, nil, self:decodenuminput(v[2]) or 1)
elseif v[1] == "addpoints" then
addpoints(self:decodenuminput(v[2]) or 1)
elseif v[1] == "changebackgroundcolor" then
love.graphics.setBackgroundColor(self:decodenuminput(v[2]) / 255 or 1, self:decodenuminput(v[3]) / 255 or 1, self:decodenuminput(v[4]) / 255 or 1)
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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(string.sub(v[2], -1))]:die("script")
end
end
elseif v[1] == "changetime" then
mariotime = (self:decodenuminput(v[2]) or 400)
elseif v[1] == "loadlevel" then
love.audio.stop()
marioworld = self:decodenuminput(v[2]) or marioworld
mariolevel = self:decodenuminput(v[3]) or mariolevel
mariosublevel = self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(string.sub(v[2], -1))]:removeportals()
end
end
elseif v[1] == "makeplayerlook" then
local ang = math.mod(math.mod(self:decodenuminput(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"][self:decodenuminput(string.sub(v[2], -1))] then
objects["player"][self:decodenuminput(string.sub(v[2], -1))].pointingangle = math.rad(ang)-math.pi/2
end
end
elseif v[1] == "makeplayerfireportal" then
if self:decodenuminput(v[3]) == 1 or self:decodenuminput(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 = self:decodenuminput(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 = self:decodenuminput(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 = self:decodenuminput(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])
elseif v[1] == "dotoint" then
globintSH(v[2],v[3],self:decodenuminput(v[4]))
elseif v[1] == "dotoallbool" then
for i, n in pairs(globools) do
if string.sub(i, 1, string.len(v[2])) == v[2] then
globoolSH(i,v[3])
end
end
elseif v[1] == "dotoallint" then
for i, n in pairs(globints) do
if string.sub(i, 1, string.len(v[2])) == v[2] then
globintSH(i,v[3],self:decodenuminput(v[4]))
end
end
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 (self:decodenuminput(mariosublevel) ~= 0)) or (v[2] ~= "main" and self:decodenuminput(v[2]) ~= self:decodenuminput(mariosublevel)) then
pass = false
break
end
elseif v[1] == "levelequals" then
if self:decodenuminput(v[2]) ~= self:decodenuminput(mariolevel) then
pass = false
break
end
elseif v[1] == "worldequals" then
if self:decodenuminput(v[2]) ~= self:decodenuminput(marioworld) then
pass = false
break
end
elseif v[1] == "requirecoins" then
if mariocoincount < self:decodenuminput(v[2]) then
pass = false
break
end
elseif v[1] == "ifbool" then
if (globoolSH(v[2], "check")) ~= (v[3] == "true") then
pass = false
break
end
elseif v[1] == "ifint" then
if not globintCH(v[2], v[3], self:decodenuminput(v[4])) 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
function animation:decodenuminput(x)
if tonumber(x) then
return tonumber(x)
elseif string.sub(x,1,2) == "g:" then
return _G[string.sub(x,3)]
else
return globints[x] or 0
end
end