-
Notifications
You must be signed in to change notification settings - Fork 12
/
reflection.p8
1847 lines (1674 loc) · 71.5 KB
/
reflection.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 41
__lua__
--newleste.p8 base cart
--original game by:
--maddy thorson + noel berry
-- based on evercore v2.0.2
--with major project contributions by
--taco360, meep, gonengazit, and akliant
-- [data structures]
function vector(x,y)
return {x=x,y=y}
end
function rectangle(x,y,w,h)
return {x=x,y=y,w=w,h=h}
end
-- [globals]
objects,got_fruit, --tables
freeze,delay_restart,sfx_timer,ui_timer, --timers
cam_x,cam_y,cam_spdx,cam_spdy,cam_gain,cam_offx,cam_offy, --camera values <camtrigger>
_pal, --for outlining
shake,screenshake
=
{},{},
0,0,0,-99,
0,0,0,0,0.1,0,0,
pal,
0,false
local _g=_ENV --for writing to global vars
-- [entry point]
function _init()
max_djump,deaths,frames,seconds,minutes,time_ticking,berry_count=1,0,0,0,0,true,0
music(0,0,7)
load_level(1)
end
-- [effects]
clouds={}
for i=0,16 do
add(clouds,{
x=rnd"128",
y=rnd"128",
spd=1+rnd"4",
w=32+rnd"32"
})
end
particles={}
for i=0,24 do
add(particles,{
x=rnd"128",
y=rnd"128",
s=flr(rnd"1.25"),
spd=0.25+rnd"5",
off=rnd(),
c=6+rnd"2",
})
end
dead_particles={}
-- [player entity]
player={
init=function(_ENV)
djump, hitbox, collides,layer = max_djump, rectangle(1,3,6,5), true,2
--<fruitrain>--
-- ^ refers to setting berry_timer and berry_count to 0
foreach(split"grace,jbuffer,dash_time,dash_effect_time,dash_target_x,dash_target_y,dash_accel_x,dash_accel_y,spr_off,berry_timer,berry_count", function(var)
_ENV[var]=0
end)
create_hair(_ENV)
end,
update=function(_ENV)
if pause_player then
return
end
-- horizontal input
local h_input=split"0,-1,1,1"[btn()%4+1]
-- <feather> --
-- vertical input
local v_input=btn(⬆️) and -1 or btn(⬇️) and 1 or 0
-- update feather particles (update remaining ones if not in feather state)
foreach(feather_particles, function(p)
p.x+=p.xspd
p.y+=p.yspd
p.xspd=appr(p.xspd, 0, 0.03)
p.yspd=appr(p.yspd, 0, 0.03)
p.life-=1
if p.life==0 then
del(feather_particles, p)
end
end)
-- </feather> --
-- spike collision / bottom death
if is_flag(0,0,-1) or
y>lvl_ph and not exit_bottom then
kill_player(_ENV)
end
if feather_state then
local k=1
if h_input!=0 or v_input!=0 then
-- calculate direction and velocity
movedir=appr_circ(movedir,atan2(h_input,v_input),0.04)
-- speed up if holding button
k=1.5
end
spd = vector(k*cos(movedir), k*sin(movedir))
-- update tail
local last=vector(x+4.5,y+4.5)
foreach(tail,function(h)
h.x+=(last.x-h.x)/1.4
h.y+=(last.y-h.y)/1.4
last=h
end)
--bounce off objects
if bouncetimer==0 then
if is_solid(0, 2) or is_solid(0, -2) then
movedir *=-1
bouncetimer = 2
init_smoke()
elseif is_solid(2, 0) or is_solid(-2, 0) then
movedir = round(movedir)+0.5-movedir
bouncetimer = 2
init_smoke()
end
end
--make sure we dont bounce too often
if bouncetimer > 0 then
bouncetimer-=1
end
-- feather particles
local particle = {x=x+rnd"8"-4, y=y+rnd"8"-4, life=10+flr(rnd"5")}
particle.xspd = -spd.x/2-(x-particle.x)/4
particle.yspd = -spd.y/2-(y-particle.y)/4
add(feather_particles, particle)
lifetime-=1
if lifetime==0 or btn(❎) then
-- transform back to player
p_dash=false
feather_state=false
init_smoke()
player.init(_ENV)
spd.x/=2
spd.y=spd.y<0 and -1.5 or 0
end
elseif feather_idle then
spd.x*=0.8
spd.y*=0.8
spawn_timer-=1
if spawn_timer==0 then
feather_idle=false
feather_state=true
if h_input==0 and v_input==0 then
movedir=flip.x and 0.5 or 0
else
movedir=atan2(h_input,v_input)
end
lifetime=60
bouncetimer=0
tail={}
feather_particles={}
for i=0,15 do
add(tail,{x=x+4,y=y+4,size=mid(1,2,9-i)})
end
end
end
if not feather_state and not feather_idle then
-- cursed token save: use else and goto here
-- on ground checks
local on_ground=is_solid(0,1)
-- <fruitrain> --
if is_solid(0,1,true) then
berry_timer+=1
else
berry_timer, berry_count=0, 0
end
for i,f in inext,fruitrain do
if f.type==fruit and not f.golden and berry_timer>5 then
-- to be implemented:
-- save berry
-- save golden
berry_count+=1
_g.berry_count+=1
berry_timer, got_fruit[f.fruit_id]=-5, true
init_object(lifeup, f.x, f.y,berry_count)
del(fruitrain, f)
destroy_object(f);
(fruitrain[i] or {}).target=f.target
end
end
-- </fruitrain> --
-- landing smoke
if on_ground and not was_on_ground then
init_smoke(0,4)
end
-- jump and dash input
local jump,dash=btn(🅾️) and not p_jump,btn(❎) and not p_dash
p_jump,p_dash=btn(🅾️),btn(❎)
-- jump buffer
if jump then
jbuffer=5
end
jbuffer=max(jbuffer-1)
-- grace frames and dash restoration
if on_ground then
grace=7
if djump<max_djump then
psfx"22"
djump=max_djump
end
end
grace=max(grace-1)
-- dash effect timer (for dash-triggered events, e.g., berry blocks)
dash_effect_time-=1
-- dash startup period, accel toward dash target speed
if dash_time>0 then
init_smoke()
dash_time-=1
spd=vector(
appr(spd.x,dash_target_x,dash_accel_x),
appr(spd.y,dash_target_y,dash_accel_y)
)
else
-- x movement
local accel=on_ground and 0.6 or 0.4
-- set x speed
spd.x=abs(spd.x)<=1 and
appr(spd.x,h_input,accel) or
appr(spd.x,sign(spd.x),0.15)
-- facing direction
if spd.x~=0 then
flip.x=spd.x<0
end
-- y movement
local maxfall=2
-- wall slide
if is_solid(h_input,0) then
maxfall=0.4
-- wall slide smoke
if rnd()<0.2 then
init_smoke(h_input*6)
end
end
-- apply gravity
if not on_ground then
spd.y=appr(spd.y,maxfall,abs(spd.y)>0.15 and 0.21 or 0.105)
end
-- jump
if jbuffer>0 then
if grace>0 then
-- normal jump
psfx"18"
jbuffer,grace,spd.y=0,0,-2
init_smoke(0,4)
else
-- wall jump
local wall_dir=is_solid(-3,0) and -1 or is_solid(3,0) and 1
if wall_dir then
psfx"19"
jbuffer,spd=0,vector(wall_dir*-2,-2)
-- wall jump smoke
init_smoke(wall_dir*6)
end
end
end
-- dash
if dash then
if djump>0 then
init_smoke()
djump-=1
dash_time,_g.has_dashed,dash_effect_time=4, true, 10
-- calculate dash speeds
local dspd=h_input&v_input==0 and 5 or 3.5355339059
spd=vector(h_input~=0 and h_input*dspd or
v_input~=0 and 0 or flip.x and -1 or 1,
v_input*dspd)
-- effects
psfx"20"
_g.freeze,_g.shake=2,5
-- dash target speeds and accels
dash_target_x,dash_target_y,dash_accel_x,dash_accel_y=
2*sign(spd.x), split"-1.5,0,2"[v_input+2],
v_input==0 and 1.5 or 1.06066017177 , spd.x==0 and 1.5 or 1.06066017177 -- 1.5 * sqrt()
-- emulate soft dashes
if ph_input==-h_input and oob(ph_input,0) then
spd.x=0
end
else
-- failed dash smoke
psfx"21"
init_smoke()
end
end
end
-- animation
spr_off+=0.25
sprite = on_ground and (
btn(⬇️) and 6 or -- crouch
btn(⬆️) and 7 or -- look up
spd.x*h_input~=0 and 1+spr_off%4 or 1) -- walk or stand
or is_solid(h_input,0) and 5 or 3 -- wall slide or mid air
update_hair(_ENV)
-- was on the ground, previous horizontal input (for soft dashes)
was_on_ground,ph_input=on_ground, h_input
end
-- exit level (except summit)
if (exit_right and left()>=lvl_pw or
exit_top and y<-4 or
exit_left and right()<0 or
exit_bottom and top()>=lvl_ph) and levels[lvl_id+1] then
next_level()
end
end,
draw=function(_ENV)
--<feather> --
-- draw feather particles (if not in feather state draw remaining ones)
foreach(feather_particles, function(p)
pset(p.x+4, p.y+4,10)
end)
if feather_state then
if lifetime%5==1 then pal(10, 7) end
if lifetime < 10 then
pal(10, lifetime%4<2 and 8 or 10)
end
circfill(x+4, y+4, 4, 10)
foreach(tail,function(h)
circfill(h.x,h.y,h.size,10)
end)
elseif feather_idle then
circfill(x+4, y+4, 4, spawn_timer%4<2 and 7 or 10)
--</feather> --
else
-- draw player hair and sprite
pal(8,djump==1 and 8 or 12)
draw_hair(_ENV)
draw_obj_sprite(_ENV)
pal()
end
end
}
function create_hair(_ENV)
hair={}
for i=1,5 do
add(hair,vector(x,y))
end
end
function update_hair(_ENV)
local last=vector(x+(flip.x and 6 or 1),y+(btn(⬇️) and 4 or 2.9))
foreach(hair, function(h)
h.x+=(last.x-h.x)/1.5
h.y+=(last.y+0.5-h.y)/1.5
last=h
end)
end
function draw_hair(_ENV)
for i,h in inext,hair do
circfill(round(h.x),round(h.y),split"2,2,1,1,1"[i],8)
end
end
-- [other entities]
player_spawn={
init=function(_ENV)
layer=2
sfx"15"
sprite=3
target=y
y=min(y+48,lvl_ph)
_g.cam_x,_g.cam_y=mid(x,64,lvl_pw-64),mid(y,64,lvl_ph-64)
spd.y=-4
state=0
delay=0
create_hair(_ENV)
djump=max_djump
--- <fruitrain> ---
foreach(fruitrain, function(f)
--this gets called many times but saves tokens for checking if fruitrain is empty
fruitrain[1].target=_ENV
add(objects,f)
f.x,f.y=x,y
fruit.init(f)
end)
--- </fruitrain> ---
end,
update=function(_ENV)
-- jumping up
if state==0 and y<target+16 then
state,delay=1, 3
-- falling
elseif state==1 then
spd.y+=0.5
if spd.y>0 then
if delay>0 then
-- stall at peak
spd.y=0
delay-=1
elseif y>target then
-- clamp at target y
y,spd,state,delay,_g.shake=target,vector(0,0),2,5,4
init_smoke(0,4)
sfx"16"
end
end
-- landing and spawning player object
elseif state==2 then
delay-=1
sprite=6
if delay<0 then
destroy_object(_ENV)
local p=init_object(player,x,y);
--- <fruitrain> ---
(fruitrain[1] or {}).target=p
--- </fruitrain> ---
end
end
update_hair(_ENV)
end,
draw=player.draw
-- draw=function(this)
-- set_hair_color(max_djump)
-- draw_hair(this,1)
-- draw_obj_sprite(this)
-- unset_hair_color()
-- end
}
--<camtrigger>--
camera_trigger={
update=function(_ENV)
if timer and timer>0 then
timer-=1
if timer==0 then
_g.cam_offx,_g.cam_offy=offx,offy
else
_g.cam_offx+=cam_gain*(offx-cam_offx)
_g.cam_offy+=cam_gain*(offy-cam_offy)
end
elseif player_here() then
timer=5
end
end
}
--</camtrigger>--
spring={
init=function(_ENV)
delta,dir=0,sprite==9 and 0 or is_solid(-1,0) and 1 or -1
end,
update=function(_ENV)
delta*=0.75
--can save tokens by setting hit as _ENV
--but i'm not desperate enough yet
local hit=player_here()
if hit then
if dir==0 then
hit.move(0,y-hit.y-4,1)
hit.spd.x*=0.2
hit.spd.y=-3
else
hit.move(x+dir*4-hit.x,0,1)
hit.spd=vector(dir*3,-1.5)
end
hit.dash_time,hit.dash_effect_time,delta,hit.djump,hit.movedir=0,0,4,max_djump,.25-.25*dir
end
end,
draw=function(_ENV)
local delta=flr(delta)
if dir==0 then
sspr(72,0,8,8-delta,x,y+delta)
else
spr(8,dir==-1 and x+delta or x,y,1-delta/8,1,dir==1)
end
end
}
refill={
init=function(_ENV)
offset,timer,hitbox=rnd(),0,rectangle(-1,-1,10,10)
end,
update=function(_ENV)
if timer>0 then
timer-=1
if timer==0 then
psfx"12"
init_smoke()
end
else
offset+=0.02
local hit=player_here()
if hit and hit.djump<max_djump then
psfx"11"
init_smoke()
hit.djump,timer=max_djump,60
end
end
end,
draw=function(_ENV)
if timer==0 then
spr(15,x,y+sin(offset)+0.5)
else
-- color"7"
-- line(x,y+4,x+3,y+7)
-- line(x+4,y+7,x+7,y+4)
-- line(x+7,y+3,x+4,y)
-- line(x+3,y,x,y+3)
foreach(split(
[[0,4,3,7
4,7,7,4
7,3,4,0
3,0,0,3]],"\n"),function(t)
local o1,o2,o3,o4=unpack(split(t))
line(x+o1,y+o2,x+o3,y+o4,7)
end
)
end
end
}
fall_floor={
init=function(_ENV)
solid_obj,state,unsafe_ground,delay=true,0,true,0
end,
update=function(_ENV)
--it looks like weird stuff goes on here with the decimal constants (mostly to ensure rounding correctly), but it should be equivalent to vanilla
--(and if i made an error, probably no one cares)
-- idling
if delay>0 then
delay-=0.2
elseif state==0 then
for i=-1,1 do
if check(player,i,abs(i)-1) then
psfx"13"
state,delay=1,2.79
init_smoke()
break
end
end
-- shaking
elseif state==1 then
state,delay,collideable=2,11.79--,false
-- invisible, waiting to reset
else
if not player_here() then
psfx"12"
state,collideable=0,true
init_smoke()
end
end
--if sprite 0 is not empty, need to fixup this
sprite=state==1 and 25.8-delay or state==0 and 23
end
}
smoke={
init=function(_ENV)
layer,spd,flip=3,vector(0.3+rnd"0.2",-0.1),vector(rnd()<0.5,rnd()<0.5)
x+=-1+rnd"2"
y+=-1+rnd"2"
end,
update=function(_ENV)
sprite+=0.2
if sprite>=29 then
destroy_object(_ENV)
end
end
}
--- <fruitrain> ---
fruitrain={}
fruit={
check_fruit=true,
init=function(_ENV)
y_,off,tx,ty,golden=y,0,x,y,sprite==11
if golden and deaths>0 then
destroy_object(_ENV)
end
end,
update=function(_ENV)
if target then
tx+=0.2*(target.x-tx)
ty+=0.2*(target.y-ty)
local dtx,dty=x-tx,y_-ty
local a,k=atan2(dtx,dty),dtx^2+dty^2 > r^2 and 0.2 or 0.1
x+=k*(r*cos(a)-dtx)
y_+=k*(r*sin(a)-dty)
else
local hit=player_here()
if hit then
hit.berry_timer,target,r=
0,fruitrain[#fruitrain] or hit,fruitrain[1] and 8 or 12
add(fruitrain,_ENV)
end
end
off+=0.025
y=y_+sin(off)*2.5
end
}
--- </fruitrain> ---
fly_fruit={
check_fruit=true,
init=function(_ENV)
start,step,sfx_delay=y,0.5,8
end,
update=function(_ENV)
--fly away
if has_dashed then
sfx_delay-=1
if sfx_delay==0 then
_g.sfx_timer=20
sfx"10"
end
spd.y=appr(spd.y,-3.5,0.25)
if y<-16 then
destroy_object(_ENV)
end
-- wait
else
step+=0.05
spd.y=sin(step)*0.5
end
-- collect
if player_here() then
--- <fruitrain> ---
init_smoke(-6)
init_smoke(6)
local f=init_object(fruit,x,y,10) --if this happens to be in the exact location of a different fruit that has already been collected, this'll cause a crash
--TODO: fix this if needed
f.fruit_id=fruit_id
fruit.update(f)
--- </fruitrain> ---
destroy_object(_ENV)
end
end,
draw=function(_ENV)
spr(10,x,y)
for ox=-6,6,12 do
spr((has_dashed or sin(step)>=0) and 12 or y>start and 14 or 13,x+ox,y-2,1,1,ox==-6)
end
end
}
lifeup={
init=function(_ENV)
spd.y,duration,flash,_g.sfx_timer,outline=-0.25,30,0,20--,false
sfx"9"
end,
update=function(_ENV)
duration-=1
if duration<=0 then
destroy_object(_ENV)
end
flash+=0.5
end,
draw=function(_ENV)
--<fruitrain>--
?split"1000,2000,3000,4000,5000,1up"[min(sprite,6)],x-4,y-4,7+flash%2
--<fruitrain>--
end
}
kevin={
init=function(_ENV)
while right()<lvl_pw-1 and tile_at(right()/8+1,y/8)==65 do
hitbox.w+=8
end
while bottom()<lvl_ph-1 and tile_at(x/8,bottom()/8+1)==80 do
hitbox.h+=8
end
solid_obj=true
collides=true
retrace_list={}
hit_timer=0
retrace_timer=0
shake=0
end,
update=function(_ENV)
if shake>0 then
shake-=1
end
for xdir=-1,1 do
for ydir=-1,1 do
if (xdir+ydir)%2==1 then
local hit=check(player,xdir,ydir)
if hit and hit.dash_effect_time>0 and
(xdir!=0 and sign(hit.dash_target_x)==-xdir or ydir!=0 and sign(hit.dash_target_y)==-ydir) and
(not active or xdir!=dirx and ydir!=diry) then
hit.spd=vector(xdir*1.5,ydir==1 and 0.5 or -1.5)
hit.dash_time=-1
--hit.dash_effect_time=0
add(retrace_list,vector(x,y))
dirx,diry=xdir,ydir
spd=vector(0,0)
hit_timer=10
active=true
shake=4
end
end
end
end
if hit_timer>0 then
hit_timer-=1
if hit_timer==0 then
spd=vector(0.2*dirx,0.2*diry)
end
elseif active then
if spd.x==0 and spd.y==0 then
retrace_timer=10
active=false
shake=5
if dirx!=0 then
for oy=0,hitbox.h-1,8 do
init_smoke(dirx==-1 and -8 or hitbox.w,oy)
end
else
for ox=0,hitbox.w-1,8 do
init_smoke(ox,diry==-1 and -8 or hitbox.h)
end
end
else
spd=vector(appr(spd.x,3*dirx,0.2),appr(spd.y,3*diry,0.2))
end
elseif retrace_timer>0 then
retrace_timer-=1
if retrace_timer==0 then
retrace=true
end
elseif retrace then
local last=retrace_list[#retrace_list]
if not last then
retrace=false
elseif last.x==x and last.y==y then
del(retrace_list,last)
retrace_timer=5
shake=4
spd=vector(0,0)
rem=vector(0,0)
else
spd=vector(appr(spd.x,sign(last.x-x),0.2),appr(spd.y,sign(last.y-y),0.2))
end
end
end,
draw=function(_ENV)
local x,y=x,y
if shake>0 then
x+=rnd"2"-1
y+=rnd"2"-1
end
local r,b=x+hitbox.w-8,y+hitbox.h-8
local up,down,left,right=active and diry==-1,active and diry==1,active and dirx==-1,active and dirx==1
for sx=x+8, r-8,8 do
pal(12, up and 7 or 12)
spr(65,sx,y)
pal(12, down and 7 or 12)
spr(65,sx,b,1,1,false,true)
end
for sy=y+8, b-8,8 do
pal(12, left and 7 or 12)
spr(80,x,sy)
pal(12, right and 7 or 12)
spr(80,r,sy,1,1,true)
end
rectfill(x+8,y+8,r,b,4)
-- spr(64,x,y)
-- spr(64,r-8,y,1,1,true)
-- spr(64,x,b-8,1,1,false,true)
-- spr(64,r-8,b-8,1,1,true,true)
local lookup={down,left,up,right,down}
for i=0,3 do
pal(12,(lookup[i+1] or lookup[i+2]) and 7 or 12)
spr(64,i<=1 and x or r, (i-1)\2==0 and y or b,1,1,i>=2,(i-1)\2!=0)
end
pal()
-- face
spr(active and 67 or 66,x+hitbox.w/2-4,y+hitbox.h/2-4)
end
}
bumper={
init=function(_ENV)
hitbox=rectangle(1,1,14,14)
hittimer=0
outline=false
end,
update=function(_ENV)
if hittimer>0 then
hittimer-=1
if hittimer==0 then
init_smoke(4,4)
end
else
local hit=player_here()
if hit then
hit.init_smoke()
local dx,dy=x+8-(hit.x+4),y+8-(hit.y+4)
local angle=atan2(dx,dy)
hit.spd = abs(dx) > abs(dy) and vector(sign(dx)*-2.8,-2) or -- -3.5*(cos(0.9),sin(0.9))
vector(-3*cos(angle),-3*sin(angle))
hit.dash_time,hit.djump=-1,max_djump
hittimer=20
end
end
end,
draw=function(_ENV)
local rx,ry=x+8,y+8
if hittimer>0 then
pal(12, 1)
pal(4, 2)
if hittimer > 17 then
circ(rx, ry, 26-hittimer, 7)
circfill(rx, ry, 25-hittimer, 1)
if hittimer > 19 then
rectfill(rx-4, ry-9, rx+4, ry+9, 7)
rectfill(rx-9, ry-4, rx+9, ry+4, 7)
end
end
end
spr(68, x, y, 2, 2)
pal()
if hittimer == 1 then
circfill(rx, ry, 4, 6)
end
end
}
--<feather> --
function appr_circ(value,target,amount)
return (value +sign(sin(value)*cos(target)-cos(value)*sin(target))*amount)%1
end
feather={
init=function(_ENV)
sprtimer=0
offset=0
starty=y
timer=0
end,
update=function(_ENV)
if timer>0 then
timer-=1
if timer==0 then
init_smoke()
end
else
sprtimer+=0.2
offset+=0.01
y=starty+0.5+2*sin(offset)
local hit=player_here()
if hit then
init_smoke()
timer=60
if hit.feather_state then
hit.lifetime=60
else
hit.spawn_timer,hit.feather_idle,hit.dash_time,hit.dash_effect_time=10,true,0,0
hit.spd=vector(mid(hit.spd.x,-1.5,1.5),mid(hit.spd.y,-1.5,1.5))
end
end
end
end,
draw=function(_ENV)
if timer==0 then
local d=flr(sprtimer%6)
spr(70+min(d,6-d),x,y, 1, 1,d>3)
end
end
}
-- </feather>
psfx=function(num)
if sfx_timer<=0 then
sfx(num)
end
end
-- [tile dict]
tiles={}
foreach(split([[
1,player_spawn
8,spring
9,spring
10,fruit
11,fruit
12,fly_fruit
15,refill
23,fall_floor
64,kevin
68,bumper
70,feather
]],"\n"),function(t)
local tile,obj=unpack(split(t))
tiles[tile]=_ENV[obj]
end)
-- [object functions]
function init_object(_type,sx,sy,tile)
--generate and check berry id
local id=sx..","..sy..","..lvl_id
if _type.check_fruit and got_fruit[id] then
return
end
--local _g=_g
local _ENV=setmetatable({},{__index=_g})
type, collideable, sprite, flip, x, y, hitbox, spd, rem, fruit_id, outline, draw_seed=
_type, true, tile, vector(), sx, sy, rectangle(0,0,8,8), vector(0,0), vector(0,0), id, true, rnd()
function left() return x+hitbox.x end
function right() return left()+hitbox.w-1 end
function top() return y+hitbox.y end
function bottom() return top()+hitbox.h-1 end
function is_solid(ox,oy,require_safe_ground)
for o in all(objects) do
if o!=_ENV and (o.solid_obj or o.semisolid_obj and not objcollide(o,ox,0) and oy>0) and objcollide(o,ox,oy) and not (require_safe_ground and o.unsafe_ground) then
return true
end
end
return oy>0 and not is_flag(ox,0,3) and is_flag(ox,oy,3) or -- one way platform or
is_flag(ox,oy,0) -- solid terrain
end
function oob(ox,oy)
return not exit_left and left()+ox<0 or not exit_right and right()+ox>=lvl_pw or top()+oy<=-8
end
function is_flag(ox,oy,flag)
for i=mid(0,lvl_w-1,(left()+ox)\8),mid(0,lvl_w-1,(right()+ox)/8) do
for j=mid(0,lvl_h-1,(top()+oy)\8),mid(0,lvl_h-1,(bottom()+oy)/8) do
local tile=tile_at(i,j)
if flag>=0 then
if fget(tile,flag) and (flag~=3 or j*8>bottom()) then
return true