-
Notifications
You must be signed in to change notification settings - Fork 26
/
game.lua
9240 lines (8328 loc) · 293 KB
/
game.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
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local queuespritebatchupdate = false
function game_load(suspended, deletesuspend)
scrollfactor = 0
scrollfactory = 0
scrollfactor2 = 0
scrollfactor2y = 0
love.graphics.setBackgroundColor(backgroundcolor[1])
backgroundrgbon = false
backgroundrgb = {0, 0, 0}
backgroundcolor[4] = backgroundrgb
scrollingstart = scrollingstartv --when the scrolling begins to set in (Both of these take the player who is the farthest on the left)
scrollingcomplete = scrollingcompletev --when the scrolling will be as fast as mario can run
scrollingleftstart = scrollingleftstartv --See above, but for scrolling left, and it takes the player on the right-estest.
scrollingleftcomplete = scrollingleftcompletev
superscroll = 100
if nofunallowed then
disablecheats()
end
--Daily Challenge
if suspended == "dailychallenge" then
suspended = false
dcplaying = true
disablecheats()
--[[for i = 1, players do
setcustomplayer("mario", i)
end]]
else
dcplaying = false
end
oldjoystick = {}
--LINK STUFF
mariocoincount = 0
marioscore = 0
--get mariolives and physics
mariolivecount = 3
currentphysics = 1
camerasetting = 1
dropshadow = false
realtime = false
continuesublevelmusic = false
nolowtime = false
nocoinlimit = false
alwaysdeletesuspend = false
setphysics(1)
if not dcplaying then
loadmappacksettings()
end
updatemappacksettings()
autoscroll = true
autoscrollx = true
autoscrolly = true
inputs = { "door", "groundlight", "wallindicator", "cubedispenser", "walltimer", "notgate", "laser", "lightbridge", "delayer", "funnel", "portal1", "portal2", "text", "geldispenser", "tiletool", "enemytool", "randomizer", "musicchanger", "rocketturret", "checkpoint", "emancipationgrill", "belt", "animationtrigger", "faithplate", "animatedtiletrigger", "orgate", "andgate", "rsflipflop", "kingbill", "platform", "collectable", "skewer", "energylauncher", "camerastop", "laserfields", "track", "animationtrigger", "snakeblock", "risingwater", "trackswitch" }
inputsi = {28, 29, 30, 43, 44, 45, 46, 47, 48, 67, 74, 84, 49, 50, 51, 52, 53, 54, 55, 36, 37, 38, 39, 186, 198, 197, 199, 61, 62, 63, 64, 65, 66, 71, 72, 73, 181, 182, 183, 201, 205, 206, 210, 194, 225, 226, 227, 229, 230, 231, 232, 100, 26, 27, 266, 271, 273, 274, 272, 105, 163, 248, 249, 18, 19, 259, 166, 167, 168, 169, 304, 309, 311, 306, 270, 317, 290, 285}
outputs = { "button", "laserdetector", "box", "pushbutton", "walltimer", "notgate", "energycatcher", "squarewave", "delayer", "regiontrigger", "randomizer", "tiletool", "orgate", "andgate", "rsflipflop", "flipblock", "doorsprite", "collectablelock", "collectable", "animationoutput" }
outputsi = {40, 56, 57, 58, 59, 20, 68, 69, 74, 84, 165, 170, 171, 172, 173, 185, 186, 200, 206, 201, 222, 267, 268, 273, 274, 272, 275, 163, 248, 249, 277, 276, 291}
--purpose of enemies table:
--carried by platforms and such
--killed by blocks below
--granted despawning immunity when mario goes through doors
--killed by rainboom
--deep copied by regiontrigger
enemies = { "goomba", "koopa", "hammerbro", "plant", "lakito", "bowser", "cheep", "squid", "flyingfish", "cheepwhite", "cheepred", "beetle", "spikey",
"sidestepper", "barrel", "icicle", "angrysun", "splunkin", "firebro", "fishbone", "drybones", "muncher", "bigbeetle", "meteor",
"boomerangbro", "ninji", "boo", "mole", "bigmole", "bomb", "bombhalf", "torpedoted", "parabeetle", "parabeetleright", "boomboom",
"pinksquid", "shell", "shyguy", "beetleshell", "spiketop", "pokey", "snowpokey", "fighterfly", "chainchomp", "rockywrench", "tinygoomba", "koopaling", "bowser3", "icebro",
"squidnanny", "goombashoe", "wiggler", "magikoopa", "spike", "spikeball", "plantcreeper"}
--aren't spawned when player at checkpoint
checkpointignoreenemies = { "goomba", "koopa", "hammerbro", "plant", "lakito", "bowser", "cheep", "squid", "flyingfish", "goombahalf", "koopahalf", "cheepwhite", "cheepred", "koopared", "kooparedhalf", "kooparedflying", "beetle", "beetlehalf", "spikey", "spikeyhalf", "downplant", "paragoomba", "sidestepper", "barrel", "icicle", "angrysun", "splunkin", "biggoomba", "firebro", "redplant", "reddownplant", "fishbone", "drybones", "muncher", "dryboneshalf", "bigbeetle", "meteor", "drygoomba", "dryplant", "drydownplant", "boomerangbro", "ninji", "boo", "mole", "bigmole", "bomb", "bombhalf", "fireplant", "downfireplant", "torpedoted", "parabeetle", "parabeetleright", "boomboom", "koopablue", "koopabluehalf", "pinksquid", "shell", "shyguy", "shyguyhalf", "beetleshell", "spiketop", "spiketophalf", "pokey", "snowpokey", "fighterfly", "chainchomp", "bighammerbro", "rockywrench", "tinygoomba", "koopaling", "bowser3", "icebro", "squidnanny", "goombashoe", "wiggler", "magikoopa", "spike", "spikeball", "plantcreeper"}
jumpitems = { "mushroom", "oneup", "poisonmush" , "threeup"}
marioworld = 1
mariolevel = 1
mariosublevel = 0
respawnsublevel = 0
checkpointsublevel = false
objects = nil
if suspended == true then
continuegame()
loadmappacksettings("suspended")
updatemappacksettings("suspended")
elseif suspended then
marioworld = suspended
end
if deletesuspend or alwaysdeletesuspend then
-- On starting a new game, remove the old save
love.filesystem.remove(savesfolder .. "/" .. mappack .. ".suspend")
end
--remove custom sprites
for i = smbtilecount+portaltilecount+1, #tilequads do
tilequads[i] = nil
end
for i = smbtilecount+portaltilecount+1, #rgblist do
rgblist[i] = nil
end
--add custom tiles
local bla = love.timer.getTime()
if not dcplaying and love.filesystem.getInfo(mappackfolder .. "/" .. mappack .. "/tiles.png") then
loadtiles("custom")
customtiles = true
else
customtiles = false
customtilecount = 0
end
print("Custom tileset loaded in: " .. round(love.timer.getTime()-bla, 5))
smbspritebatch = {}
portalspritebatch = {}
customspritebatch = {}
spritebatchX = {}
spritebatchY = {}
for i = 1, 2 do
smbspritebatch[i] = love.graphics.newSpriteBatch( smbtilesimg, maxtilespritebatchsprites )
portalspritebatch[i] = love.graphics.newSpriteBatch( portaltilesimg, maxtilespritebatchsprites )
if customtiles then
customspritebatch[i] = {}
for i2 = 1, #customtilesimg do
customspritebatch[i][i2] = love.graphics.newSpriteBatch( customtilesimg[i2], maxtilespritebatchsprites )
end
end
spritebatchX[i] = 0
spritebatchY[i] = 0
end
portaldotspritebatch = love.graphics.newSpriteBatch(portaldotimg, 1000, "dynamic" )
portalprojectilespritebatch = love.graphics.newSpriteBatch(portalprojectileparticleimg, 1000, "dynamic" )
custommusic = false
--hide android controls
if android and not androidHIDE then
local hide = true
for i = 1, players do
if controls[i] then
for j, w in pairs(controls[i]) do
if not (w[1] and w[1] == "joy") then
hide = false
break
end
end
end
end
if hide then
androidHIDE = true
end
end
--send chat ingame
if SERVER or CLIENT then
guielements = {}
guielements.chatentry = guielement:new("input", 4, 207, 43+7/8, sendchat, "", 43)
guielements.sendbutton = guielement:new("button", 359, 207, "send", sendchat, 1)
guielements.chatentry.active = false
guielements.sendbutton.active = false
chatentrytoggle = false
end
--FINALLY LOAD THE DAMN LEVEL
enemies_load()
if dcplaying then
levelscreen_load("dc")
else
levelscreen_load("initial")
end
end
function game_update(dt)
--------
--GAME--
--------
--pausemenu
if pausemenuopen and not (SERVER or CLIENT) then
--joystick navigation
local s1 = controls[1]["right"]
local s2 = controls[1]["left"]
local s3 = controls[1]["down"]
local s4 = controls[1]["up"]
if s1[1] == "joy" then
if checkkey(s1,1,"right") then
if not oldjoystick[1] then
game_keypressed("right")
oldjoystick[1] = true
end
else
oldjoystick[1] = false
end
end
if s2[1] == "joy" then
if checkkey(s2,1,"left") then
if not oldjoystick[2] then
game_keypressed("left")
oldjoystick[2] = true
end
else
oldjoystick[2] = false
end
end
if s3[1] == "joy" then
if checkkey(s3,1,"down") then
if not oldjoystick[3] then
game_keypressed("down")
oldjoystick[3] = true
end
else
oldjoystick[3] = false
end
end
if s4[1] == "joy" then
if checkkey(s4,1,"up") then
if not oldjoystick[4] then
game_keypressed("up")
oldjoystick[4] = true
end
else
oldjoystick[4] = false
end
end
return
end
--animationS
animationsystem_update(dt)
--earthquake reset
if earthquake > 0 then
earthquake = math.max(0, earthquake-dt*earthquake*2-0.001)
sunrot = sunrot + dt
end
--animate animated tiles because I say so
for i = 1, #animatedtiles do
animatedtiles[i]:update(dt)
end
for i = 1, #animatedtimerlist do
animatedtimerlist[i]:update(dt)
end
updatecustombackgrounds(dt)
--coinanimation
coinanimation = coinanimation + dt*6.75
while coinanimation >= 6 do
coinanimation = coinanimation - 5
end
coinframe = math.max(1, math.floor(coinanimation))
flaganimation = ((flaganimation-1 + dt*8)%4)+1
--SCROLLING SCORES
local delete
for i, v in pairs(scrollingscores) do
if scrollingscores[i]:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(scrollingscores, v) --remove
end
end
--If everyone's dead, just update the players and coinblock timer.
if everyonedead then
for i, v in pairs(objects["player"]) do
v:update(dt)
end
return
end
--check if updates are blocked for whatever reason
if noupdate then
for i, v in pairs(objects["checkpointflag"]) do
v:update(dt)
end
for i, v in pairs(objects["player"]) do
v:update(dt)
end
return
end
--timer
if editormode == false then
--get if any player has their controls disabled
local notime = false
for i = 1, players do
if (objects["player"][i].controlsenabled == false and objects["player"][i].dead == false and objects["player"][i].groundfreeze == false) then
notime = true
end
end
if (notime == false or breakoutmode) and infinitetime == false and mariotime ~= 0 then
if realtime then --mario maker time
mariotime = mariotime - dt --mario maker purists rejoice
else
mariotime = mariotime - 2.5*dt
end
if queuelowtime then
queuelowtime = queuelowtime - 2.5*dt
end
if mariotime > 0 and mariotime + 2.5*dt >= 99 and mariotime < 99 and (not dcplaying) and (not levelfinished) and not nolowtime then
startlowtime()
end
if queuelowtime and queuelowtime < 0 and (not levelfinished) then
local star = false
for i = 1, players do
if objects["player"][i].starred and not objects["player"][i].size == 8 then
star = true
end
end
if pbuttonsound:isPlaying() then
pbuttonsound:setVolume(1)
else
if not star then
playmusic()
else
music:play("starmusic")
end
end
queuelowtime = false
end
if mariotime <= 0 then
mariotime = 0
for i, v in pairs(objects["player"]) do
v:die("time")
end
end
end
end
--Portaldots
portaldotstimer = portaldotstimer + dt
while portaldotstimer > portaldotstime do
portaldotstimer = portaldotstimer - portaldotstime
end
--portalgundelay
for i = 1, players do
if portaldelay[i] > 0 then
portaldelay[i] = math.max(0, portaldelay[i] - dt/speed)
end
end
--coinblockanimation
local delete
for i, v in pairs(coinblockanimations) do
if coinblockanimations[i]:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(coinblockanimations, v) --remove
end
end
--nothing to see here
local delete
for i, v in pairs(rainbooms) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(rainbooms, v) --remove
end
end
--userects
local delete
for i, v in pairs(userects) do
if v.delete == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(userects, v) --remove
end
end
--blockbounce
local delete
for i, v in pairs(blockbounce) do
if v.timer < 0 then
if v.timer > -blockbouncetime then
v.timer = v.timer - dt
if v.timer < -blockbouncetime then
v.timer = -blockbouncetime
if v.content then
item(v.content, v.x, v.y, v.content2)
end
if not delete then delete = {} end
table.insert(delete, i)
end
end
else
if v.timer < blockbouncetime then
v.timer = v.timer + dt
if v.timer > blockbouncetime then
v.timer = blockbouncetime
if v.content then
item(v.content, v.x, v.y, v.content2)
end
if not delete then delete = {} end
table.insert(delete, i)
end
end
end
end
if delete then
for i, v in pairs(delete) do
blockbounce[v] = nil
end
if #delete >= 1 then
generatespritebatch()
end
end
--coinblocktimer things
for i, v in pairs(coinblocktimers) do
if v[3] > 0 then
v[3] = v[3] - dt
end
end
--blockdebris
local delete
for i, v in pairs(blockdebristable) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(blockdebristable, v) --remove
end
end
--gelcannon
if not editormode then
if objects["player"][mouseowner] and (playertype == "gelcannon" or objects["player"][mouseowner].portals == "gel") and objects["player"][mouseowner].controlsenabled then
if gelcannontimer > 0 then
gelcannontimer = gelcannontimer - dt
if gelcannontimer < 0 then
gelcannontimer = 0
end
else
if love.mouse.isDown("l") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(1)
elseif love.mouse.isDown("r") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(2)
elseif love.mouse.isDown("m") or love.mouse.isDown("wd") or love.mouse.isDown("wu") or love.mouse.isDown("x1") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(4)
elseif love.mouse.isDown("x2") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(3)
end
end
end
end
--make lights have a slight wave
if lightsout then
lightsoutwave = (lightsoutwave + dt)%0.2
end
--dialog boxes
for i, v in pairs(dialogboxes) do
v:update(dt)
end
--seesaws
for i, v in pairs(seesaws) do
v:update(dt)
end
--platformspawners
for i, v in pairs(platformspawners) do
v:update(dt)
end
--Bubbles
local delete
for i, v in pairs(bubbles) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(bubbles, v) --remove
end
end
--Poofs
local delete
for i, v in pairs(poofs) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(poofs, v) --remove
end
end
--Miniblocks
local delete
for i, v in pairs(miniblocks) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(miniblocks, v) --remove
end
end
--Emancipation Fizzle
local delete
for i, v in pairs(emancipationfizzles) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(emancipationfizzles, v) --remove
end
end
--Emancipation Animations
local delete
for i, v in pairs(emancipateanimations) do
if v:update(dt) == true then
if not delete then delete = {} end
table.insert(delete, i)
end
end
if delete then
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(emancipateanimations, v) --remove
end
end
--Fireworks
local delete = {}
for i, v in pairs(fireworks) do
if v:update(dt) == true then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(fireworks, v) --remove
end
--EMANCIPATION GRILLS
local delete = {}
for i, v in pairs(emancipationgrills) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(emancipationgrills, v)
end
--LASER FIELDS
local delete = {}
for i, v in pairs(laserfields) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(laserfields, v)
end
--BULLET BILL LAUNCHERS
local delete = {}
for i, v in pairs(rocketlaunchers) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(rocketlaunchers, v)
end
--BIG BILL LAUNCHERS
local delete = {}
for i, v in pairs(bigbilllaunchers) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(bigbilllaunchers, v)
end
--KING BILL LAUNCHERS
local delete = {}
for i, v in pairs(kingbilllaunchers) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(kingbilllaunchers, v)
end
--CANNON LAUNCHERS
local delete = {}
for i, v in pairs(cannonballlaunchers) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(cannonballlaunchers, v)
end
--item animations
local delete = {}
for i, v in pairs(itemanimations) do
if v:update(dt) or v.instantdelete then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(itemanimations, v)
end
--snake blocks
local delete = {}
for i, v in pairs(snakeblocks) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(snakeblocks, v)
end
--UPDATE OBJECTS
local delete
for i, v in kpairs(objects, objectskeys) do
if i ~= "tile" and i ~= "portalwall" and i ~= "screenboundary" and i ~= "coin" and i ~= "risingwater" and i ~= "clearpipesegment" and i ~= "tracksegment" and i ~= "funnel" and i ~= "clearpipe" then
delete = nil
for j, w in pairs(v) do
if dropshadow and w.shot and w.rotation then
if not w.dropshadowrotation then
w.dropshadowrotation = w.rotation
end
w.dropshadowrotation = w.dropshadowrotation + w.speedx*2*dt
w.rotation = w.dropshadowrotation
end
if w.instantdelete or (w.update and w:update(dt)) then
w.delete = true
if not delete then delete = {} end
table.insert(delete, j)
elseif w.autodelete then
if (((w.x < xscroll - width) or (w.x > xscroll + width*4)) and not w.horautodeleteimmunity) or w.y > mapheight+1 or math.abs(w.y-yscroll) > height*5 then
w.delete = true
if w.autodeleted then
w:autodeleted()
end
if not delete then delete = {} end
table.insert(delete,j)
end
elseif w.extremeautodelete then
if w.x > mapwidth+(w.extremeautodeletedist or 3) or w.x+w.width < -(w.extremeautodeletedist or 3) or w.y > mapheight+(w.extremeautodeletedist or 3) then
w.delete = true
if w.autodeleted then
w:autodeleted()
end
if not delete then delete = {} end
table.insert(delete,j)
end
end
if stoptestinglevelsafe then
--stop testing level without crashing
--when an entity makes you go to a different level (glados)
stoptestinglevelsafe = nil
return
end
end
if delete and #delete > 0 then
table.sort(delete, function(a,b) return a>b end)
for j, w in pairs(delete) do
table.remove(v, w)
end
end
end
end
--risingwater
for i, v in pairs(objects["risingwater"]) do
v:update(dt)
end
--funnel
for i, v in pairs(objects["funnel"]) do
v:update(dt)
end
--tracks
for i, v in pairs(tracks) do
v:update(dt)
end
--clear pipes
local delete = {}
for i, v in pairs(clearpipes) do
if v:update(dt) then
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(clearpipes, v)
end
--player custom enemy riding
for i, v in pairs(objects["player"]) do
if v.fireenemyride then
local obj = v.fireenemyride
if obj.delete then
v.fireenemyride = nil
v.fireenemyoffsetx = nil
v.fireenemyoffsety = nil
v.animationstate = "jumping"
v.active = true
v.speedx = obj.speedx or 0
v.speedy = obj.speedy or 0
v.fireenemydrawable = nil
v.fireenemyanim = false
else
if obj.x and obj.y then
v.x = obj.x + (v.fireenemyoffsetx or 0)
v.y = obj.y + (v.fireenemyoffsety or 0)
if v.ducking then
if v.fireenemyduckingoffsetx then
v.x = v.x + (v.fireenemyduckingoffsetx or 0)
end
if v.fireenemyduckingoffsety then
v.y = v.y + (v.fireenemyduckingoffsety or 0)
end
end
v.active = v.fireenemyactive
if v.active then
v.speedx = obj.speedx or 0
v.speedy = obj.speedy or 0
v.falling = obj.falling or true
end
if v.fireenemycopyquadi then
v.fireenemyquadi = obj.quadi
end
end
end
end
end
--spawn animations
local delete = {}
for i, v in pairs(spawnanimations) do
if v:update(dt) then
v.delete = true
table.insert(delete, i)
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(spawnanimations, v)
end
--SCROLLING
--HORIZONTAL
local oldscroll = splitxscroll[1]
if autoscroll and autoscrollx ~= false and not minimapdragging then
local splitwidth = width/#splitscreen
for split = 1, #splitscreen do
local oldscroll = splitxscroll[split]
--scrolling
--LEFT
local i = 1
while i <= players and objects["player"][i].dead do
i = i + 1
end
local fastestplayer = objects["player"][i]
if fastestplayer then
if not CLIENT and not SERVER then
for i = 1, players do
if not objects["player"][i].dead and objects["player"][i].x > fastestplayer.x then
fastestplayer = objects["player"][i]
end
end
end
local oldscroll = splitxscroll[split]
--LEFT
if (not (autoscrollingx and not editormode)) and (camerasetting ~= 3 or editormode) then
if fastestplayer.x < splitxscroll[split] + scrollingleftstart*screenzoom2 and splitxscroll[split] > 0 then
if fastestplayer.x < splitxscroll[split] + scrollingleftstart*screenzoom2 and fastestplayer.speedx < 0 then
if fastestplayer.speedx < -scrollrate then
splitxscroll[split] = splitxscroll[split] - scrollrate*dt
else
splitxscroll[split] = splitxscroll[split] + fastestplayer.speedx*dt
end
end
if fastestplayer.x < splitxscroll[split] + scrollingleftcomplete*screenzoom2 then
splitxscroll[split] = splitxscroll[split] - scrollrate*dt
if fastestplayer.x > splitxscroll[split] + scrollingleftcomplete*screenzoom2 then
splitxscroll[split] = fastestplayer.x - scrollingleftcomplete*screenzoom2
end
end
end
end
if autoscrollingx and not editormode then
splitxscroll[split] = math.max(0, math.min(mapwidth-width*screenzoom2, splitxscroll[split] + autoscrollingx*dt))
end
--RIGHT
if not (autoscrollingx and not editormode) then
if fastestplayer.x > splitxscroll[split] + width*screenzoom2 - scrollingstart*screenzoom2 and splitxscroll[split] < mapwidth - width*screenzoom2 then
if fastestplayer.x > splitxscroll[split] + width*screenzoom2 - scrollingstart*screenzoom2 and fastestplayer.speedx > 0.3 then
if fastestplayer.speedx > scrollrate then
splitxscroll[split] = splitxscroll[split] + scrollrate*dt
else
splitxscroll[split] = splitxscroll[split] + fastestplayer.speedx*dt
end
end
if fastestplayer.x > splitxscroll[split] + width*screenzoom2 - scrollingcomplete*screenzoom2 then
splitxscroll[split] = splitxscroll[split] + scrollrate*dt
if splitxscroll[split] > fastestplayer.x - (width*screenzoom2 - scrollingcomplete*screenzoom2) then
splitxscroll[split] = fastestplayer.x - (width*screenzoom2 - scrollingcomplete*screenzoom2)
end
end
end
if camerasetting == 3 then
objects["screenboundary"]["left"].x = xscroll
end
end
--just force that shit
if not levelfinished and not (autoscrollingx and not editormode) then
if fastestplayer.x > splitxscroll[split] + width*screenzoom2 - scrollingcomplete*screenzoom2 then
splitxscroll[split] = splitxscroll[split] + superscroll*dt
if fastestplayer.x < splitxscroll[split] + width*screenzoom2 - scrollingcomplete*screenzoom2 then
splitxscroll[split] = fastestplayer.x - width*screenzoom2 + scrollingcomplete*screenzoom2
end
elseif fastestplayer.x < splitxscroll[split] + scrollingleftcomplete*screenzoom2 and (camerasetting ~= 3 or editormode) then
splitxscroll[split] = splitxscroll[split] - superscroll*dt
if fastestplayer.x > splitxscroll[split] + scrollingleftcomplete*screenzoom2 then
splitxscroll[split] = fastestplayer.x - scrollingleftcomplete*screenzoom2
end
end
end
--CLAMP
if splitxscroll[split] > mapwidth-width then
splitxscroll[split] = math.max(0, mapwidth-width)
hitrightside()
end
if (axex and splitxscroll[split] > axex-width and axex >= width) then
splitxscroll[split] = axex-width
hitrightside()
end
if splitxscroll[split] < 0 then
splitxscroll[split] = 0
end
end
end
end
--VERTICAL SCROLLING
local oldscrolly = splityscroll[1]
if autoscroll and autoscrolly ~= false and not minimapdragging then
for split = 1, #splitscreen do
local fastestplayer = 1
while fastestplayer <= players and objects["player"][fastestplayer].dead do
fastestplayer = fastestplayer + 1
end
if not CLIENT and not SERVER and objects["player"][fastestplayer] then
if mapwidth <= width then
for i = 1, players do
if not objects["player"][i].dead and math.abs(starty-objects["player"][i].y) > math.abs(starty-objects["player"][fastestplayer].y) then
fastestplayer = i
end
end
else
for i = 1, players do
if not objects["player"][i].dead and objects["player"][i].x > objects["player"][fastestplayer].x then
fastestplayer = i
end
end
end
end
if mapheight > 15*screenzoom2 and objects["player"][fastestplayer] then
if not (autoscrollingy and not editormode) then
local px, py = objects["player"][fastestplayer].x, objects["player"][fastestplayer].y
if objects["player"][fastestplayer].height > 2 then
py = objects["player"][fastestplayer].y+objects["player"][fastestplayer].height/2
end
local pspeed = objects["player"][1].speedy
if objects["player"][fastestplayer].oldy and pspeed == 0 and math.abs(objects["player"][fastestplayer].y-objects["player"][fastestplayer].oldy) < 3 then
pspeed = (objects["player"][fastestplayer].y-objects["player"][fastestplayer].oldy)/dt
end
objects["player"][fastestplayer].oldy = objects["player"][fastestplayer].y
local sx, sy = px-xscroll, py-yscroll--position on screen
yscrolltarget = yscrolltarget or splityscroll[split]