-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.lua
1456 lines (1405 loc) · 50.1 KB
/
main.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
VERSION = "Version b9.0.245"
if love.filesystem.isFused() then
love.filesystem.mount(love.filesystem.getSourceBaseDirectory(), "Source")
end
local PrintFormatted = love.graphics.printf
---@diagnostic disable-next-line: duplicate-set-field
function love.graphics.printf(text, x, y, ...)
local r, g, b, a = love.graphics.getColor()
love.graphics.setColor(0, 0, 0, a)
PrintFormatted(text, x + 1, y, ...)
PrintFormatted(text, x - 1, y, ...)
PrintFormatted(text, x, y + 1, ...)
PrintFormatted(text, x, y - 1, ...)
love.graphics.setColor(r, g, b, a)
PrintFormatted(text, x, y, ...)
end
local Print = love.graphics.print
---@diagnostic disable-next-line: duplicate-set-field
function love.graphics.print(text, x, y, ...)
local r, g, b, a = love.graphics.getColor()
love.graphics.setColor(0, 0, 0, a)
Print(text, x + 1, y, ...)
Print(text, x - 1, y, ...)
Print(text, x, y + 1, ...)
Print(text, x, y - 1, ...)
love.graphics.setColor(r, g, b, a)
Print(text, x, y, ...)
end
love.graphics.setBackgroundColor(0.1, 0.1, 0.1, 1)
function GetMapNum(mapnum)
mapnum = tostring(mapnum)
if tonumber(mapnum) < 10 then mapnum = "0"..mapnum end
if mapnum:len() > 2 then mapnum = mapnum:sub(2) end
return mapnum
end
local font
messagebox = {
title = "",
contents = "",
show = false,
error = false,
width = 0,
height = 0,
setMessage = function(title, contents, error)
messagebox.show = true
messagebox.title = title
messagebox.contents = contents or ""
local linewidth = 0
for line in string.gmatch(messagebox.contents, "[^\r\n]+") do
local clinewidth = font:getWidth(line)
linewidth = (clinewidth > linewidth and clinewidth) or linewidth
end
messagebox.width = math.max(math.max(font:getWidth(messagebox.title) * 1.5, linewidth), 260)
messagebox.height = 85
for w in messagebox.contents:gmatch("\n") do
messagebox.height = messagebox.height + 20
end
if error or (contents and type(contents) == "boolean") then
messagebox.error = true
end
end
}
notification = {
text = "",
timer = 0,
setMessage = function(text)
notification.text = text
notification.timer = 480
end
}
local ffi = require "ffi"
ffi.cdef((love.filesystem.read("cdef.c")))
require "cache"
require "menu"
require "customhandler"
require "maps"
require "objects"
require "player"
utf8 = require "utf8"
local sound = require "music"
local particles = require "particles"
local coins = require "coins"
local discord = require "discordRPC"
local cutscenes = require "cutscenes"
startTimestamp = os.time(os.date("*t") --[[@as osdateparam]])
discord.menu = {
state = "Menu",
largeImageKey = "logo",
startTimestamp = startTimestamp
}
function discord.updateGamePresence()
local presence = {
details = "Playing",
largeImageKey = "logo",
startTimestamp = startTimestamp,
smallImageText = "Level " .. gamemap + 1 .. ": " .. gamemapname
}
if customEnv then
presence.state = "Modded"
presence.smallImageKey = "unknown"
elseif gamemap == -99 then
presence.state = "???"
presence.smallImageKey = "unknown"
presence.smallImageText = "???"
elseif gamemap < 0 then
presence.state = "Bonus levels"
presence.smallImageKey = "unknown"
else
local chapter = math.floor(gamemap / 10) + 1
presence.state = "Chapter " .. chapter
presence.smallImageKey = "chapter" .. chapter
end
discord.updatePresence(presence)
end
io.stdout:setvbuf("no")
local titlescreen = love.graphics.newImage("Sprites/title1.png")
local titleglow = love.graphics.newImage("Sprites/title2.png")
local function GetUnit(val)
local tval = tostring(val)
return tonumber(tval:sub(tval:len()))
end
function GetScale(num)
return math.floor((18/num)*10)/10
end
function GetScaleByScreen()
return screenheight/600
end
local function DoTime(timetodo, timetoreset)
if timetoreset == 60 then
return timetodo+1, 0
end
return timetodo, timetoreset
end
function GetStartX()
return ((screenwidth-(mapwidth+2)*(scale * GetScaleByScreen())*32)/2)+mouse.camerax
end
function GetStartY()
return ((screenheight-((mapheight < 20 and mapheight) or mapheight+2)*(scale * GetScaleByScreen())*32)/2)+mouse.cameray
end
function love.load(args)
if args[1] == "-debug" then
debugmode = {}
table.insert(possibleTilesets, "bonus.png")
table.insert(possibleMusic, "mind.ogg")
table.insert(menu["level editor"], 4, {name = "Load file: ", string = "", func = function()
mouse.tile = TILE_WALL1
gamestate = LoadEditorMap(menu["level editor"][3].string) and "editing" or "level editor"
end})
table.insert(menu["map settings"], 6, {name = "Save to file: ", string = "", func = function(this)
local mapinfo = menu["map settings"]
SaveMap("Maps/"..this.string, mapinfo[1].string.."\n", mapinfo[2].values[mapinfo[2].value].."\n", mapinfo[3].values[mapinfo[3].value].."\n", mapinfo[4].int.."\n", mapinfo[5].int.."\n")
LoadEditorMap(this.string)
notification.setMessage("Map saved")
end})
lovebug = require "lovebug"
love.mousepressed = lovebug.mousepressed
end
love.graphics.setDefaultFilter("nearest", "nearest")
font = love.graphics.newFont("editundo.ttf", 24, "mono")
love.graphics.setFont(font)
love.keyboard.setKeyRepeat(true)
hisname = ""
leveltime = 0
frametime = 0
seconds = 0
minutes = 0
hours = 0
gamestate = "title"
laststate = "title"
statetimer = 1
gamemap = 0
lastmap = 1
scale = 1
timer = 0
flash = 0
darkness = 0
rotation = 0
screenwidth = love.graphics.getWidth()
screenheight = love.graphics.getHeight()
wheelmoved = 0
---@type nil | ffi.cdata*
player = nil
gamemapname = "forest.png"
musicname = ""
menuButtons = nil
pcall(LoadSettings)
GetAllMaps()
local tilesetimage = GetImage("Sprites/Tiles/" .. (possibleTilesets[math.ceil(lastmap / 10) - 1] or "forest.png"))
tileset = love.graphics.newSpriteBatch(tilesetimage, 1225, "dynamic")
sound.setMusic("menu.ogg")
local coinsgot, coinstotal = coins.count()
if coinsgot == coinstotal then
sound.soundtest[#sound.soundtest] = coins.soundtest
menu.extras[EXTRA_BONUSLEVELS].name = "Bonus levels"
end
if not discord.loaded then
messagebox.setMessage("Could not load DiscordRPC!", "The game can still be played\nbut Discord won't update your status", true)
return
end
discord.initialize("974379262792581231", true)
discord.updatePresence(discord.menu)
end
local glitchshader = love.graphics.newShader("Shaders/glitch.glsl")
local deathshader = love.graphics.newShader("Shaders/death.glsl")
darkshader = love.graphics.newShader("Shaders/dark.glsl")
darkshader:send("light", 200)
local function SpikesWarn(x, y) particles.spawnWarning(x, y, 0.4) end
--bumps structure:
--[1] -> on the top of the map?
--[2] -> of the left of the map?
--[3] -> on the bottom of the map?
--[4] -> on the right of the map?
--[5] -> momx
--[6] -> momy
local bumps = {
["truetruefalsefalse0-1"] = math.pi / 16,
["truetruefalsefalse-10"] = -math.pi / 16,
["truefalsefalsetrue10"] = math.pi / 16,
["truefalsefalsetrue0-1"] = -math.pi / 16,
["falsetruetruefalse-10"] = math.pi / 16,
["falsetruetruefalse01"] = -math.pi / 16,
["falsefalsetruetrue01"] = math.pi / 16,
["falsefalsetruetrue10"] = -math.pi / 16
}
local function FlashCutscene()
flash = flash + 0.02
if flash > 1.7 then
gamestate = "cutscene"
sound.setMusic("cutscene "..cutscenes.num..".ogg")
end
end
function AlternateSpikes()
if CheckMap(TILE_SPIKEON, TILE_SPIKEOFF, TILE_SPIKEOFF, TILE_SPIKEON) then
sound.playSound("spikes.wav")
end
end
local updateModes = {
ingame = function()
if not player then darkness = math.min(darkness + 0.2, 70) end
leveltime = leveltime + 1
local wobble = menu.extras[EXTRA_WOBBLE].value
rotation = (wobble and wobble > 0)
and rotation + (math.cos(leveltime / 100) / 5) / math.max(mapheight, mapwidth)
or rotation / 2
frames = frames + 1
seconds, frames = DoTime(seconds, frames)
minutes, seconds = DoTime(minutes, seconds)
hours, minutes = DoTime(hours, minutes)
if debugmode and debugmode.slowdown and leveltime % 60 ~= 0 then return end
flash = math.max(flash-0.02, 0)
if customEnv then
customEnv.leveltime = leveltime
customEnv.timer = timer
if customEnv.UpdateFrame then
customEnv.UpdateFrame(frames, seconds, minutes, hours)
end
end
if (leveltime%2) == 0 then
local sgamemap = gamemap
for _, mo in pairs(objects) do
local thinker = thinkers[ffi.string(mo.type)]
if thinker then thinker(mo) end
TryMove(mo, 0, 0)
if mo.momx and mo.momy and (mo.momx ~= 0 or mo.momy ~= 0) then
local movingmom = (mo.momx ~= 0 and mo.momx) or mo.momy
movingmom = (movingmom > 0 and math.ceil(2/movingmom)) or math.floor(2/movingmom)
if (leveltime%movingmom == 0) then
local momx = GetTrueMomentum(mo.momx)
local momy = GetTrueMomentum(mo.momy)
local check = TryMove(mo, momx, momy)
if gamemap ~= sgamemap then return end
if not check then
if mo.type == "player" then
local angley = math.max(mapheight / 100 * 20, 2)
local anglex = math.max(mapwidth / 100 * 20, 2)
local bump = bumps[tostring(mo.y <= angley) .. tostring(mo.x <= anglex) .. tostring(mo.y > mapheight - angley) .. tostring(mo.x > mapwidth - anglex) .. mo.momx .. mo.momy]
if bump then rotation = rotation + bump / math.max(mapheight, mapwidth) end
end
mo.momx = 0
mo.momy = 0
sound.playSound("stop.wav")
end
end
end
end
end
local spikeinterval = math.ceil(600 / AssistControl(2))
if ((leveltime + 40) % spikeinterval) == 0 then
IterateMap(TILE_SPIKEOFF, SpikesWarn)
elseif (leveltime % spikeinterval) == 0 then
AlternateSpikes()
elseif (leveltime % 620) == 0 and tilesets[tilesetname].thunder and menu.settings[7].value == 1 and flash == 0 then
flash = 0.7
sound.playSound("thunder.wav")
end
if (leveltime % 60) == 0 then
if timer > 0 and player then
timer = timer - 1
if timer <= 0 then
RemoveObject(player)
end
end
end
end,
editing = function()
leveltime = leveltime + 1
mouse.think()
end,
["sound test"] = function()
if sound.music and not love.mouse.isDown(1) and not sound.music:isPlaying() then sound.music:play() end
end,
["the story begins"] = FlashCutscene,
chaptercomplete = FlashCutscene,
["cutscene selected"] = FlashCutscene
}
function love.update(dt)
if saver then
coroutine.resume(saver)
if coroutine.status(saver) == "dead" then saver = nil end
end
frametime = frametime + math.min(dt, 1/15)
while frametime > 1/60 do
frametime = frametime-1/60
if statetimer < 1 then
statetimer = statetimer + (1 - statetimer) / 10
end
coins.hudtimer = math.max(coins.hudtimer-1, 0)
if #sound.list >= 10 then sound.collectGarbage() end
if #particles.list >= 20 then particles.collectGarbage() end
if updateModes[gamestate] then updateModes[gamestate]() end
end
end
tileAnimations = {
[TILE_AFLOOR1] = 20,
[TILE_RIGHTPUSHER1] = 30,
[TILE_LEFTPUSHER1] = 30,
[TILE_UPPUSHER1] = 30,
[TILE_DOWNPUSHER1] = 30
}
local quadDrawingMethods = {
none = function(_, x, y, sprite)
love.graphics.draw(sprite, x, y, 0, scale)
end,
single = function(_, x, y, sprite, quads)
love.graphics.draw(sprite, quads[1], x, y, 0, scale)
end,
directions = function(mo, x, y, sprite, quads)
love.graphics.draw(sprite, quads[math.floor((leveltime%20)/10)+mo.direction], x, y, 0, scale)
end,
movement = function(mo, x, y, sprite, quads)
love.graphics.draw(sprite, quads[mo.direction+(((mo.momx == 0 and mo.momy == 0) and 0) or 1)], x, y, 0, scale)
end,
position = function(mo, x, y, sprite, quads)
local movingaxis = mo.lastaxis and mo.x or mo.y
love.graphics.draw(sprite, quads[(movingaxis%#quads)+1], x, y, 0, scale)
end,
hp = function(mo, x, y, sprite, quads)
love.graphics.draw(sprite, quads[mo.hp], x, y, 0, scale)
end,
frame = function(mo, x, y, sprite, quads)
love.graphics.draw(sprite, quads[mo.frame], x, y, 0, scale)
end,
default = function(_, x, y, sprite, quads)
love.graphics.draw(sprite, quads[math.floor((leveltime%(#quads*10))/10)+1], x, y, 0, scale)
end
}
local function AnimatedPrint(text, x, y, speed)
speed = speed or 4
for p, c in utf8.codes(text) do
local char = utf8.char(c)
local o = math.sin((p + love.timer.getTime() * 20) / 2.5) * speed
o = math.floor(o - o / 2 + .5)
love.graphics.print(char, x, y + o)
x = x + font:getWidth(char)
end
end
local function DrawTilemap()
local shaders = {}
local flags = tilesets[tilesetname]
local centerx = GetStartX()
local centery = GetStartY()
scale = scale * GetScaleByScreen()
local tilesize = math.floor(32*scale)
local superdark = menu.extras[EXTRA_SUPERDARK].value == 1
love.graphics.push()
love.graphics.translate(screenwidth / 2, screenheight / 2)
love.graphics.rotate(rotation)
love.graphics.translate(-screenwidth / 2, -screenheight / 2)
if player then
mouse.speed = math.max(mouse.speed - 1, 1)
local playerx = centerx + player.x * tilesize + tilesize / 2
local playery = centery + player.y * tilesize + tilesize / 2
playerx, playery = love.graphics.transformPoint(playerx, playery)
if not love.mouse.isDown(1) then
if playerx > screenwidth - 100 then
mouse.camerax = mouse.camerax - 2 * mouse.speed
mouse.speed = mouse.speed + 2
elseif playerx < 100 then
mouse.camerax = mouse.camerax + 2 * mouse.speed
mouse.speed = mouse.speed + 2
end
if playery > screenheight - 100 then
mouse.cameray = mouse.cameray - 2 * mouse.speed
mouse.speed = mouse.speed + 2
elseif playery < 100 then
mouse.cameray = mouse.cameray + 2 * mouse.speed
mouse.speed = mouse.speed + 2
end
end
if flags.dark or superdark then
darkshader:send("pos", {playerx, playery})
darkshader:send("scale", scale)
table.insert(shaders, darkshader)
end
elseif gamestate == "ingame" or gamestate == "pause" or gamestate == "assist mode" then
if flags.dark or superdark then
local radius = scale - (darkness * scale / 2)
darkshader:send("scale", radius)
if radius > -6.3 * scale or superdark then
table.insert(shaders, darkshader)
end
end
deathshader:send("darkness", darkness)
table.insert(shaders, deathshader)
end
if flags.glitch and (gamestate == "ingame" or gamestate == "pause") and menu.settings[7].value == 1 then
local lt = leveltime / 100
glitchshader:send("leveltime", lt)
glitchshader:send("intensity", math.abs(math.sin(leveltime / 700)))
table.insert(shaders, glitchshader)
end
if #shaders > 0 then
love.graphics.setShader(unpack(shaders))
end
if leveltime % 10 == 0 then
UpdateTilemap(tilesize, flags.rotatebridges)
end
love.graphics.draw(tileset, centerx, centery)
for k = 1,40 do
local particle = particles.list[k]
if particle then
local x = (centerx+particle.x*tilesize)+(16*scale)
local y = (centery+particle.y*tilesize)+(16*scale)
love.graphics.draw(particle.particle, x, y, 0, scale)
end
end
for k, mo in pairs(objects) do
local x = centerx+mo.x*tilesize
local y = centery+mo.y*tilesize
local drawingMethod = quadDrawingMethods[ffi.string(mo.quadtype)]
if not drawingMethod then error('object "'..ffi.string(mo.type)..'"('..k..') has an invalid quad type!') end
drawingMethod(mo, x, y, GetImage(ffi.string(mo.sprite)), GetQuadArray(mo.quads))
end
local snow = particles.list[PARTICLE_SNOW]
if snow then
love.graphics.draw(snow.particle, -10, -10)
end
local rain = particles.list[PARTICLE_RAIN]
if rain then
love.graphics.draw(rain.particle, -10, -10)
end
local help = particles.list[PARTICLE_HELP]
if help then
local x = (centerx+help.x*tilesize)+(16*scale)
local y = (centery+help.y*tilesize)+(16*scale)
love.graphics.draw(help.particle, x, y, 0, scale)
end
love.graphics.pop()
if debugmode and debugmode.camera and player then
local playerx = centerx + player.x * tilesize
local playery = centery + player.y * tilesize
love.graphics.setColor(1, 0, 0, 1)
love.graphics.rectangle("line", playerx, playery, tilesize, tilesize)
love.graphics.rectangle("fill", playerx + tilesize / 2, playery + tilesize / 2, 1, 1)
love.graphics.line(100, 0, 100, screenheight)
love.graphics.line(screenwidth - 100, 0, screenwidth - 100, screenheight)
love.graphics.line(0, 100, screenwidth, 100)
love.graphics.line(0, screenheight - 100, screenwidth, screenheight - 100)
love.graphics.setColor(1, 1, 1, 1)
end
scale = scale / GetScaleByScreen()
if gamestate ~= "pause" and gamestate ~= "map settings" and gamestate ~= "assist mode" then
love.graphics.setColor(1, 1, 1, (360%(math.min(math.max(leveltime, 240), 360))/120))
else
love.graphics.setColor(1, 1, 1, 0)
end
love.graphics.setShader()
love.graphics.printf(gamemapname, 0, 50, screenwidth/2, "center", 0, 2, 2)
love.graphics.setColor(1, 1, 1, 1)
love.graphics.setShader()
if wheelmoved > 0 and mouse.mode == "camera" then
love.graphics.setColor(1, 1, 1, ((math.min(math.max(wheelmoved, 0), 60)%120)/60))
love.graphics.printf("scale: "..scale, 0, screenheight-20, screenwidth, "center")
wheelmoved = wheelmoved-1
love.graphics.setColor(1, 1, 1, 1)
end
end
local hudcoin = love.graphics.newImage("Sprites/hudcoin.png")
local hudcoinquads = {
notgot = love.graphics.newQuad(1, 1, 8, 8, 40, 10),
got = love.graphics.newQuad(11, 1, 8, 8, 40, 10),
brightnotgot = love.graphics.newQuad(21, 1, 8, 8, 40, 10),
brightgot = love.graphics.newQuad(31, 1, 8, 8, 40, 10),
}
local icons = love.graphics.newImage("Sprites/icons.png")
local iconsquads = GetQuads(4, icons)
local brownie = love.graphics.newImage("Sprites/brownie.png")
local girl = love.graphics.newImage("Sprites/girl.png")
local function DrawMenu(gs, prev)
if not prev then
menuButtons = {}
end
local gamestate = gs or gamestate
if gamestate ~= laststate and statetimer < 0.999 then
love.graphics.translate(0, screenwidth - ((1 -statetimer) * screenwidth))
DrawMenu(laststate, true)
love.graphics.origin()
love.graphics.translate(0, (1 - statetimer) * screenwidth)
end
local wave
if gamestate == "title" or gamestate == "select level" then
wave = math.abs(math.sin(love.timer.getTime()))
end
if gamestate == "title" then
love.graphics.draw(titlescreen, (screenwidth / 2) - 150, 50)
love.graphics.setColor(1, 1, 1, wave)
love.graphics.draw(titleglow, (screenwidth / 2) - 150, 50)
love.graphics.setColor(1, 1, 1, 1)
else
love.graphics.printf(gamestate, 0, 50, screenwidth/2, "center", 0, 2, 2)
end
local ly = 140
local x = (screenwidth/2)-225
for i = 1,#menu[gamestate] do
love.graphics.setColor(1, 1, 1, 1)
if i == pointer then love.graphics.setColor(1, 1, 0, 1)
elseif (gamestate == "select level" and i > lastmap and tonumber(menu[gamestate][i].name))
or (gamestate == "assist mode" and menu[gamestate][1].value == 0 and i > 1 and i < #menu[gamestate]) then
love.graphics.setColor(1, 1, 1, 0.5)
elseif gamestate == "settings" and i == #menu.settings-1 then
love.graphics.setColor(1, 0, 0, 1)
end
local rectangle = screenwidth
local y = (((#menu[gamestate] > 7 or (gamestate == "sound test" and i == 1)) and 200) or 290)+(30*(i-1))
if #menu[gamestate] == 1 or (gamestate == "sound test" and i == 2) then
y = 480
end
local value = menu[gamestate][i].value
if value then
rectangle = screenwidth-screenwidth/8
local text = (i == pointer and "< "..menu[gamestate][i].values[value].." >") or menu[gamestate][i].values[value]
love.graphics.printf(text, 0, y, screenwidth+screenwidth/5, "center")
end
if gamestate ~= "select level" then
local name = menu[gamestate][i].name
if (menu[gamestate][i].string or menu[gamestate][i].int) then
name = name..(menu[gamestate][i].string or menu[gamestate][i].int)
end
if i == pointer and ((menu[gamestate][i].string and menu[gamestate][i].string:len() < 20)
or (menu[gamestate][i].int and menu[gamestate][i].int:len() < 2)) then
name = name.."_"
end
local width = font:getWidth(name);
local x = rectangle / 2 - width / 2
if not prev then
menuButtons[i] = {x = x, y = y, width = x + width, height = y + font:getHeight()}
if debugmode and debugmode.buttons then
love.graphics.rectangle("line", x, y, width, font:getHeight())
end
end
(i == pointer and AnimatedPrint or love.graphics.print)(name, x, y)
else
local unit = GetUnit(i)-1
local offset = (unit >= 0 and unit) or 9
local x = x+(50*offset)
if i > 10 and GetUnit(i) == 1 then
ly = ly + 50
x = (screenwidth / 2) - 225
end
if menu[gamestate][i].name == "back" then
local x = screenwidth / 2 - 24
(i == pointer and AnimatedPrint or love.graphics.print)("back", x, 470)
if not prev then
menuButtons[i] = {x = x, y = 470, width = x + 48, height = 470 + font:getHeight()}
if debugmode and debugmode.buttons then
love.graphics.rectangle("line", x, 470, 48, font:getHeight())
end
end
else
local n = menu[gamestate][i].name
love.graphics.print(n, x, ly)
if not prev then
local width = font:getWidth(n)
menuButtons[i] = {x = x, y = ly, width = x + width, height = ly + font:getHeight()}
if debugmode and debugmode.buttons then
love.graphics.rectangle("line", x, ly, width, font:getHeight())
end
end
local coin = coins[i-1]
if coin then
local quad = (coin.got and "got") or "notgot"
local x = x + font:getWidth(n)
love.graphics.draw(hudcoin, hudcoinquads[quad], x, ly)
love.graphics.setColor(1, 1, 1, 1 - wave)
love.graphics.draw(hudcoin, hudcoinquads["bright" .. quad], x, ly)
love.graphics.setColor(1, 1, 1, 1)
end
end
end
end
love.graphics.setColor(1, 1, 1, 1)
end
local function DrawMenuWithBG()
local scale = math.max(screenwidth, screenheight) / 800
local x = screenwidth / (scale * 4) - 200
local y = screenheight / scale - 600
love.graphics.draw(girl, x, y, 0, scale)
love.graphics.draw(brownie, x + screenwidth / 2, y, 0, scale)
DrawMenu()
end
local function DrawCoinHud(time)
local coinsgot, coinstotal = coins.count()
if coinstotal == 0 then return end
love.graphics.draw(coins.sprite, coins.quads[math.floor((time%(#coins.quads*10))/10)+1], 10, screenheight-50)
love.graphics.print(coinsgot.."/"..coinstotal, 50, screenheight-40)
end
local function DrawFlash()
if menu.settings[7].value == 1 and flash > 0 then
love.graphics.setColor(1, 1, 1, flash)
love.graphics.rectangle("fill", 0, 0, screenwidth, screenheight)
love.graphics.setColor(1, 1, 1, 1)
end
end
local wallDesc = "\nMost objects can't walk in this tile"
local floorDesc = "\nObjects can walk in this tile"
local pushDesc = "\nObjects in this tile will be pushed to the "
local falsepushDesc = "\nThis tile will do nothing, use the first frame of the pusher"
local spikeDesc = "\nObjects in this tile will be destroyed"
local function MirrorUpdate(x, y)
if SearchObject(x, y) == player then
sound.playSound("box.wav")
if y == 15 then
tilemap[15][30] = TILE_FLOOR1
tilemap[6][2] = TILE_FLOOR1
tilemap[6][30] = TILE_CUSTOM3
tilemap[15][14] = TILE_CUSTOM3
tilemap[15][2] = TILE_FLOOR1
tilemap[15][18] = TILE_BLUESWITCH
tilemap[6][18] = TILE_RIGHTPUSHER1
tilemap[11][5] = TILE_SPIKEOFF
tilemap[11][11] = TILE_SPIKEOFF
tilemap[11][21] = TILE_SPIKEOFF
tilemap[11][27] = TILE_SPIKEOFF
tilemap[6][14] = TILE_SLIME
tilemap[7][30] = TILE_UPPUSHER1
CheckMap(TILE_REDWALLON, TILE_REDWALLOFF, TILE_BLUEWALLOFF, TILE_BLUEWALLON)
UpdateTilemap()
elseif y == 6 then
tilemap[6][30] = TILE_FLOOR1
tilemap[15][14] = TILE_FLOOR1
tilemap[15][18] = TILE_FLOOR1
tilemap[6][18] = TILE_FLOOR1
tilemap[7][8] = TILE_SLIME
tilemap[6][14] = TILE_FLOOR1
tilemap[7][30] = TILE_FLOOR1
tilemap[7][14] = TILE_LEFTPUSHER1
tilemap[13][24] = TILE_CUSTOM3
tilemap[14][8] = TILE_CUSTOM3
UpdateTilemap()
elseif y == 13 then
tilemap[7][8] = TILE_FLOOR1
tilemap[7][14] = TILE_FLOOR1
tilemap[13][24] = TILE_FLOOR1
tilemap[14][8] = TILE_FLOOR1
tilemap[5][24] = TILE_FLOOR1
tilemap[5][8] = TILE_FLOOR1
UpdateTilemap()
sound.playSound("lock.wav")
end
return true
end
end
tilesets = {
["bonus.png"] = { --BONUS LEVELS
enemyquadtype = "none",
rotatebridges = false,
description = {
[TILE_CUSTOM1] = "BUTTON\nyou aren't supposed to use this tileset btw",
[TILE_CUSTOM2] = "CUSTOM GOAL\nif you just like the tiles I suggest you copy\nthe .png file from the .exe",
[TILE_CUSTOM3] = "BUTTON?\nbut you're probably reading this from the source code, aren't you?"
},
collision = {
[TILE_CUSTOM1] = function(mo, momx, momy)
if momx == 0 and momy == 0 then return end
if gamemap == -4 then
for x = 10, 14 do
SearchObject(x, 4).hp = 1
end
local readersprite = "Sprites/Bonuses/reader.png"
local posmo = SpawnObject(readersprite, 10, 4, "dummy")
SpawnObject(readersprite, 4, 12, "bfreader", nil, nil, nil, 0).var1 = posmo.key
elseif gamemap == -5 then
if mo.x == 13 and mo.y == 5 then
local correct = {2, 2, 1, 2, 2, 2, 1, 2, 1, 1, 1, 2, 2, 1, 2, 1}
for _, mmo in ipairs(objects) do
if ffi.string(mmo.type) == "bimonitor" then
local t = table.remove(correct)
if mmo.frame ~= t then
notification.setMessage("Wrong combination...")
return
end
end
end
SetTile(13, 4, TILE_FLOOR1)
sound.playSound("lock.wav")
elseif mo.x == 4 and mo.y == 21 then
local monitor = SearchObject(4, 20)
if monitor.frame == 7 then
RemoveObject(monitor)
SetTile(4, 21, TILE_FLOOR1)
messagebox.setMessage("Main riddle hint #1", "The first number is just half of this line's words.\nFor the second number just add 2 to this monitor.")
else
notification.setMessage("Wrong number...")
end
elseif mo.x == 22 and mo.y == 32 then
local monitor = SearchObject(22, 31)
if monitor.frame == 9 then
RemoveObject(monitor)
SetTile(22, 32, TILE_FLOOR1)
messagebox.setMessage("Main riddle hint #2", "The last 2 numbers are both B.")
else
notification.setMessage("Wrong number...")
end
end
elseif gamemap == -6 and mo == player then
objects[4].frame = 10
sound.playSound("box.wav")
end
end,
[TILE_CUSTOM2] = function()
gamestate = "bonus level complete!"
pointer = 1
sound.playSound("win.wav")
end,
[TILE_CUSTOM3] = function(mo)
if gamemap == -1 then
mo.x = math.abs(mo.x - 22) + mo.momx
sound.playSound("box.wav")
elseif gamemap == -3 then
if mo == player or (mo.momx == 0 and mo.momy == 0) then return end
IterateMap(TILE_CUSTOM3, MirrorUpdate)
elseif gamemap == -5 then
if mo.x == 22 and mo.y == 20 then
messagebox.setMessage("Left riddle hint", "It blinks and doesn't stop\nSurely you have counted\nHow many times it's here?")
elseif mo.x == 4 and mo.y == 31 then
messagebox.setMessage("Right riddle hint", "It fades away every time\nbut only now changed shape\nyou'll have to run!")
gamemapname = "8"
end
elseif gamemap == -6 then
local line = tilemap[5]
line[9] = TILE_DOWNPUSHER1
line[10] = TILE_DOWNPUSHER1
line[11] = TILE_DOWNPUSHER1
line[12] = TILE_DOWNPUSHER1
line[13] = TILE_DOWNPUSHER1
line[14] = TILE_DOWNPUSHER1
tilemap[18][7] = TILE_DOWNPUSHER1
objects[4].frame = 10
UpdateTilemap()
sound.playSound("lock.wav")
end
end,
},
tile = {
[TILE_CUSTOM1] = nil,
[TILE_CUSTOM2] = nil,
[TILE_CUSTOM3] = nil
}
},
["forest.png"] = { --CHAPTER 1
bridgeshardcolor = {0.7, 0.4, 0.1},
description = {
[TILE_CUSTOM1] = "UNUSED"..floorDesc,
[TILE_CUSTOM2] = "UNUSED"..floorDesc,
[TILE_CUSTOM3] = "UNUSED"..floorDesc
},
collision = {
[TILE_CUSTOM1] = true,
[TILE_CUSTOM2] = true,
[TILE_CUSTOM3] = true
},
tile = {
[TILE_CUSTOM1] = nil,
[TILE_CUSTOM2] = nil,
[TILE_CUSTOM3] = nil
}
},
["frost.png"] = { --CHAPTER 2
snow = true,
enemyquadtype = "movement",
keysprite = "Sprites/Chapter 2/key.png",
bridgeshardcolor = {0.7, 0.7, 0.7},
description = {
[TILE_CUSTOM1] = "SNOWBALL".."\nA Snowball will spawn in this tile",
[TILE_CUSTOM2] = "STICKS WALL"..wallDesc.."\nIf a Snowball rams this wall it will collapse",
[TILE_CUSTOM3] = "SNOWMAN".."\nA Snowman will spawn in this tile"
},
collision = {
[TILE_CUSTOM1] = true,
[TILE_CUSTOM2] = function(mo)
if mo.type == "snowball" then
SetTile(mo.x, mo.y, TILE_FLOOR3)
RemoveObject(mo)
else return false end
end,
[TILE_CUSTOM3] = true
},
tile = {
[TILE_CUSTOM1] = function(x, y)
local snowsprite = "Sprites/Chapter 2/snowball.png"
SpawnObject(snowsprite, x, y, "snowball", GetQuads(4, snowsprite), "position")
SetTile(x, y, TILE_FLOOR3)
end,
[TILE_CUSTOM2] = nil,
[TILE_CUSTOM3] = function(x, y)
local snowmansprite = "Sprites/Chapter 2/snowman.png"
SpawnObject(snowmansprite, x, y, "snowman", GetDirectionalQuads(snowmansprite))
SetTile(x, y, TILE_FLOOR3)
end,
}
},
["castle.png"] = { --CHAPTER 3
thunder = true,
rain = {0.3, 0.5, 0.54, 1},
enemyquadtype = "movement",
keysprite = "Sprites/Chapter 3/key.png",
description = {
[TILE_CUSTOM1] = "+15\nAdds 15 seconds to the timer",
[TILE_CUSTOM2] = "BOX\nWill spawn a pushable box in this tile",
[TILE_CUSTOM3] = "BOX CONTAINER\nIf all of these tiles are covered by boxes the level will be completed"
},
collision = {
[TILE_CUSTOM1] = true,
[TILE_CUSTOM2] = true,
[TILE_CUSTOM3] = function(mo)
if mo.type == "box" and mo.var2 then
mo.var2 = false
sound.playSound("box.wav")
local all = true
IterateMap(TILE_CUSTOM3, function(x, y)
local mo = SearchObject(x, y)
if not mo or mo.type ~= "box" then all = false end
end)
if all then EndLevel() end
end
end
},
tile = {
[TILE_CUSTOM1] = function(x, y)
timer = timer + 15
SetTile(x, y, TILE_FLOOR1)
end,
[TILE_CUSTOM2] = function(x, y)
local boxsprite = "Sprites/Chapter 3/box.png"
SpawnObject(boxsprite, x, y, "box", GetQuads(5, boxsprite), "hp", nil, 5)
SetTile(x, y, TILE_FLOOR2)
end,
[TILE_CUSTOM3] = nil
}
},
["factory.png"] = { --CHAPTER 4
dark = true,
bridgeshardcolor = {0.6, 0.6, 0.6},
keysprite = "Sprites/Chapter 4/key.png",
description = {
[TILE_CUSTOM1] = "MASTER BUTTON\nPressing all of the red ones will open all locks\npressing a blue one will reset them all",
[TILE_CUSTOM2] = "METAL BOX\nCan be pushed by the player and will break any miniman or spikes it finds.",
[TILE_CUSTOM3] = "MINIMAN\nSpawns a miniman which will constantly fire when the player is in range"
},
collision = {
[TILE_CUSTOM1] = true,
[TILE_CUSTOM2] = true,
[TILE_CUSTOM3] = true
},
tile = {
[TILE_CUSTOM1] = function(x, y)
local masterbuttonsprite = "Sprites/Chapter 4/master button.png"
SpawnObject(masterbuttonsprite, x, y, "masterbutton", GetQuads(3, masterbuttonsprite), "frame")
end,
[TILE_CUSTOM2] = function(x, y)
SpawnObject("Sprites/Chapter 4/metal box.png", x, y, "metalbox")
SetTile(x, y, TILE_FLOOR2)
end,
[TILE_CUSTOM3] = function(x, y)
local minimansprite = "Sprites/Chapter 4/miniman.png"
SpawnObject(minimansprite, x, y, "miniman", GetDirectionalQuads(minimansprite))
SetTile(x, y, TILE_FLOOR1)
end
}
},
["superdark.png"] = { --SUPERDARK SECRET ROOM
dark = true,
description = {
[TILE_CUSTOM1] = "You should not use this tileset.",
[TILE_CUSTOM2] = "Just use factory.png",
[TILE_CUSTOM3] = "But you're probably reading this from the source code though, right?"
},
collision = {
[TILE_CUSTOM1] = true,
[TILE_CUSTOM2] = true,
[TILE_CUSTOM3] = function(mo)
local superdark = menu.extras[EXTRA_SUPERDARK]
superdark.name = "superdark"
superdark.value = 0
superdark.values = valuesnames
tilemap[mo.y][mo.x] = TILE_CUSTOM2
sound.playSound("lock.wav")
messagebox.setMessage("SuperDark mode unlocked!", [[
When enabled superdark mode will make all levels much darker
It will be impossible to see far away
Good luck!
(SuperDark mode can be enabled in the extras menu)]])
end
},
tile = {
[TILE_CUSTOM1] = function(x, y)
local masterbuttonsprite = "Sprites/Chapter 4/master button.png"
SpawnObject(masterbuttonsprite, x, y, "masterbutton", GetQuads(3, masterbuttonsprite), "frame")
end,
[TILE_CUSTOM2] = nil,
[TILE_CUSTOM3] = function(x, y)
if menu.extras[EXTRA_SUPERDARK].name == "superdark" then
SetTile(x, y, TILE_CUSTOM2)
end
end
}
}
}
local tileDescriptions = {
[TILE_WALL1] = "WALL 1"..wallDesc,
[TILE_WALL2] = "WALL 2"..wallDesc,
[TILE_WALL3] = "WALL 3"..wallDesc,
[TILE_WALL4] = "WALL 4"..wallDesc,
[TILE_WALL5] = "WALL 5"..wallDesc,
[TILE_WALL6] = "WALL 6"..wallDesc,
[TILE_WALL7] = "WALL 7"..wallDesc,
[TILE_WALL8] = "WALL 8"..wallDesc,
[TILE_WALL9] = "WALL 9"..wallDesc,
[TILE_FLOOR1] = "FLOOR 1"..floorDesc,
[TILE_FLOOR2] = "FLOOR 2"..floorDesc,
[TILE_FLOOR3] = "FLOOR 3"..floorDesc,
[TILE_LOCK] = "LOCK"..floorDesc.." if the lock is open\nA key is needed to open the lock",
[TILE_KEY] = "KEY\nA key will spawn in this tile"..floorDesc,
[TILE_REDSWITCH] = "RED SWITCH"..floorDesc.."\nIf pressed will turn on the blue tiles and turn off the red ones",
[TILE_BLUESWITCH] = "BLUE SWITCH"..floorDesc.."\nIf pressed will turn on the red tiles and turn off the blue ones",
[TILE_START] = "START"..floorDesc..", The player will spawn in this tile\nevery map should have 1 start tile",