-
Notifications
You must be signed in to change notification settings - Fork 17
/
game.lua
5889 lines (5093 loc) · 174 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)
checkpointx = {}
checkpointy = {}
checkpointsub = false
scrollfactor = 0
fscrollfactor = 0
love.graphics.setBackgroundColor(backgroundcolor[1])
--LINK STUFF
mariocoincount = 0
marioscore = 0
globools = {}
globints = {}
firstunder100 = true
--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
autoscrollx = true
autoscrolly = true
jumpitems = { "mushroom", "oneup" }
marioworld = 1
mariolevel = 1
mariosublevel = 0
respawnsublevel = 0
objects = nil
if suspended == true then
continuegame()
elseif suspended then
marioworld = suspended
end
musicname = nil
--FINALLY LOAD THE DAMN LEVEL
levelscreen_load("initial")
end
function game_update(dt)
if not objects then return end
dt = dt * speed
gdt = dt
--------
--GAME--
--------
--animationS
animationsystem_update(dt)
--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
--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
for i = 1, #animatedbooltimerlist do
animatedbooltimerlist[i]:update(dt)
end
--coinanimation
coinanimation = coinanimation + dt*6.75
while coinanimation >= 6 do
coinanimation = coinanimation - 5
end
coinframe = math.max(1, math.floor(coinanimation))
--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
--SCROLLING TEXTS
local delete = {}
for i, v in pairs(scrollingtexts) do
if scrollingtexts[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(scrollingtexts, v) --remove
end
if replaysystem then
for j = 1, #replaydata do
if replaydata[j].data then
replaytimer[j] = replaytimer[j] + dt
while replaydata[j].data[replayi[j]].time < replaytimer[j] and replayi[j] < #replaydata[j].data do
replayi[j] = replayi[j] + 1
end
end
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
--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 and firstunder100 then
love.audio.stop()
playsound("lowtime")
end
if mariotime > 0 and mariotime + 2.5*dt >= 99-8 and mariotime < 99-8 and firstunder100 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.ogg")
end
firstunder100 = false
end
if mariotime <= 0 then
mariotime = 0
for i, v in pairs(objects["player"]) do
v:die("time")
end
end
end
end
--remove userects
local delete = {}
for i, v in pairs(userects) do
if v.delete 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)
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
--check if updates are blocked for whatever reason
if noupdate then
for i, v in pairs(objects["player"]) do --But update players anyway.
v:update(dt)
end
return
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
--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("l") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(1)
elseif love.mouse.isDown("r") then
gelcannontimer = gelcannondelay
objects["player"][mouseowner]:shootgel(2)
end
end
end
--UPDATE STUFFFFF
local updatetable = { pedestals, emancipationfizzles, emancipateanimations, dialogboxes, rocketlaunchers, emancipationgrills, fireworks, miniblocks, bubbles, platformspawners, seesaws, blockdebristable,
userects, rainbooms, coinblockanimations, itemanimations}
for i, v in pairs(objects) do
if i ~= "tile" and i ~= "portalwall" and i ~= "screenboundary" then
table.insert(updatetable, v)
end
end
for i, v in pairs(updatetable) do
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.y > mapheight+5 or w.x > mapwidth+5 or w.x < -5 or w.y < -5 then
if w.autodeleted then
w:autodeleted()
end
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
--PHYSICS
physicsupdate(dt)
--SCROLLING
--HORIZONTAL
local oldxscroll = xscroll
local oldyscroll = yscroll
if autoscroll and minimapdragging == false then
--scrolling
local i = 1
while i <= players and (objects["player"][i].dead or objects["player"][i].remote) do
i = i + 1
end
local fastestplayer = objects["player"][i]
-- HORIZONTAL SCROLLING
if fastestplayer then
for i = 1, players do
if not objects["player"][i].dead and not objects["player"][i].remote and objects["player"][i].x > fastestplayer.x then
fastestplayer = objects["player"][i]
end
end
local speedx = converttostandard(fastestplayer, fastestplayer.speedx, fastestplayer.speedy)
if fastestplayer.dead then -- scrolling fix for online multiplayer if all local players suck. I mean, are dead.
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
--LEFT
if fastestplayer.x < xscroll + scrollingleftstart and xscroll > 0 then
if fastestplayer.x < xscroll + scrollingleftstart and speedx < 0 then
if speedx < -scrollrate then
xscroll = xscroll - scrollrate*dt
else
xscroll = xscroll + speedx*dt
end
end
if fastestplayer.x < xscroll + scrollingleftcomplete then
if fastestplayer.x > xscroll + scrollingleftcomplete - 1/16 then
xscroll = xscroll - scrollrate*dt
else
xscroll = xscroll - superscrollrate*dt
end
end
end
--RIGHT
if fastestplayer.x > xscroll + width - scrollingstart and xscroll < mapwidth - width then
if fastestplayer.x > xscroll + width - scrollingstart and speedx > 0.3 then
if speedx > scrollrate then
xscroll = xscroll + scrollrate*dt
else
xscroll = xscroll + speedx*dt
end
end
if fastestplayer.x > xscroll + width - scrollingcomplete then
if fastestplayer.x > xscroll + width - scrollingcomplete then
xscroll = xscroll + scrollrate*dt
if xscroll > fastestplayer.x - (width - scrollingcomplete) then
xscroll = fastestplayer.x - (width - scrollingcomplete)
end
else
xscroll = fastestplayer.x - (width - scrollingcomplete)
end
end
end
--just force that shit
if not levelfinished then
if fastestplayer.x > xscroll + width - scrollingcomplete then
xscroll = xscroll + superscroll*dt
if fastestplayer.x < xscroll + width - scrollingcomplete then
xscroll = fastestplayer.x - width + scrollingcomplete
end
--xscroll = fastestplayer.x + width - scrollingcomplete - width
end
end
if xscroll > mapwidth-width then
xscroll = math.max(0, mapwidth-width)
hitrightside()
end
if xscroll < 0 then
xscroll = 0
end
if (axex and xscroll > axex-width and axex >= width) then
xscroll = axex-width
hitrightside()
end
end
--VERTICAL SCROLLING
for i = 1, players do
local v = objects["player"][i]
local old = ylookmodifier
if downkey(i) then
if v.looktimer < userscrolltime then
v.looktimer = v.looktimer + dt
else
if ylookmodifier < math.min(userscrollrange, mapheight-(height+yscroll)) then
ylookmodifier = ylookmodifier + dt*userscrollspeed
if ylookmodifier > math.min(userscrollrange, mapheight-(height+yscroll)) then
ylookmodifier = math.min(userscrollrange, mapheight-(height+yscroll))
end
end
end
elseif upkey(i) then
if v.looktimer < userscrolltime then
v.looktimer = v.looktimer + dt
else
if ylookmodifier > -math.min(userscrollrange, yscroll) then
ylookmodifier = ylookmodifier - dt*userscrollspeed
if ylookmodifier < -math.min(userscrollrange, yscroll) then
ylookmodifier = -math.min(userscrollrange, yscroll)
end
end
end
else
v.looktimer = 0
if ylookmodifier > 0 then
ylookmodifier = math.max(0, ylookmodifier - userscrollspeed*dt)
elseif ylookmodifier < 0 then
ylookmodifier = math.min(0, ylookmodifier + userscrollspeed*dt)
end
end
yscroll = yscroll + (ylookmodifier-old)
end
local i = 1
while i <= players and (objects["player"][i].dead or objects["player"][i].remote) 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 not objects["player"][i].remote and objects["player"][i].y > fastestplayer.y then
fastestplayer = objects["player"][i]
end
end
local dummy, speedy = converttostandard(fastestplayer, fastestplayer.speedx, fastestplayer.speedy)
if fastestplayer.y-yscroll < upscrollborder then
local minspeed = (fastestplayer.y-yscroll-upscrollborder)*yscrollingrate
yscroll = yscroll+math.min(speedy, minspeed)*dt
elseif fastestplayer.y-yscroll > height-downscrollborder then
local minspeed = (fastestplayer.y-yscroll - (height-downscrollborder))*yscrollingrate
yscroll = yscroll+math.max(speedy, minspeed)*dt
end
end
if yscroll > mapheight-height-1 then
yscroll = math.max(0, mapheight-height-1)
end
if yscroll < 0 then
yscroll = 0
end
end
if not autoscroll or not autoscrollx then
xscroll = oldxscroll
end
if not autoscroll or not autoscrolly then
yscroll = oldyscroll
end
if firstpersonview then
xscroll = objects["player"][1].x-width/2+objects["player"][1].width/2
yscroll = objects["player"][1].y-height/2+objects["player"][1].height/2-.5
end
if mapwidth > width then
xscroll = math.min(xscroll, mapwidth-width)
end
--[[ Code I wrote for testing all levels for crashes.. doesn't properly change the levels anymore..
for i = 1, 10 do
mazesolved[i] = true
end
xscroll = xscroll + dt*100
if xscroll >= mapwidth-width then
while true do
mariosublevel = mariosublevel + 1
if mariosublevel > 5 then
mariosublevel = 0
mariolevel = mariolevel + 1
if mariolevel > 4 then
mariolevel = 1
marioworld = marioworld + 1
end
end
love.timer.sleep(0.1)
if mariosublevel == 0 then
print(marioworld .. "-" .. mariolevel .. ".txt")
if love.filesystem.exists("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. ".txt") then
startlevel(marioworld .. "-" .. mariolevel)
break
end
else
print(marioworld .. "-" .. mariolevel .. "_" .. mariosublevel .. ".txt")
if love.filesystem.exists("mappacks/" .. mappack .. "/" .. marioworld .. "-" .. mariolevel .. "_" .. mariosublevel .. ".txt") then
startlevel(marioworld .. "-" .. mariolevel .. "_" .. mariosublevel)
break
end
end
end
end
--]]
--camera pan x
if xpan then
xpantimer = xpantimer + dt
if xpantimer >= xpantime then
xpan = false
xpantimer = xpantime
end
local i = xpantimer/xpantime
xscroll = xpanstart + xpandiff*i
end
--camera pan y
if ypan then
ypantimer = ypantimer + dt
if ypantimer >= ypantime then
ypan = false
ypantimer = ypantime
end
local i = ypantimer/ypantime
yscroll = ypanstart + ypandiff*i
end
--enemy spawning
if not editormode then
if round(xscroll) ~= round(oldxscroll) then
local xstart, xend
if xscroll > oldxscroll then
xstart, xend = round(oldxscroll)+1+math.ceil(width), round(xscroll)+math.ceil(width)
else
xstart, xend = round(xscroll), round(oldxscroll)-1
end
for x = xstart, xend do
for y = round(yscroll)-1, round(yscroll)+height+1 do
spawnenemy(x, y)
end
end
end
if round(yscroll) ~= round(oldyscroll) then
local ystart, yend
if yscroll > oldyscroll then
ystart, yend = round(oldyscroll)+1+math.ceil(height), round(yscroll)+math.ceil(height)
else
ystart, yend = round(yscroll), round(oldyscroll)-1
end
for y = ystart, yend do
for x = round(xscroll)-1, round(xscroll)+width+1 do
spawnenemy(x, y)
end
end
end
end
--SPRITEBATCH UPDATE and CASTLEREPEATS
if math.floor(xscroll) ~= spritebatchX[1] then
if not editormode then
for currentx = lastrepeat+1+width, math.floor(xscroll)+1+width do
reachedx(currentx)
end
end
generatespritebatch()
spritebatchX[1] = math.floor(xscroll)
elseif math.floor(yscroll) ~= spritebatchY[1] then
generatespritebatch()
spritebatchY[1] = math.floor(yscroll)
end
--portal update
for i, v in pairs(portals) do
v:update(dt)
end
--portal particles
portalparticletimer = portalparticletimer + dt
while portalparticletimer > portalparticletime do
portalparticletimer = portalparticletimer - portalparticletime
for i, v in pairs(portals) do
if v.facing1 and v.x1 and v.y1 then
local x1, y1
if v.facing1 == "up" then
x1 = v.x1 + math.random(1, 30)/16-1
y1 = v.y1-1
elseif v.facing1 == "down" then
x1 = v.x1 + math.random(1, 30)/16-2
y1 = v.y1
elseif v.facing1 == "left" then
x1 = v.x1-1
y1 = v.y1 + math.random(1, 30)/16-2
elseif v.facing1 == "right" then
x1 = v.x1
y1 = v.y1 + math.random(1, 30)/16-1
end
table.insert(portalparticles, portalparticle:new(x1, y1, v.portal1color, v.facing1))
end
if v.facing2 ~= nil and v.x2 and v.y2 then
local x2, y2
if v.facing2 == "up" then
x2 = v.x2 + math.random(1, 30)/16-1
y2 = v.y2-1
elseif v.facing2 == "down" then
x2 = v.x2 + math.random(1, 30)/16-2
y2 = v.y2
elseif v.facing2 == "left" then
x2 = v.x2-1
y2 = v.y2 + math.random(1, 30)/16-2
elseif v.facing2 == "right" then
x2 = v.x2
y2 = v.y2 + math.random(1, 30)/16-1
end
table.insert(portalparticles, portalparticle:new(x2, y2, v.portal2color, v.facing2))
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)
local temp = enemy:new(xscroll + width, math.random(3)+7, "fire")
table.insert(objects["enemy"], temp)
if objects["bowser"][1] then --make bowser fire this
temp.y = objects["bowser"][1].y+0.25
temp.x = objects["bowser"][1].x-0.750
--get goal Y
temp.movement = "targety"
temp.targetyspeed = 2
temp.targety = objects["bowser"][1].starty-math.random(3)+2/16
end
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
local x, y = math.random(math.floor(xscroll), math.floor(xscroll)+width), mapheight
local temp = enemy:new(x, y, "flyingfish")
table.insert(objects["enemy"], temp)
temp.speedx = objects["player"][1].speedx + math.random(10)-5
if temp.speedx == 0 then
temp.speedx = 1
end
if temp.speedx > 0 then
temp.animationdirection = "left"
else
temp.animationdirection = "right"
end
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["enemy"], enemy:new(xscroll+width+2, math.random(4, 12), "bulletbill"))
end
end
--Editor
if editormode then
editor_update(dt)
end
--Update pointing angle of players
for i, v in pairs(objects.player) do
if not v.disableaiming then
v:updateangle()
end
end
end
function drawlevel()
if incognito then
return
end
love.graphics.setColor(love.graphics.getBackgroundColor())
love.graphics.rectangle("fill", 0, 0, width*16*scale, height*16*scale)
love.graphics.setColor(1, 1, 1, 1)
local xtodraw
if mapwidth < width+1 then
xtodraw = math.ceil(mapwidth)
else
if mapwidth > width and xscroll < mapwidth-width then
xtodraw = math.ceil(width+1)
else
xtodraw = math.ceil(width)
end
end
local ytodraw
if mapheight < height+1 then
ytodraw = math.ceil(mapheight)
else
if mapheight > height and yscroll < mapheight-height then
ytodraw = height+2
else
ytodraw = height
end
end
--custom background
if custombackground then
if custombackground == true then
local xscroll = xscroll / (scrollfactor + 1)
if reversescrollfactor() == 1 then
xscroll = 0
end
for y = 1, math.ceil(height/14)+1 do
for x = 1, math.ceil(width)+1 do
love.graphics.draw(portalbackgroundimg, math.floor((x-1)*16*scale) - math.floor(math.mod(xscroll, 1)*16*scale), math.floor(((y-1)*14)*16*scale) - math.floor(math.mod(yscroll, 14)*16*scale), 0, scale, scale)
end
end
else
if custombackgroundimg[custombackground] then
for i = #custombackgroundimg[custombackground], 1, -1 do
local xscroll = xscroll / (i * scrollfactor + 1)
if reversescrollfactor() == 1 then
xscroll = 0
end
local yscroll = yscroll / (i * scrollfactor + 1)
if reversescrollfactor() == 1 then
yscroll = 0
end
for y = 1, math.ceil(height/custombackgroundheight[custombackground][i])+1 do
for x = 1, math.ceil(width/custombackgroundwidth[custombackground][i])+1 do
love.graphics.draw(custombackgroundimg[custombackground][i], math.floor(((x-1)*custombackgroundwidth[custombackground][i])*16*scale) - math.floor(math.mod(xscroll, custombackgroundwidth[custombackground][i])*16*scale), math.floor(((y-1)*custombackgroundheight[custombackground][i])*16*scale) - math.floor(math.mod(yscroll, custombackgroundheight[custombackground][i])*16*scale), 0, scale, scale)
end
end
end
end
end
end
--castleflag
if levelfinished and levelfinishtype == "flag" and not custombackground then
love.graphics.draw(castleflagimg, math.floor((flagx+6-xscroll)*16*scale), (flagy-7+10/16)*16*scale+(castleflagy-yscroll)*16*scale, 0, scale, scale)
end
--itemanimations
for j, w in pairs(itemanimations) do
w:draw()
end
--TILES
love.graphics.draw(smbspritebatch, math.floor(-math.mod(xscroll, 1)*16*scale), math.floor(-math.mod(yscroll, 1)*16*scale))
love.graphics.draw(portalspritebatch, math.floor(-math.mod(xscroll, 1)*16*scale), math.floor(-math.mod(yscroll, 1)*16*scale))
if customtiles then
love.graphics.draw(customspritebatch, math.floor(-math.mod(xscroll, 1)*16*scale), math.floor(-math.mod(yscroll, 1)*16*scale))
end
if modcustomtiles then
for i = 1, modcustomtiles do
love.graphics.draw(modcustomspritebatch[i], math.floor(-math.mod(xscroll, 1)*16*scale), math.floor(-math.mod(yscroll, 1)*16*scale))
end
end
local lmap = map
local flooredxscroll
if xscroll >= 0 then
flooredxscroll = math.floor(xscroll)
else
flooredxscroll = math.ceil(xscroll)
end
local flooredyscroll
if yscroll >= 0 then
flooredyscroll = math.floor(yscroll)
else
flooredyscroll = math.ceil(yscroll)
end
for y = 1, ytodraw do
for x = 1, xtodraw do
if inmap(flooredxscroll+x, flooredyscroll+y) then
local bounceyoffset = 0
for i, v in pairs(blockbouncex) do
if blockbouncex[i] == flooredxscroll+x and blockbouncey[i] == flooredyscroll+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 cox, coy = flooredxscroll+x, flooredyscroll+y
local t = lmap[flooredxscroll+x][flooredyscroll+y]
local tilenumber = t[1]
if tilequads[tilenumber]:getproperty("coinblock", cox, coy) and tilequads[tilenumber]:getproperty("invisible", cox, coy) == false then --coinblock
love.graphics.draw(coinblockimg, coinblockquads[spriteset][coinframe], math.floor((x-1-math.mod(xscroll, 1))*16*scale), math.floor(((y-1-math.mod(yscroll, 1)-bounceyoffset)*16-8)*scale), 0, scale, scale)
elseif coinmap[cox][coy] then --coin
love.graphics.draw(coinimg, coinquads[spriteset][coinframe], math.floor((x-1-math.mod(xscroll, 1))*16*scale), math.floor(((y-1-math.mod(yscroll, 1)-bounceyoffset)*16-8)*scale), 0, scale, scale)
elseif bounceyoffset ~= 0 or tilenumber > 10000 then
if not tilequads[tilenumber]:getproperty("invisible", cox, coy) then
love.graphics.draw(tilequads[tilenumber].image, tilequads[tilenumber]:quad(flooredxscroll+x, flooredyscroll+y), math.floor((x-1-math.mod(xscroll, 1))*16*scale), math.floor(((y-1-math.mod(yscroll, 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
for i = 1, 4 do
if t["gels"][dir] == i then
local img
if i == 1 then
img = gel1groundimg
elseif i == 2 then
img = gel2groundimg
elseif i == 3 then
img = gel3groundimg
elseif i == 4 then
img = gel4groundimg
end
love.graphics.draw(img, math.floor((x-.5-math.mod(xscroll, 1))*16*scale), math.floor((y-1-math.mod(yscroll, 1)-bounceyoffset)*16*scale), r, scale, scale, 8, 8)
end
end
end
end
if editormode then
if tilequads[t[1]]:getproperty("invisible", cox, coy) and t[1] ~= 1 then
love.graphics.draw(tilequads[t[1]].image, tilequads[t[1]]:quad(), math.floor((x-1-math.mod(xscroll, 1))*16*scale), ((y-1-math.mod(yscroll, 1))*16-8)*scale, 0, scale, scale)
end
if #t > 1 and t[2] ~= "link" then
tilenumber = t[2]
love.graphics.setColor(1, 1, 1, 0.6)
if tablecontains(enemies, tilenumber) then --ENEMY PREVIEW THING
local v = enemiesdata[tilenumber]
local xoff, yoff = (((v.spawnoffsetx or 0)+v.width/2-.5)*16 - v.offsetX + v.quadcenterX)*scale, (((v.spawnoffsety or 0)-v.height+1)*16-v.offsetY - v.quadcenterY)*scale
local mx, my = getMouseTile(mouse.getX(), mouse.getY()+8*scale)
local alpha = 0.6
if x == mx and y == my then
alpha = 1
end
love.graphics.setColor(1, 0, 0, alpha)
love.graphics.rectangle("fill", math.floor((x-1-math.mod(xscroll, 1))*16*scale), math.floor(((y-1-math.mod(yscroll, 1))*16-8)*scale), 16*scale, 16*scale)
love.graphics.setColor(1, 1, 1, alpha)
love.graphics.draw(v.graphic, v.quad, math.floor((x-1-math.mod(xscroll, 1))*16*scale+xoff), math.floor(((y-1-math.mod(yscroll, 1))*16)*scale+yoff), 0, scale, scale)
else
love.graphics.draw(entityquads[tilenumber].image, entityquads[tilenumber].quad, math.floor((x-1-math.mod(xscroll, 1))*16*scale), math.floor(((y-1-math.mod(yscroll, 1))*16-8)*scale), 0, scale, scale)
end
love.graphics.setColor(1, 1, 1, 1)
end
if entitylist[map[x][y][2]] and entitylist[map[x][y][2]].t == "platform" then
local dir, dist
if rightclickm and rightclickm.tx == x and rightclickm.ty == y then
dir = rightclickm.variables[2].value
dist = tonumber(rightclickm.t[6].value)
else
dir = map[x][y][3]
dist = tonumber(map[x][y][5])
end
love.graphics.setColor(252 / 255, 152 / 255, 56 / 255, 0.6)
if dir == "down" then
love.graphics.line((x-xscroll-.5)*16*scale, (y-yscroll-1.2)*16*scale, (x-xscroll-.5)*16*scale, (y-yscroll-1.2+dist)*16*scale)
elseif dir == "left" then
love.graphics.line((x-xscroll-.5)*16*scale, (y-yscroll-1.2)*16*scale, (x-xscroll-.5-dist)*16*scale, (y-yscroll-1.2)*16*scale)
end
love.graphics.setColor(1, 1, 1, 1)
end
end
end