-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit11.p8
2127 lines (1945 loc) · 82.7 KB
/
edit11.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 30
__lua__
--config
conf_level=1
conf_player=nil
preload_seg=[[]]
-->8
--smalleste2 1.1 editor version
--some gfx cut
level_index,level_intro=0,0
function game_start()
-- reset state
snow,clouds,
freeze_time,frames,seconds,minutes,shake,sfx_timer,
berry_count,death_count,
collected,show_score,
camera_x,camera_y=
{},{},
0,0,0,0,0,0,
0,0,
{},0,
0,0
for i=0,25 do
add(snow,{x=rnd(132),y=rnd(132)})
add(clouds,{x=rnd(132),y=rnd(132),s=16+rnd(32)})
end
-- goto titlescreen or level
if level_index==0 then
current_music=38
music(current_music)
else
goto_level(level_index)
end
end
function _init()
game_start()
end
function _update()
-- titlescreen
if level_index==0 then
if titlescreen_flash then
titlescreen_flash-=1
if titlescreen_flash<-30 then goto_level(1) end
elseif btn(4) or btn(5) then
titlescreen_flash=50
sfx(22,3)
end
-- level intro card
elseif level_intro>0 then
level_intro-=1
if level_intro==0 then psfx(17,24,9) end
-- normal level
else
-- timers
sfx_timer=max(sfx_timer-1)
infade=min(infade+1,60)
shake=max(shake-1)
if level_index~=8 then
frames+=1
seconds+=frames\30
minutes+=seconds\60
seconds%=60
frames%=30
end
update_input()
--freeze
if freeze_time>0 then
freeze_time-=1
else
--objects
for o in all(objects) do
if o.freeze>0 then
o.freeze-=1
else
o:update()
end
if o.destroyed then
del(objects,o)
end
end
end
end
end
function _draw()
pal()
if level_index==0 then
cls(0)
if titlescreen_flash then
local c=titlescreen_flash>10 and (titlescreen_flash%10<5 and 7 or 10) or titlescreen_flash>5 and 2 or titlescreen_flash>0 and 1 or 0
if c<10 then for i=0,15 do pal(i,c) end end
end
sspr(64,32,64,32,36,32)
rect(0,0,127,127,7)
print_center("lani's trek",68,14)
print_center("a game by",80,1)
print_center("maddy thorson",87,5)
print_center("noel berry",94,5)
print_center("lena raine",101,5)
-- draw_snow()
return
end
if level_intro>0 then
cls()
camera()
draw_time(4,4)
if level_index~=8 then
print_center("level "..(level_index-2),56, 7)
end
print_center(level.title,64,7)
return
end
local camera_x,camera_y=peek2(0x5f28),peek2(0x5f2a)
if shake>0 then
camera(camera_x-2+rnd(5),camera_y-2+rnd(5))
end
-- clear screen
cls(level and level.bg or 0)
-- draw clouds
-- draw_clouds(1,0,0,1,1,level.clouds or 13,#clouds)
-- columns
if level.columns then
fillp(0b0000100000000010.1)
local x=0
while x<level.width do
local tx=x*8+camera_x*0.1
rectfill(tx,0,tx+(x%2)*8+8,level.height*8,level.columns)
x+=1+x%7
end
fillp()
end
-- draw tileset
for x=mid(0,camera_x\8,level.width),mid(0,(camera_x+128)\8,level.width) do
for y=mid(0,camera_y\8,level.height),mid(0,(camera_y+128)\8,level.height) do
local tile=tile_at(x, y)
if level.pal and fget(tile,7) then level.pal() end
if tile~=0 and fget(tile,0) then spr(tile,x*8,y*8) end
pal() palt()
end
end
-- score
if show_score>105 then
rectfill(34,392,98,434,1)
rectfill(32,390,96,432,0)
rect(32,390,96,432,7)
spr(21,44,396)
?"x "..berry_count,56,398,7
spr(87,44,408)
draw_time(56,408)
spr(71,44,420)
?"x "..death_count,56,421,7
end
-- draw objects
local p
for o in all(objects) do
if o.base==player then p=o else o:draw() end
end
if p then p:draw() end
-- draw snow
-- draw_snow()
-- draw fg clouds
if level.fogmode then
if level.fogmode==1 then fillp(0b0101101001011010.1) end
-- draw_clouds(1.25,0,level.height*8+1,1,0,7,#clouds-10)
fillp()
end
camera()
-- screen wipes
-- very similar functions ... can they be compressed into one?
if p and p.wipe_timer>5 then
for i=0,127 do
rectfill(0,i,191*(p.wipe_timer-5)/12-32+sin(i*0.2)*16+(127-i)*0.25,i,0)
end
end
if infade<15 then
for i=0,127 do
rectfill(191*infade/12-32+sin(i*0.2)*16+(127-i)*0.25,i,128,i,0)
end
end
-- game timer
if infade<45 then
draw_time(4,4)
end
camera(camera_x,camera_y)
end
function draw_time(x,y)
local m,h=minutes%60,minutes\60
rectfill(x,y,x+32,y+6,0)
?two_digit_str(h)..":"..two_digit_str(m)..":"..two_digit_str(seconds),x+1,y+1,7
end
function two_digit_str(x)
return x<10 and "0"..x or x
end
--function draw_clouds(scale,ox,oy,sx,sy,color,count)
-- for i=1,count do
-- local c=clouds[i]
-- local s=c.s*scale
-- local x,y=ox+(camera_x+(c.x-camera_x*0.9)%(128+s)-s/2)*sx,oy+(camera_y+(c.y-camera_y*0.9)%(128+s/2))*sy
-- clip(x-s/2-camera_x,y-s/2-camera_y,s,s/2)
-- circfill(x,y,s/3,color)
-- if i%2==0 then
-- circfill(x-s/3,y,s/5,color)
-- circfill(x+s/3,y,s/6,color)
-- end
-- c.x+=(4-i%4)*0.25
-- end
-- clip(0,0,128,128)
--end
--function draw_snow()
-- for i,s in pairs(snow) do
-- circfill(camera_x+(s.x-camera_x*0.5)%132-2,camera_y+(s.y-camera_y*0.5)%132,i%2,7)
-- s.x+=4-i%4
-- s.y+=sin(time()*0.25+i*0.1)
-- end
--end
function print_center(text,y,c)
?text,64-2*#text-0.5,y,c
end
function approach(x,target,max_delta)
return x<target and min(x+max_delta,target) or max(x-max_delta,target)
end
function psfx(id,off,len,lock)
if sfx_timer<=0 or lock then
sfx(id,3,off,len)
if lock then sfx_timer=lock end
end
end
function draw_sine_h(x0,x1,y,col,amplitude,time_freq,x_freq,fade_x_dist)
pset(x0,y,col)
pset(x1,y,col)
local x_sign,x_max,last_y,this_y=sgn(x1-x0),abs(x1-x0)-1,y
for i=1,x_max do
local fade=i<=fade_x_dist and i/(fade_x_dist+1) or i>x_max-fade_x_dist+1 and (x_max+1-i)/(fade_x_dist+1) or 1
local ax,ay=x0+i*x_sign,y+sin(time()*time_freq+i*x_freq)*amplitude*fade
pset(ax,ay+1,1)
pset(ax,ay,col)
this_y=ay
while abs(ay-last_y)>1 do
ay-=sgn(this_y-last_y)
pset(ax-x_sign,ay+1,1)
pset(ax-x_sign,ay,col)
end
last_y=this_y
end
end
levels={
{
offset=0,
width=96,
height=16,
camera_mode=1,
music=38,
},
{
offset=343,
width=32,
height=32,
camera_mode=2,
music=36,
fogmode=1,
clouds=0,
columns=1
},
{
offset=679,
width=128,
height=22,
camera_mode=3,
camera_barriers_x={38},
camera_barrier_y=6,
music=2,
title="trailhead"
},
{
offset=1313,
width=128,
height=32,
camera_mode=4,
music=2,
title = "glacial caves",
pal=function() pal(2,12) pal(5,2) end,
columns = 1
},
{
offset=2411,
width=128,
height=16,
camera_mode=5,
music=2,
title="golden valley",
pal=function() pal(2,14) pal(5,2) end,
bg=13,
clouds=15,
fogmode=2
},
{
offset=2645,
width=128,
height=16,
camera_mode=6,
camera_barriers_x={105},
music=2,
pal=function() pal(2,14) pal(5,2) end,
bg=13,
clouds=15,
fogmode=2
},
{
offset=2880,
width=128,
height=16,
camera_mode=7,
music=2,
pal=function() pal(2,12) pal(5,2) end,
bg=13,
clouds=7,
fogmode=2,
},
{
offset=3079,
width=16,
height=62,
title="destination",
camera_mode=8,
music=2,
pal=function() pal(2, 1) pal(7, 11) end,
bg=15,
clouds=7,
fogmode=2,
right_edge=true
}
}
function camera_x_barrier(tile_x,px,py)
local bx=tile_x*8
if px<bx-8 then
camera_target_x=min(camera_target_x,bx-128)
elseif px>bx+8 then
camera_target_x=max(camera_target_x,bx)
end
end
c_offset=0
camera_modes={
-- 1: intro
function (px,py)
camera_target_x=px<42 and 0 or mid(px-48,40,level.width*8-128)
end,
-- 2: intro 2
function (px,py)
camera_target_x,camera_target_y=px<120 and 0 or px>136 and 128 or px-64,mid(py-64,0,level.height*8-128)
end,
-- 3: level 1
function (px,py)
camera_target_x,camera_target_y=mid(px-56,0,level.width*8-128),py<level.camera_barrier_y*8+3 and 0 or level.camera_barrier_y*8
for i,b in ipairs(level.camera_barriers_x) do
camera_x_barrier(b,px,py)
end
end,
-- 4: level 2
function (px,py)
if px%128>8 and px%128<120 then
px=(px\128)*128+64
end
if py%128>4 and py%128<124 then
py=(py\128)*128+64
end
camera_target_x,camera_target_y=mid(px-64,0,level.width*8-128),mid(py-64,0,level.height*8-128)
end,
-- 5: level 3-1
function (px,py)
camera_target_x=mid(px-32,0,level.width*8-128)
end,
-- 6: level 3-2
function (px,py)
if px>848 then
c_offset=48
elseif px<704 then
c_flag=false
c_offset=32
elseif px>808 then
c_flag=true
c_offset=96
end
camera_target_x=mid(px-c_offset,0,level.width*8-128)
for i,b in ipairs(level.camera_barriers_x) do
camera_x_barrier(b,px,py)
end
if c_flag then
camera_target_x=max(camera_target_x,672)
end
end,
--7: level 3-3
function (px,py)
c_offset=px>420 and (px<436 and px-388 or px>808 and 48-min(16,px-808) or 48) or 32
camera_target_x=mid(px-c_offset,0,level.width*8-128)
end,
--8: end
function (px,py)
camera_target_y=mid(py-32,0,level.height*8-128)
end
}
function snap_camera()
camera_x,camera_y=camera_target_x,camera_target_y
camera(camera_x,camera_y)
end
function tile_y(py)
return mid(py\8,0,level.height-1)--max(0,min(py\8,level.height-1))
end
function goto_level(index)
-- set level
level,level_index,level_checkpoint=levels[index],index,nil
if level.title then
level_intro=60
end
if level_index==2 then
psfx(17,8,16)
end
-- load into ram
local function vget(x,y) return peek(0x4300+x+y*level.width) end
local function vset(x,y,v) return poke(0x4300+x+y*level.width,v) end
px9_decomp(0,0,0x1000+level.offset,vget,vset)
-- start music
if current_music~=level.music and level.music then
current_music=level.music
music(level.music)
end
-- load level contents
restart_level()
end
function next_level()
level_index+=1
goto_level(level_index)
end
function restart_level()
camera_x,camera_y,camera_target_x,camera_target_y,
objects,
infade,have_grapple,sfx_timer=
0,0,0,0,
{},
0,level_index>2,0
for i=0,level.width-1 do
for j=0,level.height-1 do
local t=types[tile_at(i,j)]
if t and not collected[id(i,j)] and (not level_checkpoint or t~=player) then
create(t,i*8,j*8)
end
end
end
end
-- gets the tile at the given location from the loaded level
function tile_at(x,y)
return x<0 or y<0 or x>=level.width or y>=level.height and 0 or peek(0x4300+x+y*level.width)
end
input_x,input_jump_pressed,input_grapple_pressed,axis_x_value=0,0,0,0
function update_input()
-- axes
local prev_x=axis_x_value
if btn(0) then
if btn(1) then
if axis_x_turned then
axis_x_value,input_x=prev_x,prev_x
else
axis_x_turned,axis_x_value,input_x=true,-prev_x,-prev_x
end
else
axis_x_turned,axis_x_value,input_x=false,-1,-1
end
else
local b=btn(1) and 1 or 0
axis_x_turned,axis_x_value,input_x=false,b,b
end
-- input_jump
local jump=btn(4)
input_jump_pressed,input_jump=jump and not input_jump and 4 or jump and max(0,input_jump_pressed-1) or 0,jump
-- input_grapple
local grapple=btn(5)
input_grapple_pressed,input_grapple=grapple and not input_grapple and 4 or grapple and max(0,input_grapple_pressed-1) or 0,grapple
end
function consume_jump_press()
local val=input_jump_pressed>0
input_jump_pressed=0
return val
end
function consume_grapple_press()
local val=input_grapple_pressed>0
input_grapple_pressed=0
return val
end
objects,types,lookup={},{},{}
function lookup.__index(self, i) return self.base[i] end
object = {
speed_x=0,
speed_y=0,
remainder_x=0,
remainder_y=0,
hit_x=0,
hit_y=0,
hit_w=8,
hit_h=8,
grapple_mode=0,
hazard=0,
facing=1,
freeze=0
}
function object.move_x(self,x,on_collide)
self.remainder_x+=x
local mx=flr(self.remainder_x+0.5)
self.remainder_x-=mx
local total,mxs=mx,sgn(mx)
while mx~=0
do
if self:check_solid(mxs,0) then
if on_collide then
return on_collide(self,total-mx,total)
end
return true
else
self.x+=mxs
mx-=mxs
end
end
end
function object.move_y(self,y,on_collide)
self.remainder_y+=y
local my=flr(self.remainder_y+0.5)
self.remainder_y-=my
local total,mys=my,sgn(my)
local mys=sgn(my)
while my~=0
do
if self:check_solid(0,mys) then
if on_collide then
return on_collide(self,total-my,total)
end
return true
else
self.y+=mys
my-=mys
end
end
end
function object.on_collide_x(self,moved,target)
self.remainder_x,self.speed_x=0,0
return true
end
function object.on_collide_y(self,moved,target)
self.remainder_y,self.speed_y=0,0
return true
end
function object.update() end
function object.draw(self)
spr(self.spr,self.x,self.y,1,1,self.flip_x,self.flip_y)
end
function object.overlaps(self,b,ox,oy)
if self==b then return end
ox,oy=ox or 0,oy or 0
return
ox+self.x+self.hit_x+self.hit_w>b.x+b.hit_x and
oy+self.y+self.hit_y+self.hit_h>b.y+b.hit_y and
ox+self.x+self.hit_x<b.x+b.hit_x+b.hit_w and
oy+self.y+self.hit_y<b.y+b.hit_y+b.hit_h
end
function object.contains(self,px,py)
return
px>=self.x+self.hit_x and
px<self.x+self.hit_x+self.hit_w and
py>=self.y+self.hit_y and
py<self.y+self.hit_y+self.hit_h
end
function object.check_solid(self, ox, oy)
ox,oy=ox or 0,oy or 0
for i=(ox + self.x + self.hit_x)\8,(ox + self.x + self.hit_x + self.hit_w-1)\8 do
for j=tile_y(oy+self.y+self.hit_y),tile_y(oy+self.y+self.hit_y+self.hit_h-1) do
if fget(tile_at(i, j),1) then
return true
end
end
end
for o in all(objects) do
if o.solid and o~=self and not o.destroyed and self:overlaps(o, ox, oy) then
return true
end
end
end
function object.corner_correct(self,dir_x,dir_y,side_dist,look_ahead,only_sign,func)
look_ahead,only_sign=look_ahead or 1,only_sign or 1
if dir_x~=0 then
for i=1,side_dist do
for s=1,-2,-2 do
if s==-only_sign then
goto continue_x
end
if not self:check_solid(dir_x,i*s) and (not func or func(self,dir_x,i*s)) then
self.x+=dir_x
self.y+=i*s
return true
end
::continue_x::
end
end
elseif dir_y~=0 then
for i=1,side_dist do
for s=1,-1,-2 do
if s==-only_sign then
goto continue_y
end
if not self:check_solid(i*s,dir_y) and (not func or func(self,i*s,dir_y)) then
self.x+=i*s
self.y+=dir_y
return true
end
::continue_y::
end
end
end
end
function id(tx,ty) return level_index*100+flr(tx)+flr(ty)*128 end
function create(type,x,y)
local obj=setmetatable({
base=type,
x=x,
y=y,
id=id(x\8,y\8)
},lookup)
add(objects, obj);
(obj.init or stat)(obj)
return obj
end
function new_type(spr)
local obj=setmetatable({
spr=spr,
base=object
},lookup)
types[spr]=obj--add(types, obj)
return obj
end
grapple_pickup=new_type(20)
function grapple_pickup.draw(self)
spr(self.spr,self.x,self.y+sin(time())*2,1,1,not self.right)
end
spike_v=new_type(36)
function spike_v.init(self)
if not self:check_solid(0,1) then
self.flip_y,self.hazard=true,3
else
self.hit_y,self.hazard=5,2
end
self.hit_h = 3
end
spike_h=new_type(37)
function spike_h.init(self)
if self:check_solid(-1,0) then
self.flip_x,self.hazard=true,4
else
self.hit_x,self.hazard=5,5
end
self.hit_w=3
end
snowball=new_type(62)
snowball.grapple_mode,snowball.holdable,snowball.thrown_timer,snowball.hp=3,true,0,6
function snowball.update(self)
if not self.held then
self.thrown_timer -= 1
--speed
if self.stop then
self.speed_x=approach(self.speed_x,0,0.25)
if self.speed_x==0 then
self.stop=false
end
else
if self.speed_x~=0 then
self.speed_x=approach(self.speed_x,sgn(self.speed_x)*2,0.1)
end
end
--gravity
if not self:check_solid(0,1) then
self.speed_y=approach(self.speed_y,4,0.4)
end
--apply
self:move_x(self.speed_x,self.on_collide_x)
self:move_y(self.speed_y,self.on_collide_y)
--bounds
if self.y>level.height*8+24 then
self.destroyed=true
end
end
end
function snowball.on_collide_x(self,moved,total)
if self:corner_correct(sgn(self.speed_x),0,2,2,1) then
return
end
if self:hurt() then
return true
end
self.speed_x*=-1
self.remainder_x,self.freeze=0,1
psfx(17,0,2)
return true
end
function snowball.on_collide_y(self)--,moved,total)
if self.speed_y>=4 then
self.speed_y=-2
psfx(17,0,2)
elseif self.speed_y>=1 then
self.speed_y=-1
psfx(17,0,2)
else
self.speed_y=0
end
self.remainder_y=0
return true
end
function snowball.on_release(self,thrown)
if not thrown then
self.stop=true
end
self.thrown_timer=8
end
function snowball.hurt(self)
self.hp-=1
if self.hp<=0 then
psfx(8,16,4)
self.destroyed=true
return true
end
end
function snowball.bounce_overlaps(self,o)
if self.speed_x~=0 then
self.hit_w,self.hit_x=12,-2
local ret=self:overlaps(o)
self.hit_w,self.hit_x=8,0
return ret
end
return self:overlaps(o)
end
function snowball.contains(self,px,py)
return px>=self.x and px<self.x+8 and py>=self.y-1 and py<self.y+10
end
function snowball.draw(self)
pal(7,1)
spr(self.spr,self.x,self.y+1)
pal()
spr(self.spr,self.x,self.y)
end
springboard=new_type(11)
springboard.grapple_mode,springboard.holdable,springboard.thrown_timer=3,true,0
function springboard.update(self)
if not self.held then
self.thrown_timer-=1
--friction and gravity
if self:check_solid(0,1) then
self.speed_x=approach(self.speed_x,0,1)
else
self.speed_x=approach(self.speed_x,0,0.2)
self.speed_y=approach(self.speed_y,4,0.4)
end
--apply
self:move_x(self.speed_x,self.on_collide_x)
self:move_y(self.speed_y,self.on_collide_y)
if self.player then
self.player:move_y(self.speed_y)
end
self.destroyed=self.y>level.height*8+24
end
end
function springboard.on_collide_x(self,moved,total)
self.speed_x*=-0.2
self.remainder_x,self.freeze=0,1
return true
end
function springboard.on_collide_y(self,moved,total)
if self.speed_y<0 then
self.speed_y,self.remainder_y=0,0
return true
end
if self.speed_y>=2 then
self.speed_y*=-0.4
else
self.speed_y=0
end
self.remainder_y=0
self.speed_x*=0.5
return true
end
function springboard.on_release(self,thrown)
if thrown then
self.thrown_timer=5
end
end
grappler=new_type(46)
grappler.grapple_mode,grappler.hit_x,grappler.hit_y,grappler.hit_w,grappler.hit_h=2,-1,-1,10,10
bridge=new_type(63)
function bridge.update(self)
self.y+=self.falling and 3 or 0
end
berry=new_type(21)
function berry.update(self)
if self.collected then
self.timer+=1
self.y-=0.2*(self.timer > 5 and 1 or 0)
self.destroyed=self.timer > 30
elseif self.player then
self.x+=(self.player.x-self.x)/8
self.y+=(self.player.y-4-self.y)/8
self.flash-=1
if self.player:check_solid(0,1) and self.player.state~=99 then self.ground+=1 else self.ground=0 end
if self.ground>3 or self.player.x>level.width*8-7 or self.player.last_berry~=self then
psfx(8,8,8,20)
collected[self.id]=true
berry_count+=1
self.collected,self.timer,self.draw=true,0,score
end
end
end
function berry.collect(self,player)
if not self.player then
self.player,player.last_berry,self.flash,self.ground=player,self,5,0
psfx(7,12,4)
end
end
function berry.draw(self)
if (self.timer or 0)<5 then
grapple_pickup.draw(self)
if (self.flash or 0)>0 then
circ(self.x+4,self.y+4,self.flash*3,7)
circfill(self.x+4,self.y+4,5,7)
end
else
?"1000",self.x-4,self.y+1,8
?"1000",self.x-4,self.y,self.timer%4<2 and 7 or 14
end
end
crumble=new_type(19)
crumble.solid,crumble.grapple_mode=true,1
function crumble.init(self)
self.time,self.ox,self.oy=0,self.x,self.y
end
function crumble.update(self)
if self.breaking then
self.time+=1
if self.time>10 then
self.x,self.y=-32,-32
end
if self.time>90 then
self.x,self.y=self.ox,self.oy
local can_respawn=true
for o in all(objects) do
if self:overlaps(o) then can_respawn=false break end
end
if can_respawn then
self.breaking,self.time=false,0
psfx(17,5,3)
else
self.x,self.y=-32,-32
end
end
end
end
function crumble.draw(self)
object.draw(self)
if self.time>2 then
fillp(0b1010010110100101.1)
rectfill(self.x,self.y,self.x+7,self.y+7,1)
fillp()
end
end
checkpoint=new_type(13)
function checkpoint.init(self)
if level_checkpoint==self.id then
create(player,self.x,self.y)
end
end
function checkpoint.draw(self)
if level_checkpoint==self.id then
sspr(104,0,1,8,self.x,self.y)
pal(2,11)
for i=1,7 do
sspr(104+i,0,1,8,self.x+i,self.y+sin(-time()*2+i*0.25)*(i-1)*0.2)
end
pal()
else
object.draw(self)
end
end
function make_spawner(tile,dir)
local spawner=new_type(tile)
function spawner.init(self)
self.timer,self.spr=(self.x/8)%32,-1
end
function spawner.update(self)
self.timer+=1
if self.timer>=32 and abs(self.x-64-camera_x)<128 then
self.timer=0
local snowball=create(snowball,self.x,self.y-8)
snowball.speed_x,snowball.speed_y=dir*2,4
psfx(17,5,3)
end
end
return spawner
end
snowball_spawner_r,snowball_spawner_l=make_spawner(14,1),make_spawner(15,-1)
player=new_type(2)
player.t_jump_grace,
player.t_var_jump,
player.var_jump_speed,
player.grapple_x,
player.grapple_y,
player.grapple_dir,
player.grapple_wave,
player.t_grapple_cooldown,
player.wipe_timer,