-
Notifications
You must be signed in to change notification settings - Fork 0
/
dimensional-jump.p8
1794 lines (1684 loc) · 74.9 KB
/
dimensional-jump.p8
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
pico-8 cartridge // http://www.pico-8.com
version 38
__lua__
overlay_state = 0
function _init()
btn_0_state = false
btn_1_state = false
btn_2_state = false
btn_3_state = false
btn_4_state = false
btn_5_state = false
btn_press = {}
btn_press[0] = false
btn_press[1] = false
btn_press[2] = false
btn_press[3] = false
btn_press[4] = false
btn_press[5] = false
btn_release = {}
btn_release[0] = false
btn_release[1] = false
btn_release[2] = false
btn_release[3] = false
btn_release[4] = false
btn_release[5] = false
overlay_state = 0
music(20,1000)
-- overlay_state 0 title screen
-- overlay_state 1 main play
-- overlay_state 2 pause
-- overlay_state 3 end of level
-- overlay_state 4 transition
-- overlay_state 5 credits
level = 0 -- default 0
title_to_zero = true
reset_stage = false
pause_length = 5
score = 0
score_counter = 0
score_tabulate = 0
score1 = 0
end_stage_control = 0
transition_timer = 0
monamie_code={}
monamie = false
credit_number = 0
rolling_credits = false
rolling_credits_height = 130
reset_game = false
i=0
sintimer=0
timer=0
-- music(12, 0, 3)
end
function zero_overlay()
print('press ❎ or 🅾️ to start', 18, 103, 7)
print('presented by:', 39, 112, 6)
print('mass industries', 35, 118, 5)
end
function draw_zero_overlay()
cls()
-- map( celx, cely, sx, sy, celw, celh, [layer] )
pal(7, 12)
bluepos = sin(sintimer)*5
res = 5 + bluepos
map(1, 0, 13+bluepos, 4, 128, 128)
pal(7, 8)
redpos = -1*(sin(sintimer)*5)
map(1, 0, 4+(redpos), 4, 128, 128)
pal(7, 7)
map(1, 0, 8, 4, 128, 128)
zero_overlay()
end
function handle_button_release(btn_num)
if btn_press[btn_num] == true and btn_release[btn_num] == true then
btn_press[btn_num] = false
btn_release[btn_num] = false
end
if (btn(btn_num)) then
print('btn_num'..btn_num, 0, 6, 7)
btn_press[btn_num] = true
elseif btn_press[btn_num] == true then
btn_release[btn_num] = true
end
return btn_release[btn_num]
end
function zero_level_start()
if (reset_stage == false and title_to_zero == false) music(21,1000)
reset_stage = false
-- TODO: debugging
--overlay_state = 4
-- TODO: debugging
zero_level = {
lscore = 0,
button_released = false,
button_prev = false,
button_cur = false,
button_release_count = 0,
color = 5,
even = false,
update=function(self)
-- handle button press
self.button_released = handle_button_release(4) or handle_button_release(5)
if (not btn(4) and not btn(5)) self.button_prev = false
if ((btn(4) or btn(5)) and self.button_prev == false) then
self.button_cur = true
self.button_prev = true
else
self.button_cur = false
end
if (self.button_released) self.button_release_count += 1
if (self.button_release_count == 1) self.button_released = false
if (timer == 300) score+=1
if self.lscore == 10 then
overlay_state = 4
end
if (stat(51) > 14 and self.even == true) self.even = false
if (stat(51) > 23 and self.even == false) self.even = true
end,
draw=function(self)
-- draw items in here
self.color = 5
if (stat(51) != nil) then
print('beats: '..self.lscore, 0, 6, 7)
-- print('even:'..(self.even and 'true' or 'false'), 0, 18, 7)
print('press ❎/🅾️ when', 34, 20, 7)
print('the object lights up', 27, 26, 7)
-- print('button:'..(self.button_released and 'true' or 'false'), 0, 24, 7)
if ((stat(51) > 16 and stat(51) < 30 and self.even == false) or (stat(51) > 7 and stat(51) < 21 and self.even == true)) then
self.color = 7
--if (self.button_released) self.lscore += 1
else
--if (self.button_released) self.lscore -= 1
end
end
if (self.button_cur and self.color == 7) self.lscore += 1
rectfill(44, 44, 84, 84, self.color)
end
}
end
function one_level_start()
-- TODO: debugging
--overlay_state = 4
-- TODO: debugging
if (reset_stage == false) music(2,1000)
reset_stage = false
one_level = {
-- todo: max dash value
-- todo: recharge max dash
left_released = false,
right_released = false,
start_pos = 0,
end_pos = 350,
end_tile = 88,
end_timer = 0,
player_pos = 5,
player_screen_pos = 0,
allow_timer = 0,
tick_timer = 0,
dash_jump = false,
dropping = false,
fall_anim = 0,
falling = false,
fall_override = false,
enemy_visible = false,
enemy_start_timer = 0,
enemy_current_time = 0,
enemy_pos = 0,
enemy_fall_anim = 0,
t=0,
update=function(self)
self.enemy_start_timer += 1
if (self.enemy_start_timer > 300 and self.enemy_visible == false) then
self.enemy_visible = true
self.enemy_pos = self.player_pos - 6
end
-- handle right button press
function control()
self.right_released = handle_button_release(1)
if ((btn(4) or btn(5)) and self.right_released and self.player_screen_pos < 130 and self.falling == false) then
-- handle dash jump mechanic
self.start_pos-=2
self.end_pos-=2
self.player_pos+=4
self.allow_timer = true
self.dash_jump = true
sfx(63)
if (self.enemy_visible) self.enemy_pos += 2
elseif (self.right_released and self.player_screen_pos < 130 and self.falling == false) then
self.start_pos-=1
self.end_pos-=1
self.player_pos+=2
self.allow_timer = true
self.dash_jump = false
sfx(62)
if (self.enemy_visible) self.enemy_pos += 1
end
end
if (self.end_timer == 0) control()
if self.allow_timer then
self.t += 1
if self.t % 18 == 0 then
self.allow_timer = false
self.dash_jump = false
end
end
self.tick_timer += 1
if self.tick_timer > 120 or (self.tick_timer > 10 and self.player_screen_pos > 60) then
self.allow_timer = true
self.end_pos-=1
self.tick_timer = 0
self.dash_jump = false
end
if (self.enemy_pos < self.player_pos and self.tick_timer % 15 == 0) then
if (self.enemy_visible and flr(rnd(10)) > 4 and self.enemy_fall_anim == 0 and self.end_timer == 0) self.enemy_pos += 1
end
-- if (self.player_pos > 31 and self.enemy_visible == false and flr(rnd(3)) > 2) then
-- self.enemy_visible = true
-- self.enemy_pos = self.player_pos - 6
-- end
end,
draw=function(self)
-- draw items in here
-- initial 1d grid
local space=0
local count=0
local dashx = 0
local drops = {15, 21, 28, 35, 42, 51, 65, 79}
-- 25 37 51 65 79
local x1, x2 = 0
local player_local = self.player_pos - ( (self.player_pos - 5) / 2 )
if (self.falling and self.tick_timer % 4 == 0) self.fall_anim += 1
if (self.fall_anim == 1 and self.tick_timer % 4 == 0) sfx(61)
if (self.fall_anim > 6) then
self.fall_anim = 6
if (self.tick_timer > 115) then
self.fall_override = true
reset_stage = true
overlay_state = 4
end
end
for i=self.start_pos,self.end_pos,1 do
c = 5
local x1 = space+(i*10)+i-self.t
local x2 = space+10+(i*10)+i-self.t
if (count == self.enemy_pos and self.player_pos > 31) c = 8
if(count == self.player_pos) then
c = 7
dashx = x1
self.player_screen_pos = x2
end
-- if (count == self.player_pos - 2 and self.player_pos > 31) c = 8
if (i == self.end_tile) c = 11
for drop in all(drops) do
if (i == drop) c = 0
-- 79 - ((79-5)/2)
-- if (self.player_pos > 31 and x2 > 64 and i == (player_local - 2)) c = 8
end
-- print('pp:'..self.player_pos, 0, 6, 7)
-- print('ep:'..self.enemy_pos, 0, 12, 7)
if (count < self.player_pos and count < 5) c = 0
if (count < self.player_pos-1 and count < 7) c = 0
if (count < self.player_pos-3 and count < 9) c = 0
if (count < self.player_pos-5 and count < 11) c = 0
if (self.enemy_pos == count and self.player_pos == count) then
self.falling = true
if (self.end_timer == 0) rectfill(x1, 64, x2, 74, 8)
if (self.fall_anim <= 5) rectfill(x1+self.fall_anim, 64+self.fall_anim, x2-self.fall_anim, 74-self.fall_anim, 7)
else
if (self.end_timer == 0) rectfill(x1, 64, x2, 74, c)
end
if (c == 7 and x2 < 0) self.falling = true
if (c == 0) then
if (self.player_pos == count) then
if (self.fall_anim <= 5) rectfill(x1+self.fall_anim, 64+self.fall_anim, x2-self.fall_anim, 74-self.fall_anim, 7)
self.falling = true
end
if (self.enemy_pos == count and self.enemy_start_timer > 300) then
if (self.enemy_current_time == 0) self.enemy_current_time = self.enemy_start_timer
if (self.enemy_fall_anim <= 5) rectfill(x1+self.enemy_fall_anim, 64+self.enemy_fall_anim, x2-self.enemy_fall_anim, 74-self.enemy_fall_anim, 8)
-- print('counted', 0, 18, 7)
if (self.enemy_start_timer > self.enemy_current_time + 60) then
self.enemy_fall_anim = 0
self.enemy_visible = false
self.enemy_start_timer = 0
else
self.enemy_fall_anim += 1
end
end
end
--print(i, space+(i*10)+i-self.t, 84, 7)
space = space + 2
count+=1
if (count == self.player_pos and i >= (self.end_tile - 1)) then
-- win level
self.end_timer += 1
if (self.end_timer > 0) rectfill(64 - self.end_timer*2,64 - self.end_timer*2,64 + self.end_timer*2, 64 + self.end_timer*2,11)
if (self.end_timer > 40) overlay_state = 4
end
end
if (self.dash_jump) spr(252,dashx-12, 65, 2, 1)
print('hold ❎/🅾️ and press ➡️ ', 20, 10, 7)
print('to dash-jump', 40, 20, 7)
end
}
end
function two_level_blanks()
local l = {
{127,10},
{126,11},
{125,12},
{124,13},
{123,14},
{122,15},
{113, 10},
{114, 10},
{115, 10},
{116, 10},
{117, 10},
}
for i=0,12 do
add(l, {124, i})
end
for i=112,124 do
add(l, {i, 12})
end
for i=112,124 do
add(l, {i, 6})
end
for i=2,8 do
add(l, {129, i})
end
for i=2,8 do
add(l, {130, i})
end
for i=3,9 do
add(l, {119, i})
end
for i=0,7 do
add(l, {121, i})
add(l, {126, i})
end
for i=4,8 do
add(l, {115, i})
end
for i=4,8 do
add(l, {112, i})
end
for i=113,117 do
add(l, {i, 12})
end
for i=113,117 do
add(l, {i+2, 10})
add(l, {i+1, 14})
add(l, {i-1, 8})
end
return l
end
function two_level_start()
-- TODO: debugging
-- overlay_state = 4
-- TODO: debugging
if (reset_stage == false) music(45,1000)
reset_stage = false
two_level = {
player_posx = 112,
player_posy = 0,
player_posx_prev = player_posx,
player_posy_prev = player_posy,
dashed = false,
dashed_prev = false,
dash_dir = '+h',
disappear_timer = 0,
disappear_x = 111,
disappear_y = -1,
obstacles = two_level_blanks(),
tick_timer = 0,
end_timer = 0,
lose_timer = 0,
falling = false,
enemy_visible = false,
enemy_posx = 0,
enemy_posy = 0,
enemy_win = false,
enemy_fall_timer = 0,
update=function(self)
self.tick_timer += 1
self.disappear_timer += 1
if (self.tick_timer > 60) self.tick_timer = 0
if (self.disappear_timer > 120) then
self.disappear_timer = 0
self.disappear_x += 1
self.disappear_y += 1
end
-- handle button presses
-- handle dash jump mechanic
self.dashed = false
function control()
if (handle_button_release(0)) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
if (btn(4) or btn(5)) then
-- these bounds are for dash jumping
-- it's two less than the bounds below
if (self.player_posx < 114) then
self.player_posx-=1
return
else
self.player_posx-=2
self.dashed = true
self.dash_dir = '-h'
return
end
else
self.player_posx-=1
sfx(62)
return
end
elseif (handle_button_release(1)) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
if (btn(4) or btn(5)) then
if (self.player_posx > 125) then
self.player_posx+=1
return
else
self.player_posx+=2
self.dashed = true
self.dash_dir = '+h'
return
end
else
self.player_posx+=1
sfx(62)
return
end
elseif (handle_button_release(2)) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
if (btn(4) or btn(5)) then
if (self.player_posy < 2) then
self.player_posy-=1
return
else
self.player_posy -= 2
self.dashed = true
self.dash_dir = '-v'
return
end
else
self.player_posy-=1
sfx(62)
return
end
elseif (handle_button_release(3)) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
if (btn(4) or btn(5)) then
if (self.player_posy > 13) then
self.player_posy+=1
return
else
self.player_posy+=2
self.dashed = true
self.dash_dir = '+v'
return
end
else
self.player_posy+=1
sfx(62)
return
end
end
end
if (self.player_posx == self.enemy_posx and self.player_posy == self.enemy_posy) then
self.falling = true
self.enemy_win = true
end
if (self.player_posx == 127 and self.player_posy == 15) then
self.end_timer += 1
elseif (self.falling == true) then
if (self.lose_timer == 0) sfx(61)
self.lose_timer += 1
else
control()
end
if self.lose_timer > 60 then
map(112, 0, 0, 0, 128, 128)
reset_stage = true
overlay_state = 4
end
if (self.player_posx > 127) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
self.player_posx = 127
end
if (self.player_posy > 15) then
self.player_posy_prev = self.player_posy
self.player_posx_prev = self.player_posx
self.player_posy = 15
end
if (self.player_posx < 112) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
self.player_posx = 112
end
if (self.player_posy < 0) then
self.player_posx_prev = self.player_posx
self.player_posy_prev = self.player_posy
self.player_posy = 0
end
-- spawn enemy
if (self.tick_timer > 40 and self.enemy_visible == false) then
self.enemy_fall_timer = 0
self.enemy_falling = false
self.enemy_visible = true
self.enemy_posx = flr(rnd(15)) + 112
self.enemy_posy = flr(rnd(15))
--self.enemy_posx = 115
--self.enemy_posy = 6
end
-- enemy fall animation counter
if (self.enemy_visible and self.enemy_falling) self.enemy_fall_timer += 1
-- enemy reset after falling
if (self.enemy_fall_timer > 60 and self.tick_timer == 0) then
self.enemy_visible = false
self.enemy_fall_anim = 0
end
-- temp end
-- 127,15
function enemy_ai()
if (self.enemy_falling) return
if self.enemy_visible and self.tick_timer % 30 == 0 then
local condition_x = abs(self.player_posx - self.enemy_posx)
local condition_y = abs(self.player_posy - self.enemy_posy)
if (condition_x >= condition_y) then
if (self.player_posx > self.enemy_posx) then
self.enemy_posx+=1
elseif (self.player_posx < self.enemy_posx) then
self.enemy_posx-=1
end
else
if (self.player_posy > self.enemy_posy) then
self.enemy_posy+=1
elseif (self.player_posy < self.enemy_posy) then
self.enemy_posy-=1
end
end
end
end
enemy_ai()
end,
draw=function(self)
-- draw items in here
local i = 0
local j = 0
map(112, 0, 0, 0, 128, 128)
for i=111,127,1 do
for j=-1,15,1 do
mset(i, j, 255)
end
end
mset(self.player_posx, self.player_posy, 254)
-- print('ppx:'..self.player_posx, 0, 6, 7)
-- print('ppy:'..self.player_posy, 0, 12, 7)
-- print('epx:'..self.enemy_posx, 0, 18, 7)
-- print('epy:'..self.enemy_posy, 0, 24, 7)
function dash_unset()
mset(self.player_posx_prev+1, self.player_posy_prev, 255)
mset(self.player_posx_prev-1, self.player_posy_prev, 255)
mset(self.player_posx_prev, self.player_posy_prev+1, 255)
mset(self.player_posx_prev, self.player_posy_prev-1, 255)
mset(self.player_posx_prev-2, self.player_posy_prev-2, 255)
mset(self.player_posx_prev+2, self.player_posy_prev+2, 255)
mset(self.player_posx_prev+2, self.player_posy_prev-2, 255)
mset(self.player_posx_prev-2, self.player_posy_prev+2, 255)
end
if (self.player_posx and self.player_posy) then
mset(self.player_posx+1, self.player_posy, 255)
mset(self.player_posx-1, self.player_posy, 255)
mset(self.player_posx, self.player_posy+1, 255)
mset(self.player_posx, self.player_posy-1, 255)
mset(self.player_posx-2, self.player_posy-2, 255)
mset(self.player_posx+2, self.player_posy+2, 255)
mset(self.player_posx+2, self.player_posy-2, 255)
mset(self.player_posx-2, self.player_posy+2, 255)
mset(self.player_posx, self.player_posy-2, 255)
mset(self.player_posx, self.player_posy+2, 255)
mset(self.player_posx+2, self.player_posy, 255)
mset(self.player_posx-2, self.player_posy, 255)
end
if (self.player_posx >= 112 and self.player_posx <= 127 and self.player_posy >= 0 and self.player_posy <= 15) then
mset(self.player_posx, self.player_posy, 254)
if (self.dashed) then
if (self.dashed_prev) then
dash_unset()
end
if (self.dash_dir == '+h') mset(self.player_posx_prev+1, self.player_posy_prev, 251)
if (self.dash_dir == '-h') mset(self.player_posx_prev-1, self.player_posy_prev, 251)
if (self.dash_dir == '+v') mset(self.player_posx_prev, self.player_posy_prev+1, 250)
if (self.dash_dir == '-v') mset(self.player_posx_prev, self.player_posy_prev-1, 250)
sfx(63)
self.dashed_prev = true
else
mset(self.player_posx_prev, self.player_posy_prev, 255)
if (self.dashed_prev) then
dash_unset()
self.dashed_prev = false
end
end
end
if (self.enemy_visible and self.enemy_falling == false) mset(self.enemy_posx, self.enemy_posy, 239)
mset(127,15,249)
if (self.player_posx == 127 and self.player_posy == 15) then
mset(127,15,254)
if (self.end_timer > 40) overlay_state = 4
end
for i=111,self.disappear_x,1 do
for j=-1,self.disappear_y,1 do
mset(i, j, 248)
if (self.player_posx == i and self.player_posy == j) then
mset(i, j, 247)
self.falling = true
if (self.lose_timer > 30) mset(i, j, 246)
if (self.lose_timer > 45) mset(i, j, 248)
end
end
end
if (self.enemy_win) then
if (self.lose_timer > 20) mset(self.player_posx, self.player_posy, 238)
if (self.lose_timer > 35) mset(self.player_posx, self.player_posy, 237)
if (self.lose_timer > 45) mset(self.player_posx, self.player_posy, 239)
end
for key,value in pairs(self.obstacles) do
mset(value[1], value[2], 248) -- black square representing drop
-- player falls down
if (self.player_posx == value[1] and self.player_posy == value[2]) then
mset(value[1], value[2], 247)
self.falling = true
if (self.lose_timer > 30) mset(value[1], value[2], 246)
if (self.lose_timer > 45) mset(value[1], value[2], 248)
end
-- enemy falls down
if (self.enemy_posx == value[1] and self.enemy_posy == value[2]) then
mset(value[1], value[2], 239)
self.enemy_falling = true
if (self.enemy_fall_timer > 30) mset(value[1], value[2], 236)
if (self.enemy_fall_timer > 45) mset(value[1], value[2], 235)
if (self.enemy_fall_timer > 55) mset(value[1], value[2], 248)
end
-- show dashed line of player dashing past drop
if (self.player_posx_prev and self.dashed) then
if (self.dash_dir == '+h') mset(self.player_posx_prev+1, self.player_posy_prev, 251)
if (self.dash_dir == '-h') mset(self.player_posx_prev-1, self.player_posy_prev, 251)
if (self.dash_dir == '+v') mset(self.player_posx_prev, self.player_posy_prev+1, 250)
if (self.dash_dir == '-v') mset(self.player_posx_prev, self.player_posy_prev-1, 250)
end
end
-- win condition hit
if (self.end_timer > 0) rectfill(64 - self.end_timer*2,64 - self.end_timer*2,64 + self.end_timer*2, 64 + self.end_timer*2,11)
end
}
end
function setup_block(x, y, z, depth, s, u, c, blocksize)
x0=(x-blocksize)+(z)
y0=(y-blocksize)+(z)
x1=(x+blocksize)-z
y1=(y+blocksize)-(z)
iz=depth
xx0=x0+iz+2
yy0=y0-iz+2
xx1=x1+iz-2
yy1=y1-iz-2
if iz < 3 then
rectfill(xx0,yy0,xx1,yy1,c)
else
draw_block(x0+s,x1+s,y0+u,y1+u,xx0,xx1,yy0,yy1,c)
end
end
function draw_block(x0,x1,y0,y1,xx0,xx1,yy0,yy1,c)
palt(0, false)
rectfill(xx0,yy0,xx1,yy1,0)
rect(xx0,yy0,xx1,yy1,c)
palt(0, true)
rect(x0-2,y0,x1-2,y1,c)
line(xx0,yy0,x0-2,y0,c)
line(xx1,yy0,x1-2,y0,c)
line(xx0,yy1,x0-2,y1,c)
line(xx1,yy1,x1-2,y1,c)
end
function determine_color(self, i, column)
if (self.prevcurrent == ((column-3) * -1) and self.jumppress == true and i == self.lvl) return 7
if (self.endgoallevel == (self.jumplevel) and self.jumppress == true and i == 0 and self.endblocky == i and self.endblockx == column) return 11
if (self.endgoallevel == (self.jumplevel+1) and self.jumppress == false and i == 0 and self.endblocky == i and self.endblockx == column) return 11
if (self.enemy_slice == self.jumplevel and self.jumppress == true and i == self.enemyy and column == self.enemyx) return 8
if (self.enemy_slice == (self.jumplevel+1) and self.jumppress == false and i == self.enemyy and column == self.enemyx) return 8
return 5
end
function determine_color_first_layer(self, j, column)
if (self.jumppress == false and self.endgoallevel == self.jumplevel and self.endblocky == j and self.endblockx == column) return 11
if (self.jumppress == false and self.enemy_slice == self.jumplevel and j == self.enemyy and column == self.enemyx) return 8
if (self.current == ((column * -1) + 3) and j == self.lvl) return 7
return 5
end
function three_level_start()
if (reset_stage == false) music(29,1000)
reset_stage = false
three_level = {
u=0,
current= 0,
prevcurrent = 0,
player_x_conv = ( 0 * -1) + 3,
lvl = 0,
xnudge = 0,
xcpos = 0,
jumpanim = 0,
startanim = 0,
blocksize = 8,
leftpress = false,
rightpress = false,
uppress = false,
downpress = false,
jumppress = false,
jumplevel = 0,
jumptimer = 0,
jumptimerset = false,
end_timer = 0,
lose_timer = 0,
endgoallevel = 24,
endblockx = flr(rnd(6)),
endblocky = flr(rnd(3)),
enemy_slice = 3,
enemyx = 6, --flr(rnd(6)),
enemyy = 0, --flr(rnd(3)),
enemy_visible = true,
enemy_reset = false,
tick_timer = 0,
wlcontrol = false, -- win lose control, if win or lose take control
update=function(self)
self.player_x_conv = (self.current * -1) + 3
self.tick_timer += 1
-- if (self.tick_timer > 60) self.tick_timer = 0
function control3d()
-- current = 0
if(btn(0)) then
self.leftpress = true
end
if(btn(1)) then
self.rightpress = true
end
if self.xnudge > 3 then
self.xnudge = 3
end
if self.xnudge < -3 then
self.xnudge = -3
end
if(btn(2)) then
self.uppress = true
end
if(btn(3)) then
self.downpress = true
end
if(btn(4) and self.jumptimer == 0) then
if (self.jumppress == false) self.prevcurrent = self.current
sfx(63)
self.jumppress = true
self.jumptimerset = true
self.jumplevel += 1
end
if(btn(5) and self.jumptimer == 0) then
if (self.jumppress == false) self.prevcurrent = self.current
sfx(63)
self.jumppress = true
self.jumptimerset = true
self.jumplevel += 1
end
if ((not btn(0)) and (not btn(1)) and (not btn(2)) and (not btn(3)) and (not btn(4)) and (not btn(5)))then
if (self.leftpress == true) then
sfx(62)
pset(64,64,7)
self.xnudge+=1
self.current-=1
self.xcpos+=20
self.leftpress = false
end
if (self.rightpress == true) then
sfx(62)
self.xnudge-=1
self.current+=1
self.xcpos-=20
self.rightpress = false
end
if (self.uppress == true) then
sfx(62)
self.lvl -= 1
self.uppress = false
end
if (self.downpress == true) then
sfx(62)
self.lvl += 1
self.downpress = false
end
if (self.jumptimerset == true) then
self.jumptimerset = false
self.jumptimer = 0
end
end
if self.xcpos > 60 then
self.xcpos = 60
end
if self.xcpos < -60 then
self.xcpos = -60
end
if self.current > 3 then
self.current = 3
end
if self.current < -3 then
self.current = -3
end
if self.lvl < 0 then
self.lvl = 0
end
if self.lvl > 3 then
self.lvl = 3
end
if (self.jumppress == true) then
-- prevent jumping into enemy at level gt 0
if (self.enemyx == self.player_x_conv and self.enemyy == self.lvl and self.enemyx >= 3 and self.lvl > 0) self.enemyx += 2
if (self.enemyx == self.player_x_conv and self.enemyy == self.lvl and self.enemyx < 3 and self.lvl > 0) self.enemyx -= 2
self.current = -10
if (self.startanim > 5) then
self.jumpanim -= 5.95
end
end
if (self.jumpanim < -75) then
self.jumpanim = 0
self.jumppress = false
self.current = self.prevcurrent
self.startanim = 0
self.blocksize = 8
end
if (self.jumptimerset == true) self.jumptimer += 1
if (self.jumptimer > 120) then
self.jumptimer = 0
self.jumptimerset = false
end
end
if self.jumplevel == self.endgoallevel and self.endblockx == ((self.current-3)*-1) and self.endblocky == self.lvl then
self.end_timer += 1
elseif self.jumplevel == self.enemy_slice and self.enemyx == ((self.current-3)*-1) and self.enemyy == self.lvl then
self.lose_timer += 1
self.wlcontrol = true
elseif self.wlcontrol == false then
control3d()
elseif self.wlcontrol == true and self.lose_timer > 0 then
self.lose_timer += 1
end
-- self.lvl is y the top is 0 and it goes down to 3
-- self.current is x, the middle is 0, left is -3, right is 3
function enemy_ai3d()
if self.enemy_visible and self.tick_timer % 45 == 0 then
local player_x = self.current
local player_y = self.lvl
local player_z = self.jumplevel
local player_x_conv = (player_x * -1) + 3
local condition_x = abs(abs(player_x_conv) - abs(self.enemyx))
local condition_y = abs(player_y - self.enemyy)
if (condition_x >= condition_y) then
if (self.enemyx < player_x_conv) then
self.enemyx+=1
elseif (self.enemyx > player_x_conv) then
self.enemyx-=1
end
else
if (player_y > self.enemyy) then
self.enemyy+=1
elseif (player_y < self.enemyy) then
self.enemyy-=1
end
end
end
end
if (self.jumplevel == self.enemy_slice + 1) self.enemy_visible = false
if (self.enemy_visible == false and self.jumptimer == 0) then
self.enemy_slice = self.jumplevel + flr(rnd(3))
self.enemyx = flr(rnd(6))
if (self.enemyx == self.player_x_conv and self.enemyx <= 3) then
self.enemyx += 2
elseif (self.enemyx == self.player_x_conv and self.enemyx > 3) then
self.enemyx -= 2
end
self.enemy_visible = true
end
if (self.tick_timer > 200 and self.jumptimer == 0) then
enemy_ai3d()
self.enemy_visible = true
end
if (self.end_timer > 60) overlay_state = 4
if (self.lose_timer > 60) then
reset_stage = true
overlay_state = 4
end
if (self.jumplevel > self.endgoallevel) self.endgoallevel += 10
end,
draw=function(self)
cls()
for i=0,0 do
if (self.jumpanim == 0) then
ydiff = -17 + (i * 20) - (self.lvl*4)
else
ydiff = -17 + (i * 20) - (self.lvl*4) - (self.jumpanim * .2)
end
zdiff = 7
depth = 2
self.blocksize = 8
if (self.lvl > 0) ydiff = ydiff + 5
if (self.lvl >= 3) ydiff = ydiff + 6
if (self.lvl < 3) then
setup_block(self.xcpos+64+57,64+ydiff,zdiff,depth,12+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64+37,64+ydiff,zdiff,depth,10+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64+20,64+ydiff,zdiff,depth,8+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64+3,64+ydiff,zdiff,depth,7+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64-15,64+ydiff,zdiff,depth,4+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64-32,64+ydiff,zdiff,depth,2+self.xnudge,self.u,5,self.blocksize)
setup_block(self.xcpos+64-52,64+ydiff,zdiff,depth,0+self.xnudge,self.u,5,self.blocksize)
end
end
if (self.lvl <= 3) then
for i=0,3 do