-
Notifications
You must be signed in to change notification settings - Fork 109
/
Copy pathgame.lua
4294 lines (3725 loc) · 122 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
function game_load(suspended)
scrollfactor = 0
backgroundcolor = {}
backgroundcolor[1] = {92/255, 148/255, 252/255}
backgroundcolor[2] = {0, 0, 0}
backgroundcolor[3] = {32/255, 56/255, 236/255}
love.graphics.setBackgroundColor(backgroundcolor[1])
scrollingstart = 12 --when the scrolling begins to set in (Both of these take the player who is the farthest on the left)
scrollingcomplete = 10 --when the scrolling will be as fast as mario can run
scrollingleftstart = 6 --See above, but for scrolling left, and it takes the player on the right-estest.
scrollingleftcomplete = 4
superscroll = 100
--LINK STUFF
mariocoincount = 0
marioscore = 0
--get mariolives
mariolivecount = 3
if love.filesystem.getInfo("mappacks/" .. mappack .. "/settings.txt") then
local s = love.filesystem.read( "mappacks/" .. mappack .. "/settings.txt" )
local s1 = s:split("\n")
for j = 1, #s1 do
local s2 = s1[j]:split("=")
if s2[1] == "lives" then
mariolivecount = tonumber(s2[2])
end
end
end
if mariolivecount == 0 then
mariolivecount = false
end
mariolives = {}
for i = 1, players do
mariolives[i] = mariolivecount
end
mariosizes = {}
for i = 1, players do
mariosizes[i] = 1
end
autoscroll = true
inputs = { "door", "groundlight", "wallindicator", "cubedispenser", "walltimer", "notgate", "laser", "lightbridge"}
inputsi = {28, 29, 30, 43, 44, 45, 46, 47, 48, 67, 74, 84, 52, 53, 54, 55, 36, 37, 38, 39}
outputs = { "button", "laserdetector", "box", "pushbutton", "walltimer", "notgate"}
outputsi = {40, 56, 57, 58, 59, 20, 68, 69, 74, 84}
enemies = { "goomba", "koopa", "hammerbro", "plant", "lakito", "bowser", "cheep", "squid", "flyingfish", "goombahalf", "koopahalf", "cheepwhite", "cheepred", "koopared", "kooparedhalf", "koopa", "kooparedflying", "beetle", "beetlehalf", "spikey", "spikeyhalf"}
jumpitems = { "mushroom", "oneup" }
marioworld = 1
mariolevel = 1
mariosublevel = 0
respawnsublevel = 0
objects = nil
if suspended == true then
continuegame()
elseif suspended then
marioworld = suspended
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 love.filesystem.getInfo("mappacks/" .. mappack .. "/tiles.png") then
customtiles = true
customtilesimg = love.graphics.newImage("mappacks/" .. mappack .. "/tiles.png")
local imgwidth, imgheight = customtilesimg:getWidth(), customtilesimg:getHeight()
local width = math.floor(imgwidth/17)
local height = math.floor(imgheight/17)
local imgdata = love.image.newImageData("mappacks/" .. mappack .. "/tiles.png")
for y = 1, height do
for x = 1, width do
table.insert(tilequads, quad:new(customtilesimg, imgdata, x, y, imgwidth, imgheight))
local r, g, b = getaveragecolor(imgdata, x, y)
table.insert(rgblist, {r, g, b})
end
end
customtilecount = width*height
else
customtiles = false
customtilecount = 0
end
print("Custom tileset loaded in: " .. round(love.timer.getTime()-bla, 5))
smbspritebatch = {}
portalspritebatch = {}
customspritebatch = {}
spritebatchX = {}
for i = 1, players do
smbspritebatch[i] = love.graphics.newSpriteBatch( smbtilesimg, 1000 )
portalspritebatch[i] = love.graphics.newSpriteBatch( portaltilesimg, 1000 )
if customtiles then
customspritebatch[i] = love.graphics.newSpriteBatch( customtilesimg, 1000 )
end
spritebatchX[i] = 0
end
custommusic = false
if love.filesystem.getInfo("mappacks/" .. mappack .. "/music.ogg") then
custommusic = "mappacks/" .. mappack .. "/music.ogg"
music:load(custommusic)
elseif love.filesystem.getInfo("mappacks/" .. mappack .. "/music.mp3") then
custommusic = "mappacks/" .. mappack .. "/music.mp3"
music:load(custommusic)
end
print(custommusic)
--FINALLY LOAD THE DAMN LEVEL
levelscreen_load("initial")
end
function game_update(dt)
--------
--GAME--
--------
--earthquake reset
if earthquake > 0 then
earthquake = math.max(0, earthquake-dt*earthquake*2-0.001)
sunrot = sunrot + dt
end
--pausemenu
if pausemenuopen then
return
end
--coinanimation
coinanimation = coinanimation + dt*6.75
while coinanimation >= 6 do
coinanimation = coinanimation - 5
end
if math.floor(coinanimation) == 4 then
coinframe = 2
elseif math.floor(coinanimation) == 5 then
coinframe = 1
else
coinframe = math.max(1, math.floor(coinanimation))
end
--SCROLLING SCORES
local delete = {}
for i, v in pairs(scrollingscores) do
if scrollingscores[i]: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(scrollingscores, v) --remove
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
--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) then
notime = true
end
end
if notime == false and infinitetime == false and mariotime ~= 0 then
mariotime = mariotime - 2.5*dt
if mariotime > 0 and mariotime + 2.5*dt >= 99 and mariotime < 99 then
love.audio.stop()
playsound(lowtime)
end
if mariotime > 0 and mariotime + 2.5*dt >= 99-7.5 and mariotime < 99-7.5 then
local star = false
for i = 1, players do
if objects["player"][i].starred then
star = true
end
end
if not star then
playmusic()
else
music:play("starmusic")
end
end
if mariotime <= 0 then
mariotime = 0
for i, v in pairs(objects["player"]) do
v:die("time")
end
end
end
end
--check if updates are blocked for whatever reason
if noupdate then
for i, v in pairs(objects["player"]) do
v:update(dt)
end
return
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
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(coinblockanimations, v) --remove
end
--nothing to see here
local delete = {}
for i, v in pairs(rainbooms) 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(rainbooms, v) --remove
end
--userects
local delete = {}
for i, v in pairs(userects) do
if v.delete == 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(userects, v) --remove
end
--blockbounce
local delete = {}
for i, v in pairs(blockbouncetimer) do
if blockbouncetimer[i] < blockbouncetime then
blockbouncetimer[i] = blockbouncetimer[i] + dt
if blockbouncetimer[i] > blockbouncetime then
blockbouncetimer[i] = blockbouncetime
if blockbouncecontent then
item(blockbouncecontent[i], blockbouncex[i], blockbouncey[i], blockbouncecontent2[i])
end
table.insert(delete, i)
end
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.remove(blockbouncetimer, v)
table.remove(blockbouncex, v)
table.remove(blockbouncey, v)
table.remove(blockbouncecontent, v)
table.remove(blockbouncecontent2, v)
end
if #delete >= 1 then
generatespritebatch()
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
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(blockdebristable, v) --remove
end
--gelcannon
if objects["player"][mouseowner] and playertype == "gelcannon" 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(1) then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(1)
elseif love.mouse.isDown(2) then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(2)
end
end
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
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(bubbles, v) --remove
end
--Miniblocks
local delete = {}
for i, v in pairs(miniblocks) 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(miniblocks, v) --remove
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
--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
--UPDATE OBJECTS
for i, v in pairs(objects) do
if i ~= "tile" and i ~= "portalwall" and i ~= "screenboundary" then
delete = {}
for j, w in pairs(v) do
if w.update and w:update(dt) then
table.insert(delete, j)
elseif w.autodelete then
if w.x < xscroll - width or w.y > 16 then
table.insert(delete,j)
end
end
end
if #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
local oldscroll = splitxscroll[1]
if autoscroll and minimapdragging == false 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
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
local oldscroll = splitxscroll[split]
if fastestplayer.x < splitxscroll[split] + scrollingleftstart and splitxscroll[split] > 0 then
if fastestplayer.x < splitxscroll[split] + scrollingleftstart 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 then
if fastestplayer.x > splitxscroll[split] + scrollingleftcomplete - 1/16 then
splitxscroll[split] = splitxscroll[split] - scrollrate*dt
else
splitxscroll[split] = splitxscroll[split] - superscrollrate*dt
end
end
if splitxscroll[split] < 0 then
splitxscroll[split] = 0
end
end
--RIGHT
if fastestplayer.x > splitxscroll[split] + width - scrollingstart and splitxscroll[split] < mapwidth - width then
if fastestplayer.x > splitxscroll[split] + width - scrollingstart 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 - scrollingcomplete then
if fastestplayer.x > splitxscroll[split] + width - scrollingcomplete then
splitxscroll[split] = splitxscroll[split] + scrollrate*dt
if splitxscroll[split] > fastestplayer.x - (width - scrollingcomplete) then
splitxscroll[split] = fastestplayer.x - (width - scrollingcomplete)
end
else
splitxscroll[split] = fastestplayer.x - (width - scrollingcomplete)
end
end
end
--just force that shit
if not levelfinished then
if fastestplayer.x > splitxscroll[split] + width - scrollingcomplete then
splitxscroll[split] = splitxscroll[split] + superscroll*dt
if fastestplayer.x < splitxscroll[split] + width - scrollingcomplete then
splitxscroll[split] = fastestplayer.x - width + scrollingcomplete
end
--splitxscroll[split] = fastestplayer.x + width - scrollingcomplete - width
end
end
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
end
end
end
if players == 2 then
--updatesplitscreen()
end
--SPRITEBATCH UPDATE and CASTLEREPEATS
if math.floor(splitxscroll[1]) ~= spritebatchX[1] then
if not editormode then
for currentx = lastrepeat+1, math.floor(splitxscroll[1])+2 do
lastrepeat = math.floor(currentx)
--castlerepeat?
--get mazei
local mazei = 0
for j = 1, #mazeends do
if mazeends[j] < currentx+width then
mazei = j
end
end
--check if maze was solved!
for i = 1, players do
if objects["player"][i].mazevar == mazegates[mazei] then
local actualmaze = 0
for j = 1, #mazestarts do
if objects["player"][i].x > mazestarts[j] then
actualmaze = j
end
end
mazesolved[actualmaze] = true
for j = 1, players do
objects["player"][j].mazevar = 0
end
break
end
end
if not mazesolved[mazei] or mazeinprogress then --get if inside maze
if not mazesolved[mazei] then
mazeinprogress = true
end
local x = math.ceil(currentx)+width
if repeatX == 0 then
repeatX = mazestarts[mazei]
end
table.insert(map, x, {{1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}, {1}})
for y = 1, 15 do
for j = 1, #map[repeatX][y] do
map[x][y][j] = map[repeatX][y][j]
end
map[x][y]["gels"] = {}
for cox = mapwidth, x, -1 do
--move objects
if objects["tile"][cox .. "-" .. y] then
objects["tile"][cox + 1 .. "-" .. y] = tile:new(cox, y-1, 1, 1, true)
objects["tile"][cox .. "-" .. y] = nil
end
end
--create object for block
if tilequads[map[repeatX][y][1]].collision == true then
objects["tile"][x .. "-" .. y] = tile:new(x-1, y-1, 1, 1, true)
end
end
mapwidth = mapwidth + 1
repeatX = repeatX + 1
if flagx then
flagx = flagx + 1
flagimgx = flagimgx + 1
objects["screenboundary"]["flag"].x = objects["screenboundary"]["flag"].x + 1
end
if axex then
axex = axex + 1
objects["screenboundary"]["axe"].x = objects["screenboundary"]["axe"].x + 1
end
if firestartx then
firestartx = firestartx + 1
end
objects["screenboundary"]["right"].x = objects["screenboundary"]["right"].x + 1
--move mazestarts and ends
for i = 1, #mazestarts do
mazestarts[i] = mazestarts[i]+1
mazeends[i] = mazeends[i]+1
end
--check for endblock
local x = math.ceil(currentx)+width
for y = 1, 15 do
if map[x][y][2] and entityquads[map[x][y][2]].t == "mazeend" then
if mazesolved[mazei] then
repeatX = mazestarts[mazei+1]
end
mazeinprogress = false
end
end
--reset thingie
local x = math.ceil(currentx)+width-1
for y = 1, 15 do
if map[x][y][2] and entityquads[map[x][y][2]].t == "mazeend" then
for j = 1, players do
objects["player"][j].mazevar = 0
end
end
end
end
end
end
generatespritebatch()
spritebatchX[1] = math.floor(splitxscroll[1])
if editormode == false and splitxscroll[1] < mapwidth-width then
for x = math.ceil(oldscroll)+width+1, math.floor(splitxscroll[1])+width+1 do
for y = 1, 15 do
spawnenemy(x, y)
end
if goombaattack then
local randomtable = {}
for y = 1, 15 do
table.insert(randomtable, y)
end
while #randomtable > 0 do
local rand = math.random(#randomtable)
if tilequads[map[x][randomtable[rand]][1]].collision then
table.remove(randomtable, rand)
else
table.insert(objects["goomba"], goomba:new(x-.5, math.random(13)))
break
end
end
end
end
end
end
--portal animation
portalanimationtimer = portalanimationtimer + dt
while portalanimationtimer > portalanimationdelay do
portalanimationtimer = 0
portalanimation = portalanimation + 1
if portalanimation > portalanimationcount then
portalanimation = 1
end
end
--portal particles
portalparticletimer = portalparticletimer + dt
while portalparticletimer > portalparticletime do
portalparticletimer = portalparticletimer - portalparticletime
for i, v in pairs(objects["player"]) do
if v.portal1facing ~= nil then
local x1, y1
if v.portal1facing == "up" then
x1 = v.portal1X + math.random(1, 30)/16 -1
y1 = v.portal1Y-1
elseif v.portal1facing == "down" then
x1 = v.portal1X + math.random(1, 30)/16-2
y1 = v.portal1Y
elseif v.portal1facing == "left" then
x1 = v.portal1X-1
y1 = v.portal1Y + math.random(1, 30)/16-2
elseif v.portal1facing == "right" then
x1 = v.portal1X
y1 = v.portal1Y + math.random(1, 30)/16-1
end
local color
if players == 1 then
color = {157/255, 222/255, 254/255}
else
color = v.portal1color
end
table.insert(portalparticles, portalparticle:new(x1, y1, color, v.portal1facing))
end
if v.portal2facing ~= nil then
local x2, y2
if v.portal2facing == "up" then
x2 = v.portal2X + math.random(1, 30)/16 -1
y2 = v.portal2Y-1
elseif v.portal2facing == "down" then
x2 = v.portal2X + math.random(1, 30)/16-2
y2 = v.portal2Y
elseif v.portal2facing == "left" then
x2 = v.portal2X-1
y2 = v.portal2Y + math.random(1, 30)/16-2
elseif v.portal2facing == "right" then
x2 = v.portal2X
y2 = v.portal2Y + math.random(1, 30)/16-1
end
local color
if players == 1 then
color = {255/255, 122/255, 66/255}
else
color = v.portal2color
end
table.insert(portalparticles, portalparticle:new(x2, y2, color, v.portal2facing))
end
end
end
delete = {}
for i, v in pairs(portalparticles) 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(portalparticles, v) --remove
end
--PORTAL PROJECTILES
delete = {}
for i, v in pairs(portalprojectiles) 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(portalprojectiles, v) --remove
end
--FIRE SPAWNING
if not levelfinished and firestarted and (not objects["bowser"][1] or (objects["bowser"][1].backwards == false and objects["bowser"][1].shot == false and objects["bowser"][1].fall == false)) then
firetimer = firetimer + dt
while firetimer > firedelay do
firetimer = firetimer - firedelay
firedelay = math.random(4)
table.insert(objects["fire"], fire:new(splitxscroll[1] + width, math.random(3)+7))
end
end
--FLYING FISH
if not levelfinished and flyingfishstarted then
flyingfishtimer = flyingfishtimer + dt
while flyingfishtimer > flyingfishdelay do
flyingfishtimer = flyingfishtimer - flyingfishdelay
flyingfishdelay = math.random(6, 20)/10
table.insert(objects["flyingfish"], flyingfish:new())
end
end
--BULLET BILL
if not levelfinished and bulletbillstarted then
bulletbilltimer = bulletbilltimer + dt
while bulletbilltimer > bulletbilldelay do
bulletbilltimer = bulletbilltimer - bulletbilldelay
bulletbilldelay = math.random(5, 40)/10
table.insert(objects["bulletbill"], bulletbill:new(splitxscroll[1]+width+2, math.random(4, 12), "left"))
end
end
--minecraft stuff
if breakingblockX then
breakingblockprogress = breakingblockprogress + dt
if breakingblockprogress > minecraftbreaktime then
breakblock(breakingblockX, breakingblockY)
breakingblockX = nil
end
end
--Editor
if editormode then
editor_update(dt)
end
--PHYSICS
physicsupdate(dt)
end
function game_draw()
for split = 1, #splitscreen do
love.graphics.translate((split-1)*width*16*scale/#splitscreen, yoffset*scale)
--This is just silly
if earthquake > 0 then
local colortable = {{242, 111, 51}, {251, 244, 174}, {95, 186, 76}, {29, 151, 212}, {101, 45, 135}, {238, 64, 68}}
for i = 1, backgroundstripes do
local r, g, b = unpack(colortable[math.fmod(i-1, 6)+1])
local a = earthquake/rainboomearthquake*255
love.graphics.setColor(r, g, b, a)
local alpha = math.rad((i/backgroundstripes + math.fmod(sunrot/5, 1)) * 360)
local point1 = {width*8*scale+300*scale*math.cos(alpha), 112*scale+300*scale*math.sin(alpha)}
local alpha = math.rad(((i+1)/backgroundstripes + math.fmod(sunrot/5, 1)) * 360)
local point2 = {width*8*scale+300*scale*math.cos(alpha), 112*scale+300*scale*math.sin(alpha)}
love.graphics.polygon("fill", width*8*scale, 112*scale, point1[1], point1[2], point2[1], point2[2])
end
end
love.graphics.setColor(1, 1, 1, 1)
--tremoooor!
if earthquake > 0 then
tremorx = (math.random()-.5)*2*earthquake
tremory = (math.random()-.5)*2*earthquake
love.graphics.translate(round(tremorx), round(tremory))
end
local currentscissor = {(split-1)*width*16*scale/#splitscreen, 0, width*16*scale/#splitscreen, 15*16*scale}
love.graphics.setScissor(unpack(currentscissor))
xscroll = splitxscroll[split]
love.graphics.setColor(1, 1, 1, 1)
local xtodraw
if mapwidth < width+1 then
xtodraw = math.ceil(mapwidth/#splitscreen)
else
if mapwidth > width and xscroll < mapwidth-width then
xtodraw = width+1
else
xtodraw = width
end
end
--custom background
if custombackground then
for i = #custombackgroundimg, 1, -1 do
local xscroll = xscroll / (i * scrollfactor + 1)
if reversescrollfactor() == 1 then
xscroll = 0
end
for y = 1, math.ceil(15/custombackgroundheight[i]) do
for x = 1, math.ceil(width/custombackgroundwidth[i])+1 do
love.graphics.draw(custombackgroundimg[i], math.floor(((x-1)*custombackgroundwidth[i])*16*scale) - math.floor(math.fmod(xscroll, custombackgroundwidth[i])*16*scale), (y-1)*custombackgroundheight[i]*16*scale, 0, scale, scale)
end
end
end
end
--Mushroom under tiles
for j, w in pairs(objects["mushroom"]) do
w:draw()
end
--Flowers under tiles
for j, w in pairs(objects["flower"]) do
w:draw()
end
--Oneupunder tiles
for j, w in pairs(objects["oneup"]) do
w:draw()
end
--star tiles
for j, w in pairs(objects["star"]) do
w:draw()
end
--castleflag
if levelfinished and levelfinishtype == "flag" and not custombackground then
love.graphics.draw(castleflagimg, math.floor((flagx+6-xscroll)*16*scale), 106*scale+castleflagy*16*scale, 0, scale, scale)
end
--TILES
love.graphics.draw(smbspritebatch[split], math.floor(-math.fmod(xscroll, 1)*16*scale), 0)
love.graphics.draw(portalspritebatch[split], math.floor(-math.fmod(xscroll, 1)*16*scale), 0)
if customtiles then
love.graphics.draw(customspritebatch[split], math.floor(-math.fmod(xscroll, 1)*16*scale), 0)
end
local lmap = map
for y = 1, 15 do
for x = 1, xtodraw do
local bounceyoffset = 0
for i, v in pairs(blockbouncex) do
if blockbouncex[i] == math.floor(xscroll)+x and blockbouncey[i] == y then
if blockbouncetimer[i] < blockbouncetime/2 then
bounceyoffset = blockbouncetimer[i] / (blockbouncetime/2) * blockbounceheight
else
bounceyoffset = (2 - blockbouncetimer[i] / (blockbouncetime/2)) * blockbounceheight
end
end
end
local t = lmap[math.floor(xscroll)+x][y]
local tilenumber = t[1]
if tilequads[tilenumber].coinblock and tilequads[tilenumber].invisible == false then --coinblock
love.graphics.draw(coinblockimage, coinblockquads[spriteset][coinframe], math.floor((x-1-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16-8)*scale, 0, scale, scale)
elseif tilequads[tilenumber].coin then --coin
love.graphics.draw(coinimage, coinquads[spriteset][coinframe], math.floor((x-1-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16-8)*scale, 0, scale, scale)
elseif bounceyoffset ~= 0 then
if tilequads[tilenumber].invisible == false or editormode then
love.graphics.draw(tilequads[tilenumber].image, tilequads[tilenumber].quad, math.floor((x-1-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16-8)*scale, 0, scale, scale)
end
end
--Gel overlays!
if t["gels"] then
for i = 1, 4 do
local dir = "top"
local r = 0
if i == 2 then
dir = "right"
r = math.pi/2
elseif i == 3 then
dir = "bottom"
r = math.pi
elseif i == 4 then
dir = "left"
r = math.pi*1.5
end
if t["gels"][dir] == 1 then
love.graphics.draw(gel1ground, math.floor((x-.5-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16)*scale, r, scale, scale, 8, 8)
elseif t["gels"][dir] == 2 then
love.graphics.draw(gel2ground, math.floor((x-.5-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16)*scale, r, scale, scale, 8, 8)
elseif t["gels"][dir] == 3 then
love.graphics.draw(gel3ground, math.floor((x-.5-math.fmod(xscroll, 1))*16*scale), ((y-1-bounceyoffset)*16)*scale, r, scale, scale, 8, 8)
end
end