-
Notifications
You must be signed in to change notification settings - Fork 0
/
tempo.p8
1123 lines (1038 loc) · 44.8 KB
/
tempo.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 29
__lua__
--TEMPo BY cARSON kOMPON
function _init()
cls()
cartdata("carsonk_tempo")
menuitem(1, "return to menu", init_menu)
difficulty=1
init_menu()
end
function _update60()
if stat(24) == 6 then
t+=0.5
else t+=1 end
if isplaying then
update_game()
else
update_menu()
end
end
function _draw()
--cls()
if isplaying then
draw_game()
else
draw_menu()
end
end
-->8
--player stuff
function init_player()
ball={
x=252,y=252,hspd=0,vspd=0,
acc=0.1,spd=3,dr=0,cx=0,cy=0,dx=0,dy=0,
box={0,0,7,7},hp=maxhp,invul=0,
col=choose({8,9,11,12,14}),
}
trailcols = split"14,2,8"
if(ball.col == 9) trailcols = split"10,4,9"
if(ball.col == 11) trailcols = split"3,5,11"
if(ball.col == 12) trailcols = split"13,1,12"
if(ball.col == 14) trailcols = split"8,2,14"
itime = 0
ctime = 0
bgcol = choose({4,3,13})
timescale=1
charging=false
charge=0
atk=0
score=0
killchain=0
chaintime=0
dead=false
sfx(21,1)
end
function update_player()
--parts
local cl = trailcols
local cnt = 4
if(charging) cnt = 1
if(atk > 0 or itime>0) cl = {8,9,10}
if(abs(ball.hspd) > 0 or abs(ball.vspd) > 0) spawn_parts(ball.x+3,ball.y+3,cnt,3,0.1,cl)
--charge press
if btn(🅾️) and not charging then
if(itime==0) music(0,0,1)
atk=0
charge=0
ball.dx=0
ball.dy=0
end
--release charge
if not btn(🅾️) and charging then
if itime==0 then
music(-1)
sfx(10,0)
end
ball.hspd = ball.dx/3
ball.vspd = ball.dy/3
if ctime>0 then
ball.hspd*=1.5
ball.vspd*=1.5
end
atk = 20*charge
end
--charging up
charging = btn(🅾️)
if charging then
timescale = lerp(timescale,0.25,0.125)
ball.acc = 0.05
if(charge < 2) charge += 0.1
if btn(⬆️) then ball.cy=-8
elseif btn(⬇️) then ball.cy=8
else ball.cy=0 end
if btn(⬅️) then ball.cx=-8
elseif btn(➡️) then ball.cx=8
else ball.cx=0 end
ball.dx=lerp(ball.dx,ball.cx*charge,0.125)
ball.dy=lerp(ball.dy,ball.cy*charge,0.125)
else
timescale = lerp(timescale,1,0.125)
ball.acc = 0.1
end
--vertical movement
if btn(⬆️) and ball.vspd > -ball.spd and not charging then
ball.vspd -= ball.acc
elseif btn(⬇️) and ball.vspd < ball.spd and not charging then
ball.vspd += ball.acc
elseif abs(ball.vspd) > 0 then
if(abs(ball.vspd) < ball.acc) ball.vspd = 0
ball.vspd -= ball.acc*sgn(ball.vspd)*timescale
end
--horizontal movement
if btn(⬅️) and ball.hspd > -ball.spd and not charging then
ball.hspd -= ball.acc
elseif btn(➡️) and ball.hspd < ball.spd and not charging then
ball.hspd += ball.acc
elseif abs(ball.hspd) > 0 then
if(abs(ball.hspd) < ball.acc) ball.hspd = 0
ball.hspd -= ball.acc*sgn(ball.hspd)*timescale
end
--wall collision
local nx = ball.x+ball.hspd*timescale
local ny = ball.y+ball.vspd*timescale
if nx < 0 or nx > gamesize-7 or (ball.hspd != 0 and cmap(nx,ball.y)) then
ball.hspd *= bump()
end
if ny < 0 or ny > gamesize-7 or (ball.vspd != 0 and cmap(ball.x,ny)) then
ball.vspd *= bump()
end
--move ball
ball.x += ball.hspd*timescale
ball.y += ball.vspd*timescale
--reduce attack timer
if(atk > 0) atk-=1
if(ball.invul > 0) ball.invul-=1
end
--bump fx
function bump()
sfx(11)
screenshake(3,1)
return -0.75
end
function draw_player()
--charging line
if charging then
line(ball.x+3,ball.y+3,ball.x+3+ball.dx,ball.y+3+ball.dy,0)
end
--draw outline
--[[
pal(8,0)
for i=-1,1 do
for j=-1,1 do
if not(i==0 and j==0) then
spr(1,ball.x+i,ball.y+j)
end
end
en
]]
--draw ball
if (itime > 0 or ctime > 0) and flr(t/2)%2==0 then
pal(8,trailcols[1])
elseif charging and flr(t/4)%2==0 then
pal(8,trailcols[1])
elseif (atk > 0 and t%4==0) then
pal(8,7)
else
pal(8,ball.col)
end
if ball.invul == 0 or flr(t/5)%2==0 then
spr(1,ball.x,ball.y)
end
pal()
end
function dmg_ball(dmg)
if ball.hp > 0 then
ball.hp -= dmg
ball.invul = 30
if ball.hp < 1 then
dead=true
spawn_parts(ball.x+3,ball.y+3,100,10,0.025,trailcols,1,1)
screenshake(10,0.1)
sfx(22,1)
sfx(23,2)
music(-1)
playtime = flr(t/60)/60
t=0
enemies = {}
bigenemies = {}
save_highscore(difficulty,score)
end
end
end
-->8
--draw stuff
function draw_game()
local cx = ball.x-60
local cy = ball.y-60
local cl = caml
if charging then
cx += ball.dx*2
cy += ball.dy*2
cl = caml/4
end
camx=lerp(camx,cx,cl)
camy=lerp(camy,cy,cl)
camera(camx+rnd(shake)-shake/2,camy+rnd(shake)-shake/2)
if dead or (camx < 0 or camx > 384 or camy < 0 or camy > 384) then
draw_background(camx,camy)
end
if not dead then
draw_floor()
draw_powerups()
end
draw_parts()
if not dead then
draw_enemies()
draw_player()
draw_walls()
end
draw_score_fx()
--map() --draw collision
if dead then
draw_dead_gui(camx,camy)
else
draw_gui(camx,camy)
end
end
function draw_gui(x,y)
--draw hearts
palt(2,true)
palt(0,false)
local hpp = ball.hp
local hpx = 2
local hdrawn = 0
while hpp > 1 do
spr(13,x+hpx,y+1)
hpx+=10
hdrawn+=1
hpp-=2
end
if hpp > 0 then
spr(14,x+hpx,y+1)
hpx+=10
hdrawn+=1
hpp-=1
end
while hdrawn < maxhp/2 do
spr(15,x+hpx,y+1)
hpx+=10
hdrawn+=1
end
palt()
--draw score
local sctxt = tostr(score)
if(score > 0) sctxt = sctxt .. "00"
outline_print(sctxt,x+125-#sctxt*4,y+2,7,ball.col)
end
function draw_dead_gui(x,y)
local str="you died"
outline_print(str,x+64-#str*2,y+16,7,trailcols[2])
str="highscore"
outline_print(str,x+64-#str*2,y+38,7,trailcols[2])
str=tostr(highscore) .. "00"
outline_print(str,x+64-#str*2,y+46,7,ball.col)
str="your score"
outline_print(str,x+64-#str*2,y+58,7,trailcols[2])
str=tostr(score) .. "00"
outline_print(str,x+64-#str*2,y+66,7,ball.col)
str="your playtime"
outline_print(str,x+64-#str*2,y+78,7,trailcols[2])
str=tostr(playtime) .. "M"
outline_print(str,x+64-#str*2,y+86,7,ball.col)
str="🅾️ - rETRY"
outline_print(str,x+64-#str*2,y+104,7,trailcols[2])
str="❎ - rETURN TO mENU"
outline_print(str,x+64-#str*2,y+112,7,trailcols[2])
end
--fuzzy background
function draw_background(x,y)
local cnt=300
if(stat(24) == 6) cnt=100
for i=0,cnt do
circfill(x+rnd(128),y+rnd(128),rnd(2),choose(split"1,5,0"))
end
end
--tiled floor
function draw_floor()
pal(12,bgcol)
for i=0,7 do
for j=0,7 do
sspr(24,0,8,8,i*64,j*64,64,64)
--spr(16,i*32,j*32,4,4)
end
end
pal()
--sspr(48,0,32,32+8,64,64-8)
end
--walls
function draw_walls()
for w in all(walls) do
cl=7
bcl=6
if w.col then
cl=bgcol
bcl=5
end
rectfill(w.x,w.y-8,w.x+31,w.y+23,cl)
fillp(▒)
rectfill(w.x,w.y+24,w.x+31,w.y+31,bcl)
fillp()
line(w.x,w.y-8,w.x+31,w.y-8,0)
line(w.x,w.y-8,w.x,w.y+31,0)
line(w.x+32,w.y-8,w.x+32,w.y+31,0)
end
end
--draw powerups
function draw_powerups()
for p in all(powerups) do
spr(10+p.typ,p.x,p.y)
end
end
--draw enemies
function draw_enemies()
--normal enemies
pal(1,0)
for e in all(enemies) do
if e.tmr<=0 or flr(t/4)%2==0 then
spr(2,e.x,e.y)
end
end
pal(1,1)
--big enemies
for e in all(bigenemies) do
pal(2,e.hp-1)
if e.tmr<=0 or flr(t/4)%2==0 then
spr(4,e.x,e.y,2,2)
end
end
pal(2,2)
end
--draw particles
function draw_parts()
for p in all(parts) do
circfill(p.x,p.y,p.size,p.col)
end
end
--draw score fx
function draw_score_fx()
for s in all(scores) do
outline_print(s.str,s.x-#s.str*2,s.y,7,s.col)
end
end
-->8
--game update
function init_game()
gamesize=64*8
isplaying=true
music(-1)
init_enemycount()
init_player()
init_camera()
load_map(0)
parts={}
scores={}
enemies={}
bigenemies={}
powerups={}
highscore=load_highscore(difficulty)
t=0
spawn_parts(ball.x+3,ball.y+3,100,6,0.1,trailcols,2,2)
for i=1,ecount do
spawn_enemy()
end
for i=1,bcount do
spawn_bigenemy()
end
end
function init_camera()
camx=192
camy=192
caml=0.325
shake=0
shakedec=0
end
function update_game()
if(not dead) update_player()
update_enemies()
update_bigenemies()
update_parts()
update_scorenums()
update_powerups()
if(itime > 0) itime-=1
if(ctime > 0) ctime-=1
if(itime==1) music(-1)
if dead and t > 60 then
if btnp(🅾️) then
init_game()
elseif btnp(❎) then
init_menu()
end
end
if shake > 0 then
shake -= shakedec
elseif shake < 0 then
shake = 0
end
if chaintime > 0 then
chaintime-=1
if(chaintime==0) killchain=0
end
if(ceil(timescale*100) == 100) timescale = 1
end
function init_enemycount()
if difficulty==0 then
maxhp = 8
ecount = 10
bcount = 1
espd = 1
bspd = 1
elseif difficulty==1 then
maxhp = 6
ecount = 10
bcount = 2
espd = 2
bspd = 2
elseif difficulty==2 then
maxhp = 4
ecount = 15
bcount = 3
espd = 2.5
bspd = 2
end
end
function spawn_powerup(xx,yy,chance)
if rnd(100) < chance then
add(powerups,{
typ=flr(rnd(3)),x=xx,y=yy,
box={0,0,6,6},life=12
})
end
end
function update_powerups()
for p in all(powerups) do
if(p.life > 0) p.life-=1
if coll(p,ball) and p.life==0 then
if p.typ == 0 then
sfx(40,0)
powerup_msg("health up",p.x,p.y)
ball.hp += 2
if(ball.hp > maxhp) ball.hp = maxhp
elseif p.typ == 1 then
music(10,0,1)
powerup_msg("invincibility",p.x,p.y)
itime = 10*60
elseif p.typ == 2 then
sfx(41,0)
powerup_msg("X2 charge",p.x,p.y)
ctime = 10*60
end
del(powerups,p)
end
end
end
function spawn_enemy()
repeat
sx = rnd(gamesize-7)
sy = rnd(gamesize-7)
until not cmap(sx,sy)
add(enemies,{
x=sx,y=sy,
hs=rnd(espd*2)-espd,vs=rnd(espd*2)-espd,
box={0,0,7,7},tmr=60
})
end
function spawn_bigenemy()
repeat
sx = rnd(gamesize-15)
sy = rnd(gamesize-15)
until not cmap(sx,sy,15,15)
add(bigenemies,{
x=sx,y=sy,
hs=rnd(bspd*2)-bspd,vs=rnd(bspd*2)-bspd,
box={0,0,15,15},tmr=60,hp=3
})
end
function update_enemies()
for e in all(enemies) do
if e.tmr > 0 then
e.tmr-=1
else
if(not charging or t%4==0) spawn_parts(e.x+3,e.y+3,1,3,0.1,{5,6})
e.x += e.hs*timescale
e.y += e.vs*timescale
if(e.x < 0 or e.x > gamesize-7 or cmap(e.x+e.vs,e.y)) e.hs *= -1
if(e.y < 0 or e.y > gamesize-7 or cmap(e.x,e.y+e.hs)) e.vs *= -1
if coll(e,ball) then
if atk > 0 or itime > 0 then
screenshake(5,0.1)
sfx(12,1)
spawn_parts(e.x+3,e.y+3,50,8,0.1,{5,6},1,1)
add_score(1,e.x,e.y)
spawn_powerup(e.x,e.y,killchain+1)
del(enemies,e)
while #enemies < ecount do
spawn_enemy()
end
elseif ball.invul == 0 then
bump_ball(e,0)
dmg_ball(1)
end
end
end
end
end
function update_bigenemies()
for e in all(bigenemies) do
if e.tmr > 0 then
e.tmr-=1
else
if(not charging or t%4==0) spawn_parts(e.x+3,e.y+3,1,5,0.1,{5,6})
e.x += e.hs*timescale
e.y += e.vs*timescale
if(e.x < 0 or e.x > gamesize-15 or cmap(e.x+e.vs,e.y,15,15)) e.hs *= -1
if(e.y < 0 or e.y > gamesize-15 or cmap(e.x,e.y+e.hs,15,15)) e.vs *= -1
if coll(e,ball) then
if atk > 0 or itime > 0 then
if e.hp > 1 and itime==0 and ctime==0 then
e.hp-=1
bump_ball(e,2)
sfx(17,2)
else
screenshake(5,0.1)
sfx(12,1)
spawn_parts(e.x+3,e.y+3,50,8,0.1,{5,6},1,1)
add_score(5,e.x,e.y)
sfx(18,2)
spawn_powerup(e.x+5,e.y+5,25)
del(bigenemies,e)
while #bigenemies < bcount do
spawn_bigenemy()
end
end
elseif ball.invul == 0 then
bump_ball(e,0)
dmg_ball(2)
end
end
end
end
end
function bump_ball(e,ekb)
dr=atan2(ball.y - e.y, ball.x - e.x)
ball.hspd=sin(dr)*4
ball.vspd=cos(dr)*4
if ekb > 0 then
e.hs=sin(dr+0.5)*ekb
e.vs=cos(dr+0.5)*ekb
end
screenshake(5,0.1)
sfx(13,1)
end
function powerup_msg(st,xx,yy)
add(scores,{
x=xx,y=yy,ey=yy-8,str=st,
col=0
})
end
function add_score(n,xx,yy)
sfx(14+killchain,2)
n*=killchain+1
add(scores,{
x=xx,y=yy,ey=yy-8,str=tostr(n).."00",
col=ball.col
})
while n > 0 do
score+=1
n-=1
if(score%20==0) ecount+=1
if(score%100==0) bcount+=1
end
if(killchain < 2) killchain+=1
chaintime=120
end
function update_scorenums()
for s in all(scores) do
s.y = lerp(s.y,s.ey,0.0425)
if flr(s.y) == flr(s.ey) then
del(scores,s)
end
end
end
function spawn_parts(xx,yy,n,s,d,c,dx,dy)
vx = dx or 0
vy = dy or 0
for i=1,n do
add(parts,{
x=xx+rnd(s*2)-s,y=yy+rnd(s*2)-s,
size=rnd(s),decay=d,col=choose(c),
hs=rnd(vx*2)-vx,vs=rnd(vy*2)-vy
})
end
end
function update_parts()
for p in all(parts) do
p.size -= p.decay*timescale
p.x += p.hs*timescale
p.y += p.vs*timescale
if(p.size <= 0) del(parts,p)
end
end
-->8
--useful functions
--collision box
function abs_box(s)
local box = {}
box[1] = s.box[1] + s.x
box[2] = s.box[2] + s.y
box[3] = s.box[3] + s.x
box[4] = s.box[4] + s.y
return box
end
--collision
function coll(a,b)
local box_a = abs_box(a)
local box_b = abs_box(b)
if box_a[1] > box_b[3] or
box_a[2] > box_b[4] or
box_b[1] > box_a[3] or
box_b[2] > box_a[4] then
return false
end
return true
end
--screenshake
function screenshake(am,dc)
shake=am
shakedec=dc
end
--linear interpolation
function lerp(pos,tar,perc)
return pos+((tar-pos)*perc)
end
--choose random array
function choose(t)
return t[flr(rnd(#t))+1]
end
--outlined text
function outline_print(s,x,y,c1,c2)
for i=0,2 do
for j=0,2 do
if not(i==1 and j==1) then
print(s,x+i,y+j,c1)
end
end
end
print(s,x+1,y+1,c2)
end
-->8
--main menu
function init_menu()
music(4,10000)
t=0
menusel=0
playx = 64
optionsx = 64
isplaying=false
end
function update_menu()
if btnp(⬆️) then
menusel-=1
if(menusel < 0) menusel = 1
bump_menu_text()
elseif btnp(⬇️) then
menusel+=1
if(menusel > 1) menusel=0
bump_menu_text()
elseif btnp(🅾️) then
if menusel == 0 then
init_game()
end
end
if menusel == 1 then
if btnp(⬅️) then
difficulty-=1
if(difficulty < 0) difficulty = 0
optionsx = 56
elseif btnp(➡️) then
difficulty+=1
if(difficulty > 2) difficulty = 2
optionsx = 72
end
end
playx = lerp(playx,64,0.125)
optionsx = lerp(optionsx,64,0.125)
end
function bump_menu_text()
if(menusel==0) playx = 56
if(menusel==1) optionsx = 56
end
function draw_menu()
camera(0,0)
draw_background(0,0)
draw_title()
local str = "play"
if(menusel == 0) str = "▶ " .. str .. " ◀"
outline_print(str,playx-#str*2,64,12,7)
str="difficulty"
outline_print(str,64-#str*2,82,3,7)
str = "normal"
if(difficulty==0) str = "easy"
if(difficulty==2) str = "hard"
local drawstr = str
if(menusel == 1) str = "⬅️ " .. str .. " ➡️ "
outline_print(str,optionsx-#str*2,92,3,7)
str = "⬆️⬇️⬅️➡️ - move | 🅾️ - charge "
outline_print(str,64-#str*2,118,1,7)
end
--draw TEMPo
function draw_title()
--outline
local x = 24 + sin(t/64)*2
local y = 20 + sin(t/128)*8
pal(7,8)
sspr(0,16,40,16,x-2,y,80,32)
sspr(0,16,40,16,x+2,y,80,32)
sspr(0,16,40,16,x,y+2,80,32)
sspr(0,16,40,16,x,y-2,80,32)
sspr(0,16,40,16,x-2,y-2,80,32)
sspr(0,16,40,16,x+2,y-2,80,32)
sspr(0,16,40,16,x-2,y+2,80,32)
sspr(0,16,40,16,x+2,y+2,80,32)
pal()
--normal
sspr(0,16,40,16,x,y,80,32)
end
-->8
--save/load scores
function load_highscore(dif)
return dget(dif)
end
function save_highscore(dif,score)
if score > load_highscore(dif) then
dset(dif,score)
highscore = score
end
end
-->8
--maps
function clear_map()
for i=0,127 do
for j=0,63 do
mset(i,j,0)
end
end
end
function set_block(gx,gy,c)
local cl = c or false
for i=0,3 do
for j=0,3 do
mset(gx+i,gy+j,16)
end
end
add(walls,{
x=gx*8,y=gy*8,col=cl
})
end
function setb(x,y,c)
local cl = c or false
set_block(x*4,y*4,cl)
end
function load_map(dif)
clear_map()
walls={}
--easy
if dif==0 then
setb(2,2)
setb(13,2,true)
setb(2,13,true)
setb(13,13)
for i=0,5 do
c=false
if((i+1)%2==0) c=true
setb(5+i,5,c)
setb(5+i,10,not c)
end
setb(3,7)
setb(3,8,true)
setb(12,7,true)
setb(12,8)
end
end
--map collision
function cmap(x,y,w,h)
local ww = w or 7
local hh = h or 7
local ct=false
-- if colliding with map tiles
local x1=x/8
local y1=y/8
local x2=(x+ww)/8
local y2=(y+hh)/8
local a=fget(mget(x1,y1),0)
local b=fget(mget(x1,y2),0)
local c=fget(mget(x2,y2),0)
local d=fget(mget(x2,y1),0)
ct=a or b or c or d
return ct
end
__gfx__
0000000000888800001111007777cccc000002222220000077777777777777777777777777777777088088000099900000999000222222222222222222222222
0000000008888880011111107777cccc0002222222222000777777777777777777777777777777778888878009aaa90009aaa900288228822882200220022002
0070070088888888111111117777cccc002222222222220077777777777777777777777777777777888888809a111a909a111a90888887788888000000000000
0007700088888888111111117777cccc022222222222222077777777777777777777777777777777088888009aa1aa909a1aaa90888888788888000000000000
000770008888888811111111cccc7777022222222222222077777777777777777777777777777777008880009a111a909a111a90888888888888000000000000
007007008888888811111111cccc77772222222222222222777777777777777777777777777777770008000009aaa90009aaa900288888822888000220000002
000000000888888001111110cccc7777222222222222222277777777777777777777777777777777000000000099900000999000228888222288002222000022
000000000088880000111100cccc7777222222222222222277777777777777777777777777777777000000000000000000000000222882222228022222200222
55555555000000000000000000000000222222222222222277777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000222222222222222277777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000222222222222222277777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000022222222222222077777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000022222222222222077777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000002222222222220077777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000000222222222200077777777777777777777777777777777000000000000000000000000000000000000000000000000
55555555000000000000000000000000000002222220000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070000000000000000000000000000077777700000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070000000000000000000000000000770000770000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
07777700077777007077077000777700700000070000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070000700000700700700707000070700000070000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070000777777700700700707000070700000070000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070000700000000700700707000070700000070000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00070070700000700700700707000070770000770000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00007700077777007707707707777700077777700000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000007000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000007000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000077700000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000077777777777777777777777777777777000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
00000000000000000000000000000000000000000000000066666666666666666666666666666666000000000000000000000000000000000000000000000000
__label__
00101115011115550050000051111111155500000500051000010001005551001101001110050155551500511001151105051101000011000100000551500005
01110110001155155550000111111111115101100550151001510051010010001111105100051115151115511100155105511105050110510000005551150001
11100000011115511100055501111111115011150000011511155100550001011111055510051115511110011055551505550015055105550000005515551511
01510000100015500110105100115155555555550110550001551000050015501010055505515111511100005555555515510501155510555511011111055550
11111115515501500151111001110505105510500115550001150000510005550001155000115510055510055511555515551151055111115015101110005555
01111155000005000501111000155550511051100500501000110001505011555011155005055515515505055515055000511115151011010055501101011555
55111055511115500510501501151500110001015551001000100011155515050001000010005155111010510055555150000555511111100155011115551150
05550555555550000050000515555155105051115510015100100111055015005001050001011115001005050015055005555555101101505551011155505151
00505011050500500555500515051111500551000151011501111101005111000005010011151150110010511110011055510501010055000055151555500555
00155511115510551055050115005111150110501550155555111010051015101101110111500555155011551551111010110505100555105001511101015515
11115011111501511510001550001511155555550151505051511005101051111150105510010050000505505508111558800051100055051011150051155115
00100001115001051100011155000111815555550515010515550001100555111055150511115500000111055550115555880808110110001110100000015155
00051010005550051100011111100018858855151115100011011010115055501151505515505155105050055500085511588000888010000111111005111115
55555505055551000000150111180888085811110155000050000105101510000555550115551555511550005518508515558000888515051111111000111155
55550505555015515000000011011808888851101555101818011005588550110058500115500855500508085111000888518800088111111111111001115051
55000515555105055001555580111188588555005858815588885515088881050810008185550000000050888811800058111880858815501155511100000005
15105551550000500501055518851888858858800818155550885550008511188110055888585880080518888811180555818888555555000055110010005505
55555515501001000555555500808888881588000888815500088518081851885058858180881105558188888588888051111858158111101051000510015055
05105155500000500155508808858888885158805818115550580008855555080015881111110000588858888880888011118555188110100015005000000055
05000115551015100055050808588888855558088111111588850005855550000058888181100055188888888888858888888818181000000110555500000515
50505111500101050551101000888888885555808515115888885088880508088888888880181555888888888888808880888888885150010000005510515555
51055511051111155551111108888888808158888858581888888188888018888888888888011158888888888888888888888888880515511550011100511511
11100001151100055551051888888888888881888885558888181118888111888108888851001008888888888888888888888888085110111151551100051111
51555055151150000551555888887788888881188888588888888888888888881118888808888888888888887777777777778888008510010111111010011115
55555551555511055011058888887788888851888888888888888888888888888888888888888881818888887777777777778888058851111501111100001000
51555151151051500510008888887788888855888888888888888888888888888888880888888888888888777788888888777788888055111000110515011105
15155510111111555555018888887788888888888888888888888888888888888888888888888888888888777788888888777788855555500000105551151000
55510011011511555550518877777777778888887777777777888877887777887777888888777777778888778888508188887788555551000001011555110055
05010555105555550500118877777777778888887777777777888877887777887777888888777777778888778888888888887788815115001055555055105150
55500001155551500000118888887788888888778888888888778888778888778888778877888888887788778800088188887788111110011150555555500105
15100005555555500000118888887788888888778888888888778888778888778888778877888888887788778880880888887788818110011155055005551115
01110000051115550101111110887788855588777777777777778888778888778888778877888885887788778888800088887788881110111150505000501111
05151000005155551010110150887788888888777777777777778888778888778888778877888888887788778888080818887788880110110100000100000051
55115505010050501101115000887788888888778888888888888888778888778888778877888888887788778888008188887788885500101000051111100555
00111551110005111010055000887788888888778888888888888888778888778888778877888888887788778888088888887788885000000501055111110055
00010055510001111000005550887788887788778888888888778888778888778888778877888888887788777788888888777788855501100005151511150101
05050515500001111101015050887788887788778888888888778888778888778888778877888888887788777788888888777788555551000000011150115515
55505555150100151010111100888877778888887777777777888877778877778877778877777777778888887777777777778888155110005005501055055555
55555555511110011515001551888877778888887777777777888877778877778877778877777777778888887777777777778888015111000015050550005505
05555015101501115550001555108888888855888888888888888888888888888888888877888888888851888888888888888810011115011111000055011501
55515111100511110500011555008888888850888888888888888888888888888888888877888888888805888888888888888801511111111110000000115515
15500110005551100001011105855511055001555111050151015550005850001555888877888888111000501555001551111010001111151505551005110515
55115100055510550000501555015115151550050000555005510150005515011151888877888888015000050055511105115101000511115005550101110011
55551110005100051105555555050155115155015005551155550555515550551110887777778885001500000001111000050011001105050015550000001015
55555111051100001010555555551510551550005150551155500551111155515105887777778880055150151011111000005011101005111115550505500505
05551110555550515000555555550111150110015550550555005551155505111015888888888800011111550501010100055511151055111015500515550110
51110100555555515505055155511010111100000051051155505515155111111151888888888800111011105555501150555110555001000005000055500111
11100010051511055550505555510505010111005011050111155500515111111110105550505010110001000555551555555100050151111010000115551115
11100010110111150100015555551055500010105101150101005000111501005011001511550151115010011115011155155500001115501115000110501105
50000000050011555110055555555115010001155000555111111110010050155551111110555550105511111155101001011510010155501151505115100551
00000550500005050150115555550105111001055501555111551111555111115551151101550155000500110005100555111055111505015555001111501051
00550555055105511151111555000005510010115155555511100010155011155551551015500155500150011555150551110005111010010055510010501550
00055050555515550111011551510000000050111555515111501500000000005551051555550505001115001151110005505051111055000055500115511100
00500500555110500150111101011001000111151055551001000505000001000500005555555550000155511010100151110005111155500005500010011550
01050511511110001115111511151100051150555501500011105551105511101100005051555151010515150100000000101150111555050115550500115055
11101115111550001155011011511101055100155551105115000550105551051115000501151511105151555050100005110115511105150010505501010551
51550150011555000150101105015000101050011550551111101101000510005111005000501511150515055051500055015555511550505050000555055501
50550055110155100555001550111500010000551110155115015555505155015511111005555551005115510005100011155050550550110010505550555000
55555555100001150551105510015100000001055000555015555550555555101555111000551155105110051051000551110005550051111100151500155500
55550155015505000011515500005110115150150005050055555555015555000555015000011111510100005505555555101110500055115000555000015100
00500115555500001115551550155511101551115051505005511155555555000111110000111101100010000000150501001111000000550000051100105550
05000055550100011111515555115151101155151105000505151511015150105111100000011051005000110101550511150111100005011050551100005515
05550115050015551005115505515511110001110101505555155111111111155510510500150500005501015111500111055511100010110155511100000111
55555110500050505551150100555551115551151111100055515551550110111555555550055551005115510110000010005055100151151115111110105510
051550555505550050005550000055015550110550115011ccc05055ccccccc1ccccccccc00115ccc01111555550500155011555000551550101115110515051
055105555000551500000555000000001550110001155511c7cc1155c777c7c1c777c7c7c1111cc7c55011155551151111510505100001155515551115110115