-
Notifications
You must be signed in to change notification settings - Fork 5
/
game.lua
1229 lines (1074 loc) · 31.6 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(i)
currentmap = i
gamestate = "game"
if loadmap(filetable[i].path) == false then
gamestate = "error"
end
controlsenabled = false
gamepaused = false
newstar = false
fadetimer = 0
fadetimert = 1
fadetimer2 = 0
fadetimer2t = 0
fadetimer3 = 0
fadetimer3t = 0
fadetimer4 = 0
fadetimer4t = 0
fadecolor = 0
fadegoal = "in"
coinglowtimer = 0
coinglowtimert = 0
coinglowa = 0
if filetable[i].text then
texttimer = 0
texttime = string.len(filetable[i].text)/30
end
pausemenutimer = 0
pausemenutimert = 0
menumusic:stop()
musicvolume = 0
gamemusic:setVolume(musicvolume)
wantedbackground = {0, 0, 0}
collectedcoins = {}
camY = - mapheight*20
camX = 10
--get boxwidth
boxwidth = (screenheight+screenwidth)/2/(math.sqrt(mapwidth^2+mapdepth^2)*(1/math.sqrt(2)))
playerscale = math.ceil(boxwidth/50)
drawcenterX = screenwidth/2
drawcenterY = screenheight/2
rotation = 1.1*pi2--math.pi
pitch = 0.5
won = false
calculatevars()
pl = player:new(unpack(start))
perspective = "none"
--updateperspective("none")
scoretime = 0
scoresteps = 0
scorewarps = 0
pausebuttons = {}
pausebuttons["next"] = pausebutton:new(screenwidth/2, screenheight/2+118, "Next Level", completed_next)
pausebuttons["retry"] = pausebutton:new(screenwidth/2, screenheight/2+145, "Improve", completed_retry)
pausebuttons["return"] = pausebutton:new(screenwidth/2, screenheight/2+172, "Back to Menu", completed_return)
pausebuttons["back"] = pausebutton:new(screenwidth/2, screenheight/2-24, "Back to Game", pause_back)
pausebuttons["restart"] = pausebutton:new(screenwidth/2, screenheight/2+3, "Restart Level", pause_restart)
if soundenabled then
pausebuttons["togglesound"] = pausebutton:new(screenwidth/2, screenheight/2+30, "Sound ON", pause_togglesound)
else
pausebuttons["togglesound"] = pausebutton:new(screenwidth/2, screenheight/2+30, "Sound OFF", pause_togglesound)
end
pausebuttons["tomenu"] = pausebutton:new(screenwidth/2, screenheight/2+57, "Back to Menu", pause_tomenu)
pausebuttons["back"].width = 258
pausebuttons["restart"].width = 258
pausebuttons["togglesound"].width = 258
pausebuttons["tomenu"].width = 258
skipupdate = true
playsound(gamemusic)
end
function game_update(dt)
--LOTSA TIMERS
if fadetimer >= 0.5 and fadetimer3 ~= 1.5 and rotation ~= math.pi*1.1 then
local speed = math.abs(math.pi*1.1-rotation)*1.95+0.02
rotation = rotation - speed*dt
if rotation < math.pi*1.1 then
rotation = math.pi*1.1
end
if rotation < 0 then
rotation = rotation + pi2
end
calculatevars()
end
if fadetimer ~= fadetimert then
if fadetimert > fadetimer then
fadetimer = fadetimer + dt
if fadetimer >= fadetimert then
fadetimer = fadetimert
fadecolor = fadetimer
gamemusic:setVolume(1)
if fadegoal == "in" then
fadetimer2t = 1
fadetimer2 = fadetimer - fadetimert
end
else
gamemusic:setVolume(fadetimer)
fadecolor = fadetimer
end
else
fadetimer = fadetimer - dt
if fadetimer <= fadetimert then
fadetimer = fadetimert
gamemusic:stop()
if fadegoal == "menu" then
menu_load(0, 500)
return
elseif fadegoal == "retry" then
game_load(currentmap)
return
elseif fadegoal == "next" then
game_load(currentmap+1)
return
elseif fadegoal == "menuwin" then
menu_load(-screenwidth, 500)
return
elseif fadegoal == "menustar" then
menu_load(screenwidth, 500)
return
end
else
gamemusic:setVolume(fadetimer)
fadecolor = fadetimer
end
end
else
if menuoffsett >= 0 then
gamemusic:setVolume(gamemusic:getVolume()+dt)
if gamemusic:getVolume() > 1 then
gamemusic:setVolume(1)
end
end
end
if fadetimer2 ~= fadetimer2t then
fadetimer2 = fadetimer2 + dt
if fadetimer2 >= fadetimer2t then
fadetimer3t = 1.5
fadetimer3 = fadetimer2 - fadetimer2t
fadetimer2 = fadetimer2t
end
end
if fadetimer3 ~= fadetimer3t then
fadetimer3 = fadetimer3 + dt
if fadetimer3 >= fadetimer3t then
fadetimer3 = fadetimer3t
controlsenabled = true
fadetimer4t = 0.2
fadetimer4 = fadetimer3 - fadetimer3t
if rotatedrag then
rotatedragX, rotatedragY = mymousegetPosition()
end
end
end
if fadetimer4 ~= fadetimer4t then
fadetimer4 = fadetimer4 + dt
if fadetimer4 >= fadetimer4t then
fadetimer4 = fadetimer4t
end
end
if controlsenabled and texttimer ~= texttime and not gamepaused then
texttimer = texttimer + dt
if texttimer >= texttime then
texttimer = texttime
end
end
if coinglowtimer ~= coinglowtimert then
if coinglowtimer < coinglowtimert then
coinglowtimer = coinglowtimer + dt
if coinglowtimer >= coinglowtimert then
coinglowtimer = coinglowtimert
coinglowtimert = 0
end
else
coinglowtimer = coinglowtimer - dt
if coinglowtimer <= coinglowtimert then
coinglowtimer = coinglowtimert
end
end
end
--coinglow
coinglowa = coinglowtimer*2
if won == true then
winwindowtimer = winwindowtimer + dt
if winwindowtimer > 1 then
winwindowtimer = 1
end
elseif fadetimer3 == 1.5 and not gamepaused then
scoretime = scoretime + dt
end
if pausemenutimer ~= pausemenutimert then
if pausemenutimer < pausemenutimert then
pausemenutimer = pausemenutimer + dt*2
if pausemenutimer >= pausemenutimert then
pausemenutimer = pausemenutimert
end
else
pausemenutimer = pausemenutimer - dt*2
if pausemenutimer <= pausemenutimert then
pausemenutimer = pausemenutimert
end
end
end
if movedrag then
local mousex, mousey = mymousegetPosition()
local xdist = mousex - movedragX
local ydist = mousey - movedragY
movedragX = mousex
movedragY = mousey
--XDIST
cozdist = math.sin(rotation-pi025)*(xdist/pointsevenboxwidth)
coxdist = math.sin(rotation+pi025)*(xdist/pointsevenboxwidth)
rotcenterZ = rotcenterZ + cozdist
rotcenterX = rotcenterX + coxdist
if pitch ~= 0 then
--YDIST
cozdist = math.sin(rotation-pi075)*(ydist/pointsevenboxwidth)*(1/pitch)
coxdist = math.sin(rotation-pi025)*(ydist/pointsevenboxwidth)*(1/pitch)
rotcenterZ = rotcenterZ + cozdist
rotcenterX = rotcenterX + coxdist
end
elseif rotatedrag and controlsenabled then
local mousex, mousey = mymousegetPosition()
local xdist = mousex - rotatedragX
local ydist = mousey - rotatedragY
rotatedragX = mousex
rotatedragY = mousey
rotation = rotation - xdist*rotatespeed
pitch = pitch + ydist*pitchspeed
if rotation < 0 then
rotation = rotation + pi2
elseif rotation > pi2 then
rotation = rotation - pi2
end
if pitch > maxpitch then
pitch = maxpitch
elseif pitch < minpitch then
pitch = minpitch
end
calculatevars()
else
if smoothtarget then
local dir = 1
if rotation > smoothtarget then
dir = -1
end
rotation = smooth(rotation, smoothtarget, dt)
if dir == 1 then
if rotation >= smoothtarget then
rotation = smoothtarget
smoothtarget = nil
updateperspective()
end
else
if rotation <= smoothtarget then
rotation = smoothtarget
smoothtarget = nil
updateperspective()
end
end
calculatevars()
end
if pitchtarget then
local dir = 1
if pitchtarget == 0 then
dir = -1
end
pitch = smooth(pitch, pitchtarget, dt)
if dir == 1 then
if pitch >= pitchtarget then
pitch = pitchtarget
pitchtarget = nil
updateperspective()
end
else
if pitch <= pitchtarget then
pitch = pitchtarget
pitchtarget = nil
updateperspective()
end
end
calculatevars()
end
end
pl:update(dt)
for i, v in pairs(pausebuttons) do
v:update(dt)
end
end
function game_draw()
local lmap = map
love.graphics.setColor(fillcolor[1], fillcolor[2], fillcolor[3], 255)
love.graphics.draw(scanlineimg, 0, math.mod(creditss*3, 5)-5)
if fadetimert == 1 then
gridfadecolor = fadecolor
fillfadecolor = fadetimer2
playerfadecolor = fadecolor
else
gridfadecolor = fadecolor
fillfadecolor = fadecolor
playerfadecolor = fadecolor
end
--ISOMETRIC WORLD
if rotation >= pi125 and rotation < pi175 then
--DRAW ORDER: X, -Z, Y
for cox = 1, mapwidth do
for coz = mapdepth, 1, -1 do
for coy = 1, mapheight do
drawtile(cox, coy, coz, lmap[cox][coy][coz], 1, 1, -1)
end
end
end
elseif rotation >= pi175 or rotation < pi025 then
--DRAW ORDER: Z, X, Y
for coz = 1, mapdepth do
for cox = 1, mapwidth do
for coy = 1, mapheight do
drawtile(cox, coy, coz, lmap[cox][coy][coz], 1, 1, 1)
end
end
end
elseif rotation >= pi025 and rotation < pi075 then
--DRAW ORDER: -X, Z, Y
for cox = mapwidth, 1, -1 do
for coz = 1, mapdepth do
for coy = 1, mapheight do
drawtile(cox, coy, coz, lmap[cox][coy][coz], -1, 1, 1)
end
end
end
elseif rotation >= pi075 and rotation < pi125 then
--DRAW ORDER: -Z, -X, Y
for coz = mapdepth, 1, -1 do
for cox = mapwidth, 1, -1 do
for coy = 1, mapheight do
drawtile(cox, coy, coz, lmap[cox][coy][coz], -1, 1, -1)
end
end
end
end
--always draw player in topdown
if perspective == "up" then
local x, y = convertGRDtoSCR(pl.drawx, pl.drawy, pl.drawz)
love.graphics.setColor(255, 255, 255, 255*fadecolor)
if won == false then
love.graphics.drawq(playerimg, playerquad[1], round(x), round(y+halfboxwidth*pitch*0.6), 0, playerscale, playerscale, 10, 20)
love.graphics.setColor(255, 255, 255, 255*coinglowa)
love.graphics.draw(coinglowimg, round(x), round(y+halfboxwidth*pitch*0.6), 0, playerscale/4, playerscale/4, 29, 89)
else
love.graphics.drawq(playerimg, playerquad[2], round(x), round(y+halfboxwidth*pitch*0.6), 0, playerscale, playerscale, 10, 20)
love.graphics.setColor(0, 255, 0, 255*fadecolor)
love.graphics.rectangle("fill", round(x)-2*playerscale, round(y+halfboxwidth*pitch*0.6)-16*playerscale-winwindowtimer/1*3*playerscale, 4*playerscale, winwindowtimer/1*3*playerscale)
end
end
--Level text
if filetable[currentmap].text then
alpha = fadecolor
width = 99 + (625-(1-((fadetimer3)/1.5))^2 * 625)
mygraphicssetScissor(149, 0, width+1, 101)
love.graphics.setColor(0, 0, 0, 200*alpha)
love.graphics.rectangle("fill", 150, 1, width, 100)
love.graphics.setColor(255, 255, 255, 100*alpha)
love.graphics.rectangle("fill", 159, 10, 80, 81)
local r, g, b = unpack(getrainbowcolor(math.mod(rainbowi+0.5, 1)))
love.graphics.setColor(r, g, b, 200*alpha)
love.graphics.rectangle("line", 150, 1, width, 100)
love.graphics.draw(textavatarimg, 159, 11)
love.graphics.setFont(winwindowfont)
love.graphics.setColor(190, 206, 248, alpha*255)
local s = string.sub(filetable[currentmap].text, 1, math.max(0, string.len(filetable[currentmap].text)*(texttimer/texttime)-1))
if math.mod(rainbowi, 0.1) > 0.033 then
s = s .. "_"
end
love.graphics.printf( s, 260, 10, 604, "left" )
love.graphics.setColor(fillcolor[1], fillcolor[2], fillcolor[3], 255*alpha)
love.graphics.draw(scanlineimg, 0, math.mod(creditss*3, 5)-5)
mygraphicssetScissor()
end
local r, g, b = unpack(getrainbowcolor(math.mod(rainbowi+0.5, 1)))
love.graphics.setColor(r, g, b, 200*fadecolor)
if fadetimer >= 0.5 and fadetimer2 < 0.5 then
love.graphics.draw(number3img, 436.5, 296-(fadetimer+fadetimer2-1)*2*(screenheight/2+175))
elseif fadetimer2 >= 0.5 and fadetimer3 < 0.5 then
love.graphics.draw(number2img, 436.5, 296-(fadetimer2+fadetimer3-1)*2*(screenheight/2+175))
elseif fadetimer3 >= 0.5 and fadetimer3 < 1.5 then
love.graphics.draw(number1img, 474, 296-(fadetimer3-1)*2*(screenheight/2+175))
elseif fadetimer3 == 1.5 and fadetimer4 < 0.1 then
love.graphics.setColor(r, g, b, 200*fadecolor)
love.graphics.draw(gosmallimg, 311.5, 296)
elseif fadetimer4 >= 0.1 and fadetimer4 < 0.2 then
love.graphics.setColor(r, g, b, 200*fadecolor)
love.graphics.draw(gobigimg, 111.5, 208.5)
end
love.graphics.setColor(255, 255, 255, 200*fadecolor)
love.graphics.setFont(winwindowfont)
love.graphics.draw(clockimg, 7, 7, 0, 2, 2)
love.graphics.draw(stepsimg, 7, 32, 0, 2, 2)
love.graphics.draw(warpsimg, 7, 57, 0, 2, 2)
love.graphics.printf(round(scoretime, 2), 0, 2, 120, "right")
love.graphics.printf(scoresteps, 0, 27, 120, "right")
love.graphics.printf(scorewarps, 0, 52, 120, "right")
love.graphics.line(0, 28, 111, 28)
love.graphics.line(0, 53, 111, 53)
if pausemenutimer > 0 then
local height = (100-(1-((pausemenutimer)/1))^2 * 100)
mygraphicssetScissor(screenwidth/2-130-1, screenheight/2-height-1, 260+1, height*2+1)
love.graphics.setColor(0, 0, 0, 200*fadecolor)
love.graphics.rectangle("fill", screenwidth/2-130, screenheight/2-height, 259, height*2)
love.graphics.setColor(255, 255, 255, 255*fadecolor)
love.graphics.setFont(winwindowtitlefont, 20)
love.graphics.print("Game Paused", screenwidth/2-111, screenheight/2-80)
pausebuttons["back"]:draw()
pausebuttons["restart"]:draw()
pausebuttons["togglesound"]:draw()
pausebuttons["tomenu"]:draw()
local r, g, b = unpack(getrainbowcolor(math.mod(rainbowi+0.5, 1)))
love.graphics.setColor(r, g, b, 255*fadecolor)
love.graphics.rectangle("line", screenwidth/2-130, screenheight/2-height, 260, height*2)
mygraphicssetScissor()
end
if won then
local height = (200-(1-((winwindowtimer)/1))^2 * 200)
mygraphicssetScissor(0, screenheight/2-height-1, screenwidth, height*2+1)
if newstar then
love.graphics.setColor(255, 255, 255, 150*fadecolor)
love.graphics.draw(yaywonimg, screenwidth/2-210, screenheight/2-200)
end
love.graphics.setColor(0, 0, 0, 200*fadecolor)
love.graphics.rectangle("fill", screenwidth/2-110, screenheight/2-height, 219, height*2)
love.graphics.setColor(255, 255, 255, 255*fadecolor)
love.graphics.setFont(winwindowtitlefont, 20)
love.graphics.print("Level Done!", screenwidth/2-91, screenheight/2-200)
love.graphics.draw(clockimg, screenwidth/2-92, screenheight/2-159, 0, 2, 2)
love.graphics.draw(stepsimg, screenwidth/2-92, screenheight/2-59, 0, 2, 2)
love.graphics.draw(warpsimg, screenwidth/2-92, screenheight/2+41, 0, 2, 2)
love.graphics.print("Time", screenwidth/2-70, screenheight/2-170)
love.graphics.print("Steps", screenwidth/2-70, screenheight/2-70)
love.graphics.print("Warps", screenwidth/2-70, screenheight/2+30)
love.graphics.setFont(winwindowfont, 20)
love.graphics.print("You:", screenwidth/2-70, screenheight/2-145)
love.graphics.print("You:", screenwidth/2-70, screenheight/2-45)
love.graphics.print("You:", screenwidth/2-70, screenheight/2+55)
love.graphics.setFont(winwindowfont, 20)
love.graphics.print("P. Best:", screenwidth/2-70, screenheight/2-128)
love.graphics.print(besttime or "-", screenwidth/2+30, screenheight/2-128)
love.graphics.print("P. Best:", screenwidth/2-70, screenheight/2-28)
love.graphics.print(beststeps or "-", screenwidth/2+30, screenheight/2-28)
love.graphics.print("P. Best:", screenwidth/2-70, screenheight/2+72)
love.graphics.print(bestwarps or "-", screenwidth/2+30, screenheight/2+72)
if timebeaten then
love.graphics.setColor(0, 255, 0, 255*fadecolor)
else
love.graphics.setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(scoretime, screenwidth/2+30, screenheight/2-145)
if stepsbeaten then
love.graphics.setColor(0, 255, 0, 255*fadecolor)
else
love.graphics.setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(scoresteps, screenwidth/2+30, screenheight/2-45)
if warpsbeaten then
love.graphics.setColor(0, 255, 0, 255*fadecolor)
else
love.graphics.setColor(255, 0, 0, 255*fadecolor)
end
love.graphics.print(scorewarps, screenwidth/2+30, screenheight/2+55)
love.graphics.setColor(255, 255, 255, 255*fadecolor)
love.graphics.print("Goal:", screenwidth/2-70, screenheight/2-111)
love.graphics.print(goaltime, screenwidth/2+30, screenheight/2-111)
love.graphics.print("Goal:", screenwidth/2-70, screenheight/2-11)
love.graphics.print(goalsteps, screenwidth/2+30, screenheight/2-11)
love.graphics.print("Goal:", screenwidth/2-70, screenheight/2+89)
love.graphics.print(goalwarps, screenwidth/2+30, screenheight/2+89)
if currentmap ~= #filetable then
pausebuttons["next"]:draw()
end
pausebuttons["retry"]:draw()
pausebuttons["return"]:draw()
local r, g, b = unpack(getrainbowcolor(math.mod(rainbowi+0.5, 1)))
love.graphics.setColor(r, g, b, 255*fadecolor)
love.graphics.rectangle("line", screenwidth/2-110, screenheight/2-height, 220, height*2)
mygraphicssetScissor()
end
end
function updateperspective(persp)
local previouspersp = perspective
if persp then
perspective = persp
else
--get what perspective we're even _talking_ about!
if pitchtarget ~= nil or smoothtarget ~= nil then
return
end
perspective = "none"
if pitch == 1 then
perspective = "up"
else
if rotation == pi025 + 0.000001 then
perspective = "back"
elseif rotation == pi075 + 0.000001 then
perspective = "left"
elseif rotation == pi125 + 0.000001 then
perspective = "front"
elseif rotation == pi175 + 0.000001 then
perspective = "right"
end
end
end
if perspective == "none" then
if previouspersp ~= "none" then
if not won then
wantedbackground = {70, 0, 0}
end
if map[pl.x][pl.y][pl.z].tilenum == 1 then --Player is flying lol /noclip
if previouspersp == "front" or previouspersp == "back" then
--Player is wrong on the Z axis
local plusdist, mindist = mapdepth, mapdepth
for z = pl.z+1, mapdepth do
if map[pl.x][pl.y][z].tilenum ~= 1 then
plusdist = z - pl.z
break
end
end
for z = pl.z-1, 1, -1 do
if map[pl.x][pl.y][z].tilenum ~= 1 then
mindist = pl.z - z
break
end
end
if plusdist <= mindist then
pl.z = pl.z+plusdist
else
pl.z = pl.z-mindist
end
pl.drawz = pl.z
elseif previouspersp == "left" or previouspersp == "right" then
--Player is wrong on the X axis
local plusdist, mindist = mapwidth, mapwidth
for x = pl.x+1, mapwidth do
if map[x][pl.y][pl.z].tilenum ~= 1 then
plusdist = x - pl.x
break
end
end
for x = pl.x-1, 1, -1 do
if map[x][pl.y][pl.z].tilenum ~= 1 then
mindist = pl.x - x
break
end
end
if plusdist <= mindist then
pl.x = pl.x+plusdist
else
pl.x = pl.x-mindist
end
pl.drawx = pl.x
end
end
end
else
scorewarps = scorewarps + 1
if previouspersp == "none" then
pl.oldx, pl.oldy, pl.oldz = pl.x, pl.y, pl.z
end
wantedbackground = {0, 70, 0}
local playercovered = false
if perspective == "front" then
map2d = {}
for x = 1, mapwidth do
map2d[x] = {}
for y = 1, mapheight do
--find closest to screen (lowest Z)
local lowestz = mapdepth+1
for z = mapdepth, 1, -1 do
if map[x][y][z].tilenum ~= 1 then
lowestz = z
end
end
if x == pl.x and y == pl.y+1 then
if lowestz ~= mapdepth+1 then
playercovered = true
end
end
if lowestz ~= mapdepth+1 then
map2d[x][y] = map[x][y][lowestz].tilenum
else
map2d[x][y] = 1
end
end
end
elseif perspective == "back" then
map2d = {}
for x = 1, mapwidth do
map2d[x] = {}
for y = 1, mapheight do
--find closest to screen (highest Z)
local highestz = 0
for z = 1, mapdepth do
if map[mapwidth-x+1][y][z].tilenum ~= 1 then
highestz = z
end
end
if mapwidth-x+1 == pl.x and y == pl.y+1 then
if highestz ~= 0 then
playercovered = true
end
end
if highestz ~= 0 then
map2d[x][y] = map[mapwidth-x+1][y][highestz].tilenum
else
map2d[x][y] = 1
end
end
end
elseif perspective == "left" then
map2d = {}
for x = mapdepth, 1, -1 do
map2d[x] = {}
for y = 1, mapheight do
--find closest to screen (lowest X)
local lowestx = mapwidth+1
for x2 = mapwidth, 1, -1 do
if map[x2][y][mapdepth-x+1].tilenum ~= 1 then
lowestx = x2
end
end
if mapdepth-x+1 == pl.z and y == pl.y+1 then
if lowestx ~= mapwidth+1 then
playercovered = true
end
end
if lowestx ~= mapwidth+1 then
map2d[x][y] = map[lowestx][y][mapdepth-x+1].tilenum
else
map2d[x][y] = 1
end
end
end
elseif perspective == "right" then
map2d = {}
for x = 1, mapdepth do
map2d[x] = {}
for y = 1, mapheight do
--find closest to screen (highest X)
local highestx = 0
for x2 = 1, mapwidth do
if map[x2][y][x].tilenum ~= 1 then
highestx = x2
end
end
if x == pl.z and y == pl.y+1 then
if highestx ~= 0 then
playercovered = true
end
end
if highestx ~= 0 then
map2d[x][y] = map[highestx][y][x].tilenum
else
map2d[x][y] = 1
end
end
end
elseif perspective == "up" then
map2d = {}
for x = 1, mapwidth do
map2d[x] = {}
for y = 1, mapdepth do
--find closest to screen (highest Y)
local highesty = 0
for y2 = 1, mapheight do
if map[x][y2][y].tilenum ~= 1 then
highesty = y2
end
end
if x == pl.x and y == pl.z then
if highesty > pl.y+1 or map[x][highesty][y].tilenum == 3 then
playercovered = true
end
end
if highesty ~= 0 then
map2d[x][y] = map[x][highesty][y].tilenum
else
map2d[x][y] = 1
end
end
end
end
if playercovered then
updateperspective("none")
return
end
end
checkstuff()
end
function checkperspective(perspective)
local playercovered = false
if perspective == "front" then
for x = 1, mapwidth do
for y = 1, mapheight do
--find closest to screen (lowest Z)
local lowestz = mapdepth+1
for z = mapdepth, 1, -1 do
if map[x][y][z].tilenum ~= 1 then
lowestz = z
end
end
if x == pl.x and y == pl.y+1 then
if lowestz ~= mapdepth+1 then
playercovered = true
end
end
end
end
elseif perspective == "back" then
for x = 1, mapwidth do
for y = 1, mapheight do
--find closest to screen (highest Z)
local highestz = 0
for z = 1, mapdepth do
if map[mapwidth-x+1][y][z].tilenum ~= 1 then
highestz = z
end
end
if mapwidth-x+1 == pl.x and y == pl.y+1 then
if highestz ~= 0 then
playercovered = true
end
end
end
end
elseif perspective == "left" then
for x = mapdepth, 1, -1 do
for y = 1, mapheight do
--find closest to screen (lowest X)
local lowestx = mapwidth+1
for x2 = mapwidth, 1, -1 do
if map[x2][y][mapdepth-x+1].tilenum ~= 1 then
lowestx = x2
end
end
if mapdepth-x+1 == pl.z and y == pl.y+1 then
if lowestx ~= mapwidth+1 then
playercovered = true
end
end
end
end
elseif perspective == "right" then
for x = 1, mapdepth do
for y = 1, mapheight do
--find closest to screen (highest X)
local highestx = 0
for x2 = 1, mapwidth do
if map[x2][y][x].tilenum ~= 1 then
highestx = x2
end
end
if x == pl.z and y == pl.y+1 then
if highestx ~= 0 then
playercovered = true
end
end
end
end
elseif perspective == "up" then
for x = 1, mapwidth do
for y = 1, mapdepth do
--find closest to screen (highest Y)
local highesty = 0
for y2 = 1, mapheight do
if map[x][y2][y].tilenum ~= 1 then
highesty = y2
end
end
if x == pl.x and y == pl.z then
if highesty > pl.y+1 or map[x][highesty][y].tilenum == 3 then
playercovered = true
end
end
end
end
end
return playercovered
end
function checkstuff()
if won == true then
return
end
local delete = {}
for i, v in pairs(coins) do
if perspective == "front" or perspective == "back" then
for z = 1, mapdepth do
if v[1] == pl.x and v[2] == pl.y and v[3] == z then
collectcoin(i)
table.insert(delete, i)
coinglowtimert = 0.5
playsound(coinsound)
end
end
elseif perspective == "right" or perspective == "left" then
for x = 1, mapwidth do
if v[1] == x and v[2] == pl.y and v[3] == pl.z then
collectcoin(i)
table.insert(delete, i)
coinglowtimert = 0.5
playsound(coinsound)
end
end
elseif perspective == "up" then
for y = mapheight, pl.y, -1 do
if v[1] == pl.x and v[2] == y and v[3] == pl.z then
collectcoin(i)
table.insert(delete, i)
coinglowtimert = 0.5
playsound(coinsound)
end
end
else
if pl.x == v[1] and pl.y == v[2] and pl.z == v[3] then
collectcoin(i)
table.insert(delete, i)
coinglowtimert = 0.5
playsound(coinsound)
end
end
end
table.sort(delete, function(a,b) return a>b end)
for i, v in pairs(delete) do
table.insert(collectedcoins, {coins[v][1], coins[v][2], coins[v][3]})
table.remove(coins, v)
end
if perspective == "front" then
if map2d[pl.x][pl.y] == 4 then
win()
end
elseif perspective == "back" then
if map2d[mapwidth-pl.x+1][pl.y] == 4 then
win()
end
elseif perspective == "right" then
if map2d[pl.z][pl.y] == 4 then
win()
end
elseif perspective == "left" then
if map2d[mapdepth-pl.z+1][pl.y] == 4 then
win()
end
else
if map[pl.x][pl.y][pl.z].tilenum == 4 then
win()
end
end
end
function win()
won = true
if scoretime < 100 then
scoretime = round(scoretime, 2)
else
scoretime = round(scoretime)
end
texttimer = texttime
if scoretime <= goaltime then
timebeaten = true
else
timebeaten = false
end
if scoresteps <= goalsteps then
stepsbeaten = true
else
stepsbeaten = false
end
if scorewarps <= goalwarps then
warpsbeaten = true
else
warpsbeaten = false
end