-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathobjects.lua
1022 lines (946 loc) · 28.2 KB
/
objects.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local sound = require "music"
local particles = require "particles"
local coins = require "coins"
local ffi = require "ffi"
local discord = require "discordRPC"
local cutscenes = require "cutscenes"
-- DIRECTIONAL OBJECT SPRITE STRUCTURE
-- 1 2 LEFT
-- 3 4 RIGHT
-- 5 6 UP
-- 7 8 DOWN
DIR_LEFT = 1
DIR_RIGHT = 3
DIR_UP = 5
DIR_DOWN = 7
objects = {}
voids = {}
collisions = {}
thinkers = {}
local MakeObject = ffi.typeof("gameobject")
local MakePlayerObject = ffi.typeof("playerobject")
---@class gameobject
---@field quads number
---@field key integer
---@field char string
---@field quadtype string
---@field type string
---@field hp integer
---@field x integer
---@field y integer
---@field direction integer
---@field var1 integer
---@field frame integer
---@field var2 boolean
---@field lastaxis boolean
---@field momx number
---@field momy number
---@class playerobject: gameobject
---@field ftime integer
---@field bosskey integer
---@field fmomx number
---@field fmomy number
---@return gameobject | playerobject
function SpawnObject(sprite, x, y, type, quads, quadtype, direction, hp)
if not collisions[type] then error('object type "'..type..'" does not exist!') end
quadtype = (quadtype and quadtype) or (not quads and "none") or (hp and "hp") or (#quads == 1 and "single") or (#quads == 8 and "directions") or "default"
local key = (#voids > 0 and table.remove(voids) or #objects + 1)
local newobject = (type == "player" and MakePlayerObject or MakeObject)(quads and CacheQuadArray(quads) or 0, key, sprite, quadtype, type, hp or 1, x, y, direction or DIR_LEFT, 0, 1, false, false, 0, 0)
objects[key] = newobject
return newobject --[[@as gameobject | playerobject]]
end
function RemoveObject(mo, soundname)
objects[mo.key] = nil
table.insert(voids, mo.key)
soundname = (type(soundname) == "string" and soundname) or nil
soundname = (not soundname and ((mo == player and "heartbreak"..love.math.random(1, 2)..".wav") or "boom.wav")) or soundname
if mo == player then
if tilesets[tilesetname].dark or menu.extras[EXTRA_SUPERDARK].value == 1 then
local tilesize = math.floor(32 * scale * GetScaleByScreen())
local playerx = GetStartX() + player.x * tilesize + tilesize / 2
local playery = GetStartY() + player.y * tilesize + tilesize / 2
playerx, playery = love.graphics.transformPoint(playerx, playery)
darkshader:send("pos", {playerx, playery})
darkshader:send("scale", scale)
end
particles.spawnShards(player.x, player.y, 1)
darkness = 0
player = nil
else particles.spawnShards(mo.x, mo.y, 0.5) end
sound.playSound(soundname)
end
function RemoveMovingObject(mo, momx, momy)
momx = momx or mo.momx
momy = momy or mo.momy
if momx and momy and momx == 0 and momy == 0 then return end
RemoveObject(mo)
end
function RemoveStandingObject(mo, momx, momy)
momx = momx or mo.momx
momy = momy or mo.momy
if momx == 0 and momy == 0 then RemoveObject(mo) end
end
function RemoveCollidedObject(_, obstmo)
RemoveObject(obstmo)
end
function RemovePlayer(mo, obstmo)
local assist = AssistControl(5)
if assist == 0 then
RemoveObject(mo)
elseif assist == 2 then
RemoveObject(obstmo)
end
end
function RemoveCollidedPlayer(mo, obstmo)
local assist = AssistControl(5)
if assist == 0 then
RemoveObject(obstmo)
elseif assist == 2 then
RemoveObject(mo)
end
end
function EraseObject(mo)
objects[mo.key] = nil
table.insert(voids, mo.key)
if mo.type == "player" then player = nil end
end
function DamageObject(mo, amount)
mo.hp = mo.hp - (amount or 1)
if mo.hp <= 0 then
RemoveObject(mo)
return true
end
return false
end
local function RedSwitch(mo, momx, momy)
if momx == 0 and momy == 0 then return end
CheckMap(TILE_REDSWITCH, TILE_BLUESWITCH, TILE_REDWALLON, TILE_REDWALLOFF, TILE_BLUEWALLOFF, TILE_BLUEWALLON)
sound.playSound("door.wav")
end
local function BlueSwitch(mo, momx, momy)
if momx == 0 and momy == 0 then return end
CheckMap(TILE_BLUESWITCH, TILE_REDSWITCH, TILE_BLUEWALLON, TILE_BLUEWALLOFF, TILE_REDWALLOFF, TILE_REDWALLON)
sound.playSound("door.wav")
end
local function CrackBridge(mo)
local x = mo.x
local y = mo.y
SetTile(x, y, tilemap[y][x] == TILE_BRIDGE_ROTATED and TILE_CRACKEDBRIDGE_ROTATED or TILE_CRACKEDBRIDGE)
end
function IsBridge(tile)
return tile == TILE_BRIDGE or tile == TILE_CRACKEDBRIDGE or tile == TILE_BRIDGE_ROTATED or tile == TILE_CRACKEDBRIDGE_ROTATED
end
local function DestroyBridge(mo, momx, momy)
if momx == 0 and momy == 0 then return end
local x = mo.x
local y = mo.y
tilemap[y][x] = TILE_EMPTY
if tilemap[y + 1][x] then
if tilemap[y + 1][x] == TILE_CHASM2 then
tilemap[y + 1][x] = TILE_EMPTY
particles.spawnBridgeShards(mo.x, mo.y, 6)
particles.spawnBridgeShards(mo.x, mo.y + 1, 6, 0.2)
else
particles.spawnBridgeShards(mo.x, mo.y, 12)
end
end
local uppertile = tilemap[mo.y - 1][mo.x]
local isBridge = IsBridge(uppertile)
if uppertile and uppertile ~= TILE_EMPTY and (not isBridge) and uppertile ~= TILE_CHASM1 and uppertile ~= TILE_CHASM2 then
tilemap[y][x] = TILE_CHASM1
elseif uppertile and isBridge then
tilemap[y][x] = TILE_CHASM2
end
UpdateTilemap()
end
function StopObject(mo, momx, momy)
momx = momx or mo.momx
momy = momy or mo.momy
if momx == 0 and momy == 0 then return end
mo.momx = 0
mo.momy = 0
end
function PusherCheck(mo)
local mopos = tilemap[mo.y][mo.x]
if mopos == TILE_EMPTY or mopos == TILE_CHASM1 or mopos == TILE_CHASM2 then
RemoveObject(mo)
end
return false
end
function PushObject(_, obstmo, momx, momy)
obstmo.lastaxis = (momx ~= 0 and true) or false
PusherCheck(obstmo)
if not TryMove(obstmo, momx, momy) then return false end
end
function SlowPushObject(mo, obstmo, momx, momy)
obstmo.momx = momx/1.4
obstmo.momy = momy/1.4
obstmo.lastaxis = (momx ~= 0 and true) or false
PusherCheck(mo)
return false
end
function SearchObject(x, y, notmo)
for _, mo in pairs(objects) do
if mo.x == x and mo.y == y and mo ~= notmo then return mo end
end
end
local predicting = false
function TryMove(mo, momx, momy)
if not mo then return end
momx = GetTrueMomentum(momx)
momy = GetTrueMomentum(momy)
local moCollisions = collisions[ffi.string(mo.type)]
local tilesetCollisions = tilesets[tilesetname].collision
moCollisions[TILE_CUSTOM1] = tilesetCollisions[TILE_CUSTOM1]
moCollisions[TILE_CUSTOM2] = tilesetCollisions[TILE_CUSTOM2]
moCollisions[TILE_CUSTOM3] = tilesetCollisions[TILE_CUSTOM3]
local sgamemap = gamemap
if tilemap[mo.y+momy] and moCollisions[tilemap[mo.y+momy][mo.x+momx]] then
local obstmo = SearchObject(mo.x+momx, mo.y+momy, mo)
if (debugmode and debugmode.noclip) or predicting then obstmo = nil end
if obstmo then
local obstmoType = ffi.string(obstmo.type)
local obstmoCollisions = collisions[obstmoType]
obstmoCollisions[TILE_CUSTOM1] = tilesetCollisions[TILE_CUSTOM1]
obstmoCollisions[TILE_CUSTOM2] = tilesetCollisions[TILE_CUSTOM2]
obstmoCollisions[TILE_CUSTOM3] = tilesetCollisions[TILE_CUSTOM3]
local collision = moCollisions[obstmoType]
if not collision then return false end
local check
if type(collision) == "function" then
check = collision(mo, obstmo, momx, momy)
else
check = collision == nil and true or collision
end
if check == true then
mo.y = mo.y+momy
mo.x = mo.x+momx
return true
end
if check ~= nil then return check end
end
if sgamemap ~= gamemap then return false end
mo.y = mo.y+momy
mo.x = mo.x+momx
local tile = tilemap[mo.y][mo.x]
if tile >= 50 then tile = tile - 10 end
if type(moCollisions[tile]) == "function" and not predicting then
local check = moCollisions[tile](mo, momx, momy)
if check == false and mo then
mo.y = mo.y-momy
mo.x = mo.x-momx
return false
end
end
return true
end
return false
end
function PredictMove(mo, momx, momy)
if predicting then return false end
predicting = true
local oldx = mo.x
local oldy = mo.y
local check = TryMove(mo, momx, momy)
mo.x = oldx
mo.y = oldy
predicting = false
return check
end
local function ThrustObject(mo, thrustx, thrusty)
if not PredictMove(mo, thrustx, thrusty) then StopObject(mo) return end
local obstmo = SearchObject(mo.x + GetTrueMomentum(thrustx), mo.y + GetTrueMomentum(thrusty))
if obstmo then
local collision = collisions[ffi.string(mo.type)][ffi.string(obstmo.type)]
if not collision then StopObject(mo) return end
local check = collision(mo, obstmo, thrustx, thrusty)
if not check then StopObject(mo) return end
end
mo.momx = thrustx
mo.momy = thrusty
mo.lastaxis = (thrustx ~= 0 and true) or false
end
local directionToMomentum = {
[DIR_RIGHT] = {momx = 1, momy = 0},
[DIR_DOWN] = {momx = 0, momy = 1},
[DIR_LEFT] = {momx = -1, momy = 0},
[DIR_UP] = {momx = 0, momy = -1}
}
function DirectionMomentum(direction)
return directionToMomentum[direction].momx, directionToMomentum[direction].momy
end
function MomentumDirection(checkx, checky)
for k,v in pairs(directionToMomentum) do
if v.momx == checkx and v.momy == checky then
return k
end
end
end
function GetTrueMomentum(mom)
return (mom > 0 and math.ceil(mom)) or math.floor(mom)
end
function GetDistance(mo1, mo2)
return mo1.x-mo2.x, mo1.y-mo2.y
end
function DashObject(mo)
mo.momx, mo.momy = DirectionMomentum(mo.direction)
end
function FireShot(mo, sprite, quads, type)
local assist = AssistControl(6) / 10
if assist == 0 then return end
local bullet = SpawnObject(sprite, mo.x, mo.y, type or "bullet", quads, nil, mo.direction)
DashObject(bullet)
bullet.momx = bullet.momx * assist
bullet.momy = bullet.momy * assist
sound.playSound("bullet.wav")
return bullet
end
function FacePlayer(mo)
local distx, disty = GetDistance(mo, player)
local py = (disty/math.abs(disty))*-1
local px = (distx/math.abs(distx))*-1
local moCollisions = collisions[ffi.string(mo.type)]
if ((distx ~= 0 and distx < disty and moCollisions[tilemap[mo.y][mo.x-distx]])
or (disty == 0 or not moCollisions[tilemap[mo.y+py][mo.x]])) and moCollisions[tilemap[mo.y][mo.x+px]] then
mo.direction = MomentumDirection(px, 0) or DIR_LEFT
else
mo.direction = MomentumDirection(0, py) or DIR_LEFT
end
end
function EndLevel()
if not customEnv and (lastmap % 10) == 0 and gamemap == lastmap - 1 and menu.settings[8].value == 1 then
cutscenes.setCutscene(lastmap / 10 + 1)
gamestate = "chaptercomplete"
gamemapname = "chapter complete"
leveltime = 0
notification.setMessage("Unlocked new cutscene")
return
end
gamemap = gamemap + 1
if gamemap == lastmap then
sound.checkUnlocks(1)
end
local prevlastmap = lastmap
lastmap = math.max(gamemap + 1, lastmap)
if lastmap > prevlastmap then StartSaving() end
if gamemap == #menu["select level"] - 1 then
pointer = 1
gamestate = "the end"
sound.reset()
sound.stopMusic()
discord.updatePresence(discord.menu)
return
end
local errorcheck = LoadMap("map"..GetMapNum(gamemap)..".map")
if errorcheck and errorcheck == "error" then
gamemap = gamemap - 1
messagebox.setMessage("Failed to load next map!", "The current map was reloaded instead", true)
local errorcheck2 = LoadMap("map"..GetMapNum(gamemap)..".map")
if errorcheck2 and errorcheck2 == "error" then
local finalcheck = LoadMap("map00.map")
messagebox.setMessage("Failed to load next or current map!", "as a last ditch effort map00.map was loaded\nsomething must really be broken...", true)
if finalcheck and finalcheck == "error" then
error("Could not find a map to load\nthe Maps folder may be corrupted, reinstall the game and replace it.")
end
end
end
sound.reset()
sound.playSound("win.wav")
discord.updateGamePresence()
end
local defaultCollisions = {
__index = {
[TILE_EMPTY] = RemoveMovingObject,
[TILE_FLOOR1] = true,
[TILE_FLOOR2] = true,
[TILE_FLOOR3] = true,
[TILE_KEY] = true,
[TILE_REDSWITCH] = RedSwitch,
[TILE_BLUESWITCH] = BlueSwitch,
[TILE_START] = true,
[TILE_GOAL] = true,
[TILE_REDWALLOFF] = true,
[TILE_BLUEWALLOFF] = true,
[TILE_AFLOOR1] = true,
[TILE_AFLOOR2] = true,
[TILE_RIGHTPUSHER1] = function(mo) ThrustObject(mo, 1, 0) return true end,
[TILE_LEFTPUSHER1] = function(mo) ThrustObject(mo, -1, 0) return true end,
[TILE_UPPUSHER1] = function(mo) ThrustObject(mo, 0, -1) return true end,
[TILE_DOWNPUSHER1] = function(mo) ThrustObject(mo, 0, 1) return true end,
[TILE_SPIKEON] = RemoveObject,
[TILE_SPIKEOFF] = true,
[TILE_SPIKE] = RemoveObject,
[TILE_BRIDGE] = CrackBridge,
[TILE_CRACKEDBRIDGE] = DestroyBridge,
[TILE_SLIME] = StopObject,
[TILE_CHASM1] = RemoveMovingObject,
[TILE_CHASM2] = RemoveMovingObject,
[TILE_ENEMY] = true,
[TILE_BRIDGE_ROTATED] = CrackBridge,
[TILE_CRACKEDBRIDGE_ROTATED] = DestroyBridge
}
}
function AddObjectType(typename, collision, thinker)
CheckArgument(1, "AddObjectType", typename, "string")
if collisions[typename] then error('object type "'..typename..'" already exists!') end
collisions[typename] = setmetatable(collision or {}, defaultCollisions)
if type(thinker) == "function" then thinkers[typename] = thinker end
end
----OBJECT DEFINITIONS
---MISC
--PLAYER
local function ResetButtons(x, y)
local button = SearchObject(x, y)
button.frame = 1
end
local function PressButton(mo, obstmo, momx, momy)
local frame = obstmo.frame
if (mo.momx == 0 and mo.momy == 0) or (momx == 0 and momy == 0) or frame == 3 then return end
sound.playSound("button.wav")
if frame == 2 then
sound.playSound("button_off.wav")
IterateMap(TILE_CUSTOM1, ResetButtons)
return true
elseif frame == 1 then
obstmo.frame = 2
local check = true
local buttons = {}
IterateMap(TILE_CUSTOM1, function(x, y)
local button = SearchObject(x, y)
if button.frame == 1 then
check = false
return true
end
table.insert(buttons, button)
end)
if check then
CheckMap(TILE_LOCK, TILE_FLOOR2)
for _, button in ipairs(buttons) do button.frame = 3 end
sound.playSound("lock.wav")
end
return true
end
end
AddObjectType("player", {
[TILE_GOAL] = EndLevel,
[TILE_SUPERDARK] = function()
gamemap = -99
RestartMap()
discord.updateGamePresence()
end,
coin = function(_, obstmo)
coins.hudtimer = 160
coins[gamemap].got = true
sound.playSound("coin.wav")
particles.spawnStars(obstmo.x, obstmo.y)
EraseObject(obstmo)
if not customEnv then
local coinsgot, coinstotal = coins.count()
if coinsgot == 2 then
menu.extras[EXTRA_THEATER].name = "theater"
messagebox.setMessage("theater unlocked!", [[
Every cutscene watched will be unlocked in the theater
Where you can rewatch them whenever you want!
(the theater can be accessed from the extras menu)]])
elseif coinsgot == math.floor(coinstotal / 2) then
local wobble = menu.extras[EXTRA_WOBBLE]
wobble.name = "wobble"
wobble.value = 0
wobble.values = valuesnames
messagebox.setMessage("wobble mode unlocked!", [[
When enabled wobble mode will rotate the map up and down
Making movement much harder!
NOTE: May cause a bit of nausea
Good luck!
(wobble mode can be enabled in the extras menu)]])
elseif coinsgot == coinstotal then
sound.soundtest[#sound.soundtest] = coins.soundtest
menu.extras[EXTRA_BONUSLEVELS].name = "Bonus levels"
notification.setMessage("Unlocked music:\nLovely Bonus")
messagebox.setMessage("Bonus levels unlocked!", [[
Each bonus level has a special unique gimmick!
They are ordered by difficulty, but can be cleared in any order
Good luck!
(The bonus levels can be accessed from the extras menu)]])
end
end
StartSaving()
end,
shadowcoin = function(_, obstmo)
sound.playSound("coin.wav")
particles.spawnStars(obstmo.x, obstmo.y)
EraseObject(obstmo)
end,
key = PushObject,
box = function(_, obstmo, momx, momy)
local check = PushObject(nil, obstmo, momx, momy)
if check == false then
return DamageObject(obstmo)
elseif tilemap[obstmo.y][obstmo.x] == TILE_CUSTOM3 then
obstmo.var2 = true
end
return check
end,
enemy = RemovePlayer,
bullet = RemoveObject,
snowball = SlowPushObject,
snowman = RemovePlayer,
masterbutton = PressButton,
metalbox = PushObject,
miniman = RemovePlayer,
bfmonitor = function(_, obstmo, momx, momy)
if momx == 0 and momy == 0 then return true end
obstmo.hp = math.max((obstmo.hp + 1) % 8, 1)
return true
end,
biylove = function(mo, obstmo, momx, momy)
PushObject(nil, obstmo, momx, momy)
player = nil
mo.momx = 0
mo.momy = 0
end,
biylock = function(_, obstmo, momx, momy)
PushObject(nil, obstmo, momx, momy)
if obstmo.x == 24 and obstmo.y == 6 then
CheckMap(TILE_LOCK, TILE_SLIME)
sound.playSound("box.wav")
end
end,
biyword = PushObject,
biywin = function(_, obstmo, momx, momy)
local check = PushObject(nil, obstmo, momx, momy)
local key = objects[1]
if obstmo.x == 2 and obstmo.y == 5 and key then
EraseObject(key)
SetTile(17, 12, TILE_CUSTOM2)
sound.playSound("box.wav")
end
return check
end,
biybridge = PushObject,
pacdot = function (_, obstmo)
RemoveObject(obstmo, "menu_move.wav")
local gotAll = true;
IterateMap(TILE_FLOOR3, function(x, y)
local mo = SearchObject(x, y)
if mo and mo.type == "pacdot" then
gotAll = false
return true
end
end)
if gotAll then
SetTile(11, 10, TILE_CUSTOM2)
sound.playSound("box.wav")
end
end,
bimonitor = function(_, obstmo, momx, momy)
if momx == 0 and momy == 0 then return true end
obstmo.frame = (obstmo.frame % 2) + 1
return true
end,
numonitor = function(_, obstmo, momx, momy)
if momx == 0 and momy == 0 then return true end
obstmo.frame = math.max((obstmo.frame + 1) % 11, 1)
return true
end,
}, function(mo)
if mo.momx == 0 and mo.momy == 0 and (mo.fmomx ~= 0 or mo.fmomy ~= 0) and mo.ftime > 0 then
mo.momx = mo.fmomx
mo.momy = mo.fmomy
mo.ftime = 0
particles.spawnSmoke(mo.x, mo.y)
return
end
mo.ftime = math.max(mo.ftime - 1, 0)
end)
--COIN
AddObjectType("coin")
--SHADOW COIN
AddObjectType("shadowcoin")
--KEY
AddObjectType("key", {
[TILE_FLOOR1] = StopObject,
[TILE_FLOOR2] = StopObject,
[TILE_FLOOR3] = StopObject,
[TILE_LOCK] = function(mo)
SetTile(mo.x, mo.y, TILE_FLOOR1)
EraseObject(mo)
sound.playSound("lock.wav")
end,
[TILE_KEY] = StopObject,
[TILE_START] = StopObject,
[TILE_GOAL] = StopObject,
[TILE_REDWALLOFF] = StopObject,
[TILE_BLUEWALLOFF] = StopObject,
[TILE_AFLOOR1] = StopObject,
[TILE_AFLOOR2] = StopObject,
[TILE_SPIKEOFF] = StopObject,
[TILE_ENEMY] = StopObject
})
--ENEMY
AddObjectType("enemy", {
player = RemoveCollidedPlayer,
key = PushObject,
box = PusherCheck,
masterbutton = PressButton,
pacdot = true
}, function(mo)
if not player or (mo.momx ~= 0 and mo.momy ~= 0) then return end
local moveinterval = math.ceil(1000 / AssistControl(4))
local time = leveltime % moveinterval
if time == moveinterval - 60 then
FacePlayer(mo)
local tx, ty = DirectionMomentum(mo.direction)
particles.spawnWarning(mo.x + tx, mo.y + ty)
elseif time == 0 then
DashObject(mo)
particles.spawnSmoke(mo.x, mo.y)
end
end)
--BULLET
AddObjectType("bullet", {
[TILE_EMPTY] = true,
[TILE_REDSWITCH] = true,
[TILE_BLUESWITCH] = true,
[TILE_RIGHTPUSHER1] = true,
[TILE_LEFTPUSHER1] = true,
[TILE_UPPUSHER1] = true,
[TILE_DOWNPUSHER1] = true,
[TILE_SPIKEON] = true,
[TILE_SPIKE] = true,
[TILE_BRIDGE] = true,
[TILE_CRACKEDBRIDGE] = true,
[TILE_SLIME] = true,
[TILE_CHASM1] = true,
[TILE_CHASM2] = true,
player = RemoveCollidedObject,
bullet = function(mo, obstmo) RemoveObject(mo) RemoveObject(obstmo) end,
masterbutton = true,
metalbox = RemoveObject
}, RemoveStandingObject)
--DUMMY
AddObjectType("dummy")
---CHAPTER 2
--SNOWBALL
AddObjectType("snowball", {
[TILE_WALL1] = RemoveObject,
[TILE_WALL2] = RemoveObject,
[TILE_WALL3] = RemoveObject,
[TILE_WALL4] = RemoveObject,
[TILE_WALL5] = RemoveObject,
[TILE_WALL6] = RemoveObject,
[TILE_WALL7] = RemoveObject,
[TILE_WALL8] = RemoveObject,
[TILE_WALL9] = RemoveObject,
[TILE_LOCK] = RemoveObject,
[TILE_REDWALLON] = RemoveObject,
[TILE_BLUEWALLON] = RemoveObject,
[TILE_RIGHTPUSHER1] = function(mo) ThrustObject(mo, 0.95, 0) return true end,
[TILE_LEFTPUSHER1] = function(mo) ThrustObject(mo, -0.95, 0) return true end,
[TILE_UPPUSHER1] = function(mo) ThrustObject(mo, 0, -0.95) return true end,
[TILE_DOWNPUSHER1] = function(mo) ThrustObject(mo, 0, 0.95) return true end,
player = PushObject,
coin = true,
shadowcoin = true,
key = PushObject,
enemy = RemoveCollidedObject,
snowball = SlowPushObject,
snowman = RemoveCollidedObject,
})
--SNOWMAN
AddObjectType("snowman", nil, function(mo)
if not player then return end
local fireinterval = math.ceil(1800 / AssistControl(4))
local time = leveltime % fireinterval
if time == 0 then
FireShot(mo, mo.sprite, GetExtraQuad(mo.sprite))
elseif time == fireinterval - 70 then
FacePlayer(mo)
local tx, ty = DirectionMomentum(mo.direction)
particles.spawnWarning(mo.x+tx, mo.y+ty)
end
end)
---CHAPTER 3
--BOX
AddObjectType("box", {
[TILE_FLOOR1] = StopObject,
[TILE_FLOOR2] = StopObject,
[TILE_FLOOR3] = StopObject,
[TILE_KEY] = StopObject,
[TILE_START] = StopObject,
[TILE_GOAL] = StopObject,
[TILE_REDWALLOFF] = StopObject,
[TILE_BLUEWALLOFF] = StopObject,
[TILE_AFLOOR1] = StopObject,
[TILE_AFLOOR2] = StopObject,
[TILE_SPIKEON] = false,
[TILE_SPIKEOFF] = StopObject,
[TILE_SPIKE] = false,
[TILE_ENEMY] = StopObject,
}, function(mo)
if leveltime % 10 > 0 then return end
local tile = tilemap[mo.y][mo.x]
if tile == TILE_SPIKEON or tile == TILE_SPIKE then
DamageObject(mo)
end
end)
---CHAPTER 4
--MASTER BUTTON
AddObjectType("masterbutton")
--METAL BOX
local function DestroySpikes(mo)
SetTile(mo.x, mo.y, TILE_FLOOR2)
sound.playSound("boom.wav")
particles.spawnShards(mo.x, mo.y, 0.5)
end
AddObjectType("metalbox", {
[TILE_FLOOR1] = StopObject,
[TILE_FLOOR2] = StopObject,
[TILE_FLOOR3] = StopObject,
[TILE_KEY] = StopObject,
[TILE_START] = StopObject,
[TILE_GOAL] = StopObject,
[TILE_REDWALLOFF] = StopObject,
[TILE_BLUEWALLOFF] = StopObject,
[TILE_AFLOOR1] = StopObject,
[TILE_AFLOOR2] = StopObject,
[TILE_SPIKEON] = DestroySpikes,
[TILE_SPIKEOFF] = StopObject,
[TILE_SPIKE] = DestroySpikes,
[TILE_ENEMY] = StopObject,
enemy = RemoveCollidedObject,
bullet = RemoveCollidedObject,
miniman = function(mo, obstmo)
RemoveObject(obstmo)
local pmo = SearchObject(obstmo.x, obstmo.y)
if pmo and pmo ~= mo then RemoveObject(pmo) end
end
})
--MINIMAN
AddObjectType("miniman", {metalbox = false}, function(mo)
if not player then return end
if mo.var1 > 0 then mo.var1 = mo.var1 - 1 return end
FacePlayer(mo)
if ((mo.direction == DIR_DOWN or mo.direction == DIR_UP) and mo.x == player.x
or (mo.direction == DIR_LEFT or mo.direction == DIR_RIGHT) and mo.y == player.y)
and PredictMove(mo, DirectionMomentum(mo.direction)) then
FireShot(mo, mo.sprite, GetExtraQuad(mo.sprite))
mo.var1 = math.ceil(30 / AssistControl(4))
end
end)
---BONUS LEVELS
--BRAINFUCK MONITOR
AddObjectType("bfmonitor")
--BRAINFUCK READER
local function EndBrainfuck(mo, posmo)
EraseObject(posmo)
EraseObject(mo)
player.momy = -1
if SearchObject(10, 4).hp == 1 and SearchObject(11, 4).hp == 8 and SearchObject(12, 4).hp == 8 and SearchObject(13, 4).hp == 8 and SearchObject(14, 4).hp == 8 then
if tilemap[16][20] == TILE_LOCK then
SetTile(20, 16, TILE_FLOOR1)
sound.playSound("lock.wav")
end
end
end
local brainfuckOptions = {
function() end,
function(pos)
local monitor = SearchObject(10 + pos, 4)
monitor.hp = math.max((monitor.hp + 1) % 11, 1)
end,
function(pos)
local monitor = SearchObject(10 + pos, 4)
monitor.hp = monitor.hp == 1 and 10 or monitor.hp - 1
end,
function(pos, mo, posmo)
mo.hp = (pos - 1) % 5
posmo.x = 10 + mo.hp
end,
function(pos, mo, posmo)
mo.hp = (pos + 1) % 5
posmo.x = 10 + mo.hp
end,
function(pos, mo, posmo)
if SearchObject(10 + pos, 4).hp == 1 then
local scope = 0
while mo.x < 18 do
mo.x = mo.x + 1
local symbol = SearchObject(mo.x, mo.y).hp
if symbol == 7 then
scope = scope - 1
if scope == -1 then return end
elseif symbol == 6 then scope = scope + 1 end
end
EndBrainfuck(mo, posmo)
end
end,
function(pos, mo, posmo)
if SearchObject(10 + pos, 4).hp ~= 1 then
local scope = 0
while mo.x > 5 do
mo.x = mo.x - 1
local symbol = SearchObject(mo.x, mo.y).hp
if symbol == 6 then
scope = scope - 1
if scope == -1 then return end
elseif symbol == 7 then scope = scope + 1 end
end
EndBrainfuck(mo, posmo)
end
end,
}
AddObjectType("bfreader", nil, function(mo)
if not player then return end
player.momx = 0
player.momy = 0
player.x = 3
player.y = 6
if leveltime % 10 > 0 then return end
mo.x = mo.x + 1
local posmo = objects[mo.var1]
if mo.x == 20 then
EndBrainfuck(mo, posmo)
return
end
brainfuckOptions[SearchObject(mo.x, mo.y).hp](mo.hp, mo, posmo)
end)
--PLAYER CLONE
local function RemoveMovingObjectAndPlayer(mo, momx, momy)
local key = mo.key
RemoveMovingObject(mo, momx, momy)
if not objects[key] and player then RemoveObject(player) end
end
local function RemoveObjectAndPlayer(mo)
RemoveObject(mo)
if player then RemoveObject(player) end
end
AddObjectType("playerclone", {
[TILE_EMPTY] = RemoveMovingObjectAndPlayer,
[TILE_SPIKEON] = RemoveObjectAndPlayer,
[TILE_SPIKEOFF] = true,
[TILE_SPIKE] = RemoveObjectAndPlayer,
[TILE_BRIDGE] = CrackBridge,
[TILE_CRACKEDBRIDGE] = DestroyBridge,
[TILE_SLIME] = StopObject,
[TILE_CHASM1] = RemoveMovingObjectAndPlayer,
[TILE_CHASM2] = RemoveMovingObjectAndPlayer,
[TILE_ENEMY] = true,
}, function(mo)
if not player then RemoveObject(mo) return end
if mo.var2 and player.ftime > 0 and (player.fmomx ~= 0 or player.fmomy ~= 0) and mo.momx == 0 and mo.momy == 0 then
mo.momx, mo.momy = player.fmomx * -1, player.fmomy
particles.spawnSmoke(mo.x, mo.y)
end
mo.var2 = (player.momx == 0 and player.momy == 0)
end)
--BIY STUFF
local BIYCollision = {
[TILE_EMPTY] = StopObject,
[TILE_FLOOR1] = StopObject,
[TILE_FLOOR2] = StopObject,
[TILE_FLOOR3] = StopObject,
[TILE_KEY] = StopObject,
[TILE_START] = StopObject,
[TILE_GOAL] = StopObject,
[TILE_REDWALLOFF] = StopObject,
[TILE_BLUEWALLOFF] = StopObject,
[TILE_AFLOOR1] = StopObject,
[TILE_AFLOOR2] = StopObject,
[TILE_SPIKEON] = StopObject,
[TILE_SPIKEOFF] = StopObject,
[TILE_SPIKE] = StopObject,
[TILE_ENEMY] = StopObject,
[TILE_CHASM1] = StopObject,
[TILE_CHASM2] = StopObject,
biyword = PushObject,
biybridge = PushObject,
biylove = function(_, obstmo, momx, momy)
PushObject(nil, obstmo, momx, momy)
if not player then return end
player = nil
sound.playSound("box.wav")
end,
}
AddObjectType("biylove", BIYCollision)
AddObjectType("biylock", BIYCollision)
AddObjectType("biyword", BIYCollision)
AddObjectType("biywin", BIYCollision)
AddObjectType("biybridge", BIYCollision, function(mo)
if mo.var2 or not player then return end
local is = objects[29]
if not is or is.x ~= 14 or is.y ~= 16 then return end
local slime = objects[28]
if not slime then return end
if mo.x == 13 and mo.y == 16 and slime.x == 15 and slime.y == 16 then
tilemap[11][4] = TILE_SLIME
tilemap[11][5] = TILE_SLIME
tilemap[12][4] = TILE_SLIME
tilemap[12][5] = TILE_SLIME
tilemap[13][4] = TILE_CHASM1
tilemap[13][5] = TILE_CHASM1
UpdateTilemap()
sound.playSound("box.wav")
mo.var2 = true
elseif slime.x == 13 and slime.y == 16 and mo.x == 15 and mo.y == 16 then
CheckMap(TILE_SLIME, TILE_CRACKEDBRIDGE)
sound.playSound("box.wav")
mo.var2 = true
end
end)
--PAC DOT
AddObjectType("pacdot", {
player = function (mo)
RemoveObject(mo, "menu_move.wav")
local gotAll = true;
IterateMap(TILE_FLOOR3, function(x, y)
local mo = SearchObject(x, y)
if mo and mo.type == "pacdot" then
gotAll = false
return true
end
end)
if gotAll then
SetTile(11, 10, TILE_CUSTOM2)
sound.playSound("box.wav")
end
end
})
--RIDDLE MONITORS
AddObjectType("bimonitor")
AddObjectType("numonitor")
--ROTATIONS COUNTER
local function RotateMap()
local newtilemap = {}
for k, row in pairs(tilemap) do
for y = 1, mapheight do
if not newtilemap[y] then newtilemap[y] = {} end
newtilemap[y][mapheight - k + 1] = row[y]
end
end
tilemap = newtilemap
for _, mo in pairs(objects) do
mo.x, mo.y = mapwidth - mo.y + 1, mo.x
end
end