-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathprecompile_catfishing.p8
1767 lines (1760 loc) · 89.9 KB
/
precompile_catfishing.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 39
__lua__
function get_active_menu()
for menu in all(menus) do
if (menu.enable) return menu
end
end
function get_menu(name)
for menu in all(menus) do
if (menu.name == name) return menu
end
end
function swap_menu_context(name)
get_active_menu().enable = false
if (name == nil) return
get_menu(name).enable = true
end
function longest_menu_str(data)
local len = 0
for str in all(data) do
len = max(len, #str.text)
end
return len
end
function load_area(area_id)
get_active_menu().enable = false
loaded_area = area_id
if area_id > 0 then
FishingArea.reset(global_data_table.areas[loaded_area])
if area_id == 1 then
reload(0x0,0x0,0x2000)
else
load_stored_gfx(map_table[loaded_area-1])
end
elseif area_id == 0 then
load_stored_gfx(shop_sprite_sheet)
else
reload(0x0,0x0,0x2000)
end
end
function load_area_state(name, id)
if (id < 1) reload(0x0,0x0,0x2000)
if id == -3 then
reset()
else
swap_menu_context(name)
if (loaded_area > 0) FishingArea.reset(global_data_table.areas[loaded_area])
loaded_area = id
end
end
function parse_menu_content(data)
if type(data) == "string" then
return _ENV[data]()
else
local content = {}
for dat in all(data) do
add(content, {
text = dat.text,
color = dat.color or {7, 0},
callback = _ENV[dat.callback],
args = dat.args
})
end
return content
end
end
function sell_all_fish()
if (#fish_inventory > 0) sfx(6)
for fish in all(fish_inventory) do
local weight, size, rarity = unpack(fish)
cash +=
flr((weight * global_data_table.sell_weights.per_weight_unit +
size * global_data_table.sell_weights.per_size_unit) * rarity)
del(fish_inventory, fish)
end
end
function switch_rods_menu()
local menu_list = {}
for index, rod in pairs(rod_inventory) do
add(menu_list, {
text=rod.name.." (p "..rod.power..")",
color={7,0},
callback=select_rod,
args={index}
})
end
return menu_list
end
function display_rod_selection_icon(pos)
local border_rect = BorderRect:new(
Vec:new(4, 44),
Vec:new(18,18),
7, (current_rod == rod_inventory[pos]) and 15 or 0, 2)
BorderRect.draw(border_rect)
spr(rod_inventory[pos].spriteID, 7, 46, 2, 2)
end
function select_rod(index)
current_rod = rod_inventory[index]
end
function enable_rod_shop()
show_rod_shop = true
end
function save_and_quit()
save()
load_area_state("title", -3)
end
function save()
local address = 0x5e00
address = save_byte2(address, cash)
address = save_byte(address, encode_rod_inventory())
for i, rod in pairs(rod_inventory) do
if rod.name == current_rod.name then
address = save_byte(address, i)
break
end
end
local fishes = Inventory.get_data(fishpedia)
address = save_byte(address, #fishes)
for fish_data in all(fishes) do
address = save_byte(address, fish_data.id)
address = save_byte2(address, round_to(fish_data.data.weight * 100))
address = save_byte2(address, round_to(fish_data.data.size * 100))
end
end
function load()
local address = 0x5e00
local cash, rods = 0, {}
cash = %address
address += 2
rods = decode_rod_inventory(@address)
address += 1
local selected_rod_id = @address
address += 1
local fish_count = @address
address += 1
for i=1, fish_count do
local id = @address
address += 1
local weight_ = %address
address += 2
local size_ = %address
address += 2
local entry = Inventory.get_entry(fishpedia, id)
entry.data = {
description=entry.data.description,
weight=weight_ / 100,
size=size_ / 100,
units=entry.data.units,
rarity = entry.data.rarity
}
entry.is_hidden = false
end
for rod in all(rods) do
add(rod_inventory, rod)
end
select_rod(selected_rod_id)
Menu.update_content(get_menu("switch_rods"), switch_rods_menu())
load_area_state("main", -1)
end
global_data_str="palettes={transparent_color_id=0,menu={4,7,7,3}},credit_offsets={30,45,70,95,120,145,170,195,220,250,270,295,315},menu_data={{name=title,position={34,70},content={{text=new game,callback=load_area_state,args={main,-1}},{text=load game,callback=load},{text=credits,callback=load_area,args={-4}}}},{name=main,position={5,70},content={{text=shop,callback=load_area,args={0}},{text=fishing,callback=swap_menu_context,args={location}},{text=fishapedia,callback=load_area,args={-2}},{text=save menu,callback=swap_menu_context,args={saving menu}}}},{name=location,prev=main,position={5,70},content={{text=beach,callback=load_area,args={1}},{text=river,callback=load_area,args={2}},{text=lake,callback=load_area,args={3}}}},{name=saving menu,prev=main,position={5,70},content={{text=save,callback=save},{text=save and quit,callback=save_and_quit},{text=quit without saving,callback=load_area_state,args={title,-3}}}},{name=switch_rods,prev=fishing,position={5,70},content=switch_rods_menu,hint=display_rod_selection_icon},{name=shop,position={5,70},content={{text=sell all fish,callback=sell_all_fish},{text=buy rods,callback=enable_rod_shop}}},{name=fishing,position={5,70},content={{text=return to map,callback=load_area_state,args={main,-1}},{text=switch rods,callback=swap_menu_context,args={switch_rods}}}}},text={60,5,7,1},gauge_data={position={10,10},size={102,5},settings={4,7,2,3},req_tension_ticks=20,tension_timer=30},power_gauge_colors={8,9,10,11,3},biases={weight=8,size=3},sell_weights={per_weight_unit=3,per_size_unit=2},shopkeeper={sprite=238},animation_data={cat={data={{sprite=232},{sprite=234}},size=16,ticks_per_frame=5},menu_selector={data={{sprite=32,offset={0,0}},{sprite=32,offset={-1,0}},{sprite=32,offset={-2,0}},{sprite=32,offset={-3,0}},{sprite=32,offset={-2,0}},{sprite=32,offset={-1,0}}},ticks_per_frame=3},up_arrow={data={{sprite=33,offset={0,0}},{sprite=33,offset={0,-1}},{sprite=33,offset={0,-2}},{sprite=33,offset={0,-1}}},ticks_per_frame=3},down_arrow={data={{sprite=49,offset={0,0}},{sprite=49,offset={0,1}},{sprite=49,offset={0,2}},{sprite=49,offset={0,1}}},ticks_per_frame=3}},rods={{name=sticky the rod,power=0,description=a stick with a string on it. the most basic of basic fishing rods.,cost=10,spriteID=200},{name=good rod,power=3,description=a pretty good rod per the name. you've seen some kids with pocket-sized monsters use this thing before.,cost=50,spriteID=202},{name=fisherman classic,power=7,description=a classic rod chosen by professionals of the industry and your uncle joey.,cost=100,spriteID=204},{name=peerless pole,power=10,description=a legendary rod passed down by the most skilled of fishing artisans and fearless warriors.,cost=500,spriteID=206}},areas={{name=beach,position={60,55},music={},fishes={{gradient={8,9,10,11,11,11,10,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=3,stats={goldfish,2,2.7,12.5,1},units={cm,g},description=made with real cheese. not actual cheese; it's a fake cheese brand that's called real cheese. the more you know!},{gradient={8,9,10,11,10,9,8},successIDs={11},min_gauge_requirement=6,max_gauge_requirement=inf,stats={yellowfin tuna,4,32,2.25,4},units={m,kg},description=named such because it's got yellow fins. people like to eat it but not as much as albacore for-tuna-tely.},{gradient={8,9,10,10,10,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=3,max_gauge_requirement=6,stats={pufferfish,6,0.08,60,3},units={cm,kg},description=in a pinch it'll inflate and get prickly; makes it great for particularly vindictive matches of any inflatable variety of sportsball.},{gradient={8,9,10,11,11,11,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={triggerfish,8,0.04,71,2},units={cm,kg},description=it's got a gun watch out! fortunately fish do not have thumbs and thus are forced to always practice trigger discipline. don't drop this guy though.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={ocean sunfish,66,2.2,1,2},units={m,kg},description=named after the sun which is a deadly laser. large and in charge just like the actual sun of our solar system.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=4,max_gauge_requirement=8,stats={clownfish,72,0.007,15,3},units={cm,kg},description=the practical aquatic jokester. two whole animated feature films got made about this guy! maybe not this guy in particular.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={bonefish,74,2.7,12.5,1},units={cm,g},description=it's got a bone to pick with you. you've also got a bone to pick with it for getting hooked on your line.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={angelfish,96,0.015,25,2},units={cm,kg},description=not biblically accurate because it's just a normal fish. makes a mean angel food cake though.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=3,max_gauge_requirement=6,stats={angle fish,98,0.015,25,3},units={cm,kg},description=a particularly obtuse-looking fish. ask them about trigonometry and the unit circle; they got pretty good grades in high school pre-calc.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=5,max_gauge_requirement=8,stats={archangelfish,100,0.015,25,4},units={cm,kg},description=pretty biblically accurate for a fish. be not afraid my child. will or will not pass judgment on how well you fish.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=5,stats={plastic fish,104,2.7,12.5,1},units={cm,g},description=an assembled pvc scale model of a fish. the dominant contributor of microplastics in this body of water. maybe don't eat any of your catches.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=13,max_gauge_requirement=15,stats={cat...fish,234,0.07,25,5},units={cm,g},disabled=true,description=not to be confused with an actual catfish; it's one of your own kind. what's this guy even doing? deep sea bare hands fishing? maybe that'll be you some other time.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=3,stats={anchovy,108,1.02,20,1},units={cm,g},description=usually comes in tins but this one's hot-n-ready. reeled in 30 minutes or less or else your catch is free.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=6,max_gauge_requirement=8,stats={squid,110,2.76,30,3},units={cm,g},description=can also turn into a kid in a not-so-distant future. either that or they become a very grumpy neighbor.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=inf,stats={trashcan,230,0.02,68,1},units={cm,g},disabled=true,description=i've heard one cat's trash is another cat's treasure but this is ridiculous. at least it's not in the water anymore! do your part for the environment kids.}}},{name=river,position={46,60},music={},fishes={{gradient={8,9,10,11,11,11,10,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=3,stats={carp,10,0.12,122,1},units={cm,kg},description=oh carp? one of the pillars of fishing. major contributor to cuisine and societies at large. that and it's skilled at carpentry.},{gradient={8,9,10,11,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={salmon,12,14.6,1.5,2},units={m,kg},description=not to be confused with salmonella; this guy won't kill you if you eat it cooked or raw! particularly violent around squids for some reason.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=11,max_gauge_requirement=13,stats={rainbow trout,38,0.013,110,5},units={cm,kg},description=typically bright and reflective colors like this are meant to ward off predators but since you're a cat the shiny lights are purr-dy.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={smallmouth bass,40,0.02,45,2},units={cm,kg},description=always left in the shadow of the superior largemouth bass. this one's part of a small rock outfit! they do not play the bass contrary to what you may think.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={bluegill,44,0.04,25,2},units={cm,kg},description=more green than anything else. its gills aren't even blue dude. that's kinda lame.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={yellow pike,46,0.046,80,2},units={cm,kg},description=ride this thing around your local college campus. also known as the walleye which has no relation to the movie you're thinking of.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={alligator gar,64,9.8,1.8,2},units={m,kg},description=won't ever need dentures because this guy's got some gnarly chompers. god forbid it bites you. don't let it bite you.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={bonefish,74,2.7,12.5,1},units={cm,g},description=it's got a bone to pick with you. you've also got a bone to pick with it for getting hooked on your line.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=5,max_gauge_requirement=8,stats={arowana,102,2.18,1.2,3},units={m,kg},description=valuable and highly coveted in some regions. its name only really makes it sound like a brand of bottled water or something.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=8,max_gauge_requirement=14,stats={catfish,106,0.03,72,4},units={cm,kg},description=the owner of a particularly intricate and very funny set of facial hair. not to be confused with a fish that is actually a cat or something.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=inf,stats={trashcan,230,0.02,68,1},units={cm,g},disabled=true,description=i've heard one cat's trash is another cat's treasure but this is ridiculous. at least it's not in the water anymore! do your part for the environment kids.}}},{name=lake,position={54,64},music={},fishes={{gradient={8,9,10,11,11,11,10,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=3,stats={carp,10,0.12,122,1},units={cm,kg},description=oh carp? one of the pillars of fishing. major contributor to cuisine and societies at large. that and it's skilled at carpentry.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={largemouth bass,14,0.01,45,2},units={cm,kg},description=talks a big game but is actually quite timid. it and most of its genetic relatives are hated by most anthropomorphic animal island dwellers.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=11,max_gauge_requirement=13,stats={rainbow trout,38,0.013,110,5},units={cm,kg},description=typically bright and reflective colors like this are meant to ward off predators but since you're a cat the shiny lights are purr-dy.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={crappie,42,0.02,38,2},units={cm,kg},description=also known as the calico bass so whoever gave it this particular name was probably having a really bad day.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={sturgeon,68,30.7,4.8,2},units={m,kg},description=went to medical school and was making six figures as part of an experienced surgical team. until you showed up that is.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=4,max_gauge_requirement=10,stats={koi,70,0.076,60,4},units={cm,kg},description=this guy'll apparently turn into a dragon if it does a sick enough jump up a river per japanese legend. unfortunately that won't happen now.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={bonefish,74,2.7,12.5,1},units={cm,g},description=it's got a bone to pick with you. you've also got a bone to pick with it for getting hooked on your line.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=2,max_gauge_requirement=4,stats={killifish,76,3,7.6,2},units={cm,g},description=killer fish. killer fish from san diego. doesn't know what they are but they taste really good.},{gradient={8,9,10,11,11,10,11,11,10,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=3,stats={pond smelt,78,1.9,11,2},units={cm,g},description=they who smelt it dealt it. or in this case caught it. because you caught it. pee-ew.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=8,max_gauge_requirement=14,stats={catfish,106,0.03,72,4},units={cm,kg},description=the owner of a particularly intricate and very funny set of facial hair. not to be confused with a fish that is actually a cat or something.},{gradient={8,9,11,11,11,11,11,11,11,9,8},successIDs={11},min_gauge_requirement=1,max_gauge_requirement=inf,stats={trashcan,230,0.02,68,1},units={cm,g},disabled=true,description=i've heard one cat's trash is another cat's treasure but this is ridiculous. at least it's not in the water anymore! do your part for the environment kids.}}}}"
function reset()
global_data_table = unpack_table(global_data_str)
shop_sprite_sheet = "641264126412641264126412641264126412644744126412641264123417241225441264126412147264826412641264122415341264126412541714122417341264121415441264123417241215174412641264127412341524126412641264126412641264126412441724123417241264126412641234172412151744126412641234153412641224153412641264126412641264126412341734124417141264826412341724121517441264126412748264126412641264826412641224c5126412641264124417141215174412641264127412641264126412641264126412641264122415a1151214154412441514126452172215174412641264127412441514126412641224153412641264126412141524151412241521191139311512441514126412641244171412151744123415241264127412641264126412641264123415241264126412241521692115126412641264121415241714121517441264126412741264126412648264126412648224152119113931158264126412441714121517448264127412641264126412641264126412641264122415a1151264126412641244161412151715341264126412741264126412641264126412641264123415241224c51234152412641264122416141614122544122415341264127412343f122f141f243f143f1264122415341264126412641274126412641264126412341624121517441264126412741224ff4f4415141264126412441514126412741264126412641224153412641215174412641264127412144f201f101f102f102f202f126482641264126412741264126412641264126412151744126412441514127412341f103f101f101f101f101f101f102f6412641264126412641234153412641264126482641215174412641264127412243f102f301f101f101f202f12641264126482641274126412641214164412641264121517441264827412142f203f101f102f102f104f6412441514126412641264121472641264123634124415141264121517441264126412741224ff3f126412641264121415241514126412741264126412141620241264126412151744126412241534122415441224ff1f141f1264126412641264126412741264126412342014181418441264121517153412641264127412341f24121f141f34122f141f241264126412641254206412541514126412641244201814184412641225441264126412147264126482641264176412143120122415341274124415141264124416201654126412151744126412641274126412641264126412541712173436312021141514152412741264126412341615161016154412641215174412641264127412641264124415141264125417122524466185648264123416554412641215175264126412741264126412641264124417141215174412dd127412641264124455441264121517441264126412541514126412341524126412641244171412151744126412641214fdad557d18cd509d641264121415441264126412441714121517441264126412149d57bd557d17bd704d183d64126412641264126412441714121517441264126412148d175d17ad55dd572d504d382d6412648264126412441714121517441264126412145d26177d173d186d35bd375d774d382d6412641264126412641234172412151724151412641214154412144d169d173d38dd164d179d1057103d372d6412141524151412641264126412341724121517441264126412145d164d18172d173d37cd163d27bd504d372d6412641264126412641234172412151752648214fd173d17ed2617fd8d173d648264126412641234172412151744126412641214fd1d17fdfdfd2df0f0f0f0f0f0f0f0"
map_table = {
"fcfcfcfcfc8c139c33ac33fc1c33fcfcfcfcfc7c337c538c536c137c43fcfc3c102c102c10fcfccc336c737c635c136c53fcfc4c201c20fcfccc534c935c635c335c538c6afcfc7c102c102c106cf121535f732f142f834f333f736caabc101c101c10fc5c201c207cf14f146f935f832f531f835ccabc101c10fcfc3ce12f148fb32fb31f533f634ceafc4c101c101c10fc7cd1ef736f834f144f733cfa1afc4c101c10fc8c4114817f234f932f141f938f833cfa1afcfcfc2124917f23192fb31fc35fa32cfa3afcfcec1124a11c3f26209f147fa32fe32cfa3afc7c102c102c10fce12c46105f143f146fc34fb32cfa3afc8c201c20fc1cf12c469f145fe37f732cfa3afcfcecf1112c191cff7f246f144f932cfa3afcfcecc11c512cff3f202f247fd32cfa3afcfcecd11c412c5f25af50245ff33cfa1adc101c101c10fcccd11c412cff142f50df833cfa1aec101c10fcdcc11c512caf148f50bf934ceafcfcfc1cb11c513c1f84af151015afc35ccafcfc5c101c101c107cf1113c2489247f553ff3336caafcfc7c101c108c611c714c14c9144f757fe38c6afcfcfc5c711c416c14c9142fa53f146fa3fcfcfcfc4c711c316c1f3489342fa58fc3fcfcfcfc4c611c414c3fe43f857fe3fcfcfcfc4c611c313c5fe4ff2ff38c102c102c10fcfcfc4c511c412c1f143ff414dff3339c201c20fcfcfc5c913c4ff4349ff363fcfcfcfc3c13813c3ff4745f14ff74fcfc1c13fcfc1c13812c2f641f541fc4ff5f74fcfc1c13bc13fc4c13713c445f345f445f24af148f74fcfc33ac13fc3c23712caf347f34ff7f142f74fcfc339c33fc1c33711caf343f145f342f14ff6f74f0f0f0f0f0f0f0f0",
"f18117f1d1178117f1f1f1f1b1179117f11117a117c11b611bf1f1e13c311cf1311b5117711b7117111b611bc11b611b11171113211bf1f1b13c313cf117213bc11b912b2113211b21171b6117111b2113213b2113112bf1313c313cf1f1a1133b611b2113113b13111b1113213b2113113b13111b3113312b2113114b11332bf1112c313c311cf1f191232b1123311b1123112b232b23114b11234b232b1123213b11334b333bf1f1f1f161333b23212b11233b232b23115b332b233b435b432b334bf1f1f1f141171b332b433b11233b134b234b432b234b334b532b235bf1f1f1f1511b431b131b233b332b234b234b736b332b936bf1f1f1f1412b632b231b735b332b738bf34bf1f1f1f1411b732b231b637b233b736be36bf1f1f1f141734b837b232b738bc37bf1f1f1f141635b838ba39ba38bf1f1f1f141536b63ab93bbb36bf1f1f1f141537b63ab63bbb38bf1f1f1f141637b638b93ab939bf1f1f1f14143ab33cb63cb73abf1f1f1f14123cb23eb33fb1b639b211c312c311cf1f1f171439b43fb142f243f244f83ab313c213cf1f1f18133bb13fb2b147f246f241f24bbf1f1f1f141fb8b246f244f14df248f34f1f1f1f1411ffb4f241f242f1bff1f1bbf1b4f34f1f1f1f1411f14ab2f242f1b4f241f1b4f142f1baf1b143f1b5f1b3f143ff131f292911c811c311f243f246f242f2b9f1b8f258f3b6f143f1b2ff131221410f45412912c412c111c216f243f141f1b1f1bbf1b1f241f143f1b4f147f1b2f149f1b1ff131121412f4641012a14c412c4f253f1b2f4b3f147f1b1f443f1b6f2b4f1b8f2b4ff1311214f2a2f1411f141f1b3f1b1f2b2f2b3f144f255f347f1b1f2b9f1b2f141f1b5ff13112141211121410f45412f1312f1b5f4b1f1b7f141f256f343f143f2b9f3b6f142ff1311214122112f454101412f1214f141baf142b8f5c349f147f2b3f156ff13112141221f2a2f111145f1b2f147f1b5f5c411c24df7c9ff1211c1214121c11121412f4641012f15fcc1f5ca1ac2f4c618c1ff1313c211214221410f45412e12f3cb13cf1813cf1311cf18112141211f292d1f0f0f0f0f0f0f0f0"
}
fish_inventory = {}
current_rod = global_data_table.rods[1]
rod_inventory = {current_rod}
compendium_rect = BorderRect:new(
Vec:new(8, 8), Vec:new(111, 111),
7, 5, 3
)
compendium_sprite_rect = BorderRect:new(
compendium_rect.position + Vec:new(5, 5),
Vec:new(24, 24),
7, 0, 2
)
opened_fish_page = nil
menus = {}
for data in all(global_data_table.menu_data) do
add(menus, Menu:new(
data.name,
data.prev,
Vec:new(data.position),
parse_menu_content(data.content),
_ENV[data.hint],
unpack(global_data_table.palettes.menu)
))
end
fishing_areas = {}
for area in all(global_data_table.areas) do
add(fishing_areas, FishingArea:new(area))
end
show_fish_details, fish_detail_flag = false
show_rod_shop, show_rod_details, rod_detail_flag = false
fishpedia = Inventory:new(34, 36,
Vec:new(5, 5), 30,
{ Vec:new(8, 8), Vec:new(111, 111), 7, 5, 3 }
)
local fish_names, count = {}, 0
for area in all(global_data_table.areas) do
for fish in all(area.fishes) do
if not table_contains(fish_names, fish.stats[1]) then
Inventory.add_entry(
fishpedia,
count,
fish.stats[2],
fish.stats[1],
{
description = fish.description,
units = fish.units,
rarity = fish.stats[5]
},
true,
fish.disabled and false or true
)
add(fish_names, fish.stats[1])
count += 1
end
end
end
cat = Animator:new(global_data_table.animation_data.cat, true)
shopkeeper = global_data_table.shopkeeper
rod_shop = Inventory:new(34, 36,
Vec:new(2, 2), 4,
{ Vec:new(75, 11), Vec:new(45, 45), 5, 4, 3}, Vec:new(60,-4)
)
for i, rod in pairs(global_data_table.rods) do
Inventory.add_entry(rod_shop, i-1, rod.spriteID, rod.cost, {}, false)
end
Inventory.get_entry(rod_shop, 0).is_disabled = true
credit_y_offsets = {}
for y in all(global_data_table.credit_offsets) do
add(credit_y_offsets, y)
end
boid_array = {}
for i=1, 15 do
add(boid_array, Boid:new(Inventory.get_random_sprite(fishpedia), rnd(127), rnd(127)))
end
cash = 100
loaded_area = -3
get_menu("title").enable = true
end
BorderRect = {}
function BorderRect:new(position_, size_, border_color, base_color, thickness_size)
obj = {
position = position_,
size = position_ + size_,
border = border_color,
base = base_color,
thickness = thickness_size
}
setmetatable(obj, self)
self.__index = self
return obj
end
function BorderRect:draw()
rectfill(
self.position.x-self.thickness, self.position.y-self.thickness,
self.size.x+self.thickness, self.size.y+self.thickness,
self.border
)
rectfill(self.position.x, self.position.y, self.size.x, self.size.y, self.base)
end
function BorderRect:resize(position_, size_)
if (self.position ~= position_) self.position = position_
if (self.size ~= size_ + position_) self.size = size_ + position_
end
function BorderRect:reposition(position_)
if (self.position == position_) return
local size = self.size - self.position
self.position = position_
self.size = self.position + size
end
GradientSlider = {}
function GradientSlider:new(
position_, size_, gradient_colors, handle_color, outline_color, thickness_, speed_)
obj = {
position=position_,
size=size_,
colors=gradient_colors,
handle=handle_color,
outline=outline_color,
thickness=thickness_,
speed=speed_,
handle_size=Vec:new(3, size_.y+4),
pos=0,
dir=1
}
setmetatable(obj, self)
self.__index = self
return obj
end
function GradientSlider:draw()
local rect_size = self.position + self.size
rectfill(
self.position.x-self.thickness, self.position.y-self.thickness,
rect_size.x+self.thickness, rect_size.y+self.thickness,
self.outline
)
for y=0, self.size.y do
for x=0, self.size.x do
local pixel_coord = Vec:new(x, y) + self.position
pset(pixel_coord.x, pixel_coord.y, self.colors[GradientSlider.get_stage(self, x)])
end
end
local handle_pos = self.position + Vec:new(self.pos, -2)
local handle_size = handle_pos + self.handle_size
rectfill(
handle_pos.x-self.thickness, handle_pos.y-self.thickness,
handle_size.x+self.thickness, handle_size.y+self.thickness,
self.outline
)
rectfill(
handle_pos.x, handle_pos.y,
handle_size.x, handle_size.y,
self.handle
)
end
function GradientSlider:update()
self.pos = mid(self.pos + self.speed, 0, self.size.x)
end
function GradientSlider:reduce()
self.pos = mid(self.pos - self.speed, 0, self.size.x)
end
function GradientSlider:get_stage(x)
local p = x or self.pos
local rate = flr((p / self.size.x) * 100)
local range = self.size.x \ #self.colors
return mid(rate \ range + 1, 1, #self.colors)
end
function GradientSlider:reset()
self.pos = 0
self.dir = 1
end
Fish = {}
function Fish:new(fish_name, description_, spriteID, weight, fish_size, fish_rarity, units_, gradient, successIDs)
local star_string = fish_rarity .. "★"
local string_len = longest_string({
"name: "..fish_name.." "..star_string,
"weight: "..weight..units_[2],
"size: "..fish_size..units_[1],
"press ❎ to close"
})*5-5
local box_size = Vec:new(string_len, 40)
local gauge_data = global_data_table.gauge_data
obj = {
name=fish_name,
sprite = spriteID,
lb = weight,
size = fish_size,
rarity = fish_rarity,
units = units_,
description=description_,
success_stage_ids = successIDs,
tension_slider = GradientSlider:new(
Vec:new(gauge_data.position), Vec:new(gauge_data.size),
gradient, unpack(gauge_data.settings)
),
description_box = BorderRect:new(
Vec:new((128-box_size.x-6) \ 2, 80), box_size,
7, 1, 3
),
ticks = 0,
timer = global_data_table.gauge_data.tension_timer
}
setmetatable(obj, self)
self.__index = self
return obj
end
function Fish:update()
if (self.ticks >= global_data_table.gauge_data.req_tension_ticks) return
if Fish.catch(self) then
self.ticks += 1
self.timer = min(self.timer+1, global_data_table.gauge_data.tension_timer)
else
self.timer = max(self.timer-1, 0)
end
GradientSlider.update(self.tension_slider)
end
function Fish:draw_tension()
local thickness = self.tension_slider.thickness
local pos = self.tension_slider.position-Vec:new(thickness, 0)
local size = self.tension_slider.size
local y = pos.y+size.y+thickness+1
line(pos.x, y, pos.x + (self.ticks/global_data_table.gauge_data.req_tension_ticks)*size.x+thickness, y, 11)
line(pos.x, y+1, pos.x + (self.timer/global_data_table.gauge_data.tension_timer)*size.x+thickness, y+1, 8)
GradientSlider.draw(self.tension_slider)
end
function Fish:draw_details()
line(62, 0, 62, 48, 7)
draw_sprite_rotated(self.sprite, Vec:new(55, 48), 16, 90)
BorderRect.draw(self.description_box)
local star_string = self.rarity .. "★"
print_with_outline(
"name: "..self.name.." "..star_string.."\n\nrweight: "..self.lb..self.units[2].."\nsize: "..self.size..self.units[1].."\n\npress ❎ to close",
self.description_box.position.x + 5, self.description_box.position.y + 4, 7, 0
)
end
function Fish:catch()
return table_contains(
self.success_stage_ids,
self.tension_slider.colors[GradientSlider.get_stage(self.tension_slider)]
)
end
FishingArea = {}
function FishingArea:new(area_data_)
local lost_text_len = #"the fish got away"*5-5
obj = {
area_data = area_data_,
power_gauge = GradientSlider:new(
Vec:new(global_data_table.gauge_data.position),
Vec:new(global_data_table.gauge_data.size),
global_data_table.power_gauge_colors,
unpack(global_data_table.gauge_data.settings)
),
lost_box = BorderRect:new(
Vec:new((128-lost_text_len-6)\2, 48),
Vec:new(lost_text_len, 24),
7, 1, 3
),
state = "none",
fish = nil
}
setmetatable(obj, self)
self.__index = self
return obj
end
function FishingArea:draw()
if self.state == "casting" then
GradientSlider.draw(self.power_gauge)
elseif self.state == "fishing" then
Fish.draw_tension(self.fish)
elseif self.state == "detail" then
Fish.draw_details(self.fish)
elseif self.state == "lost" then
FishingArea.draw_lost(self)
end
end
function FishingArea:draw_lost()
BorderRect.draw(self.lost_box)
print_with_outline(
"the fish got away\n\npress ❎ to close",
self.lost_box.position.x + 5, self.lost_box.position.y+6, 7, 0
)
end
function FishingArea:update()
if not self.flag then
self.flag = true
self.started = false
return
end
if btnp(❎) and self.state ~= "casting" then
if self.state == "none" then
self.started = true
self.state = "casting"
sfx(49)
elseif self.state == "lost" then
FishingArea.reset(self)
elseif self.state == "detail" then
add(fish_inventory, {self.fish.lb, self.fish.size, self.fish.rarity})
local entry = Inventory.get_entry(fishpedia, self.fish.name)
entry.data = {
description=self.fish.description,
weight=max(entry.data.weight, self.fish.lb),
size=max(entry.data.size, self.fish.size),
units=self.fish.units,
rarity = max(entry.data.rarity, self.fish.rarity)
}
entry.is_hidden = false
FishingArea.reset(self)
end
end
if btn(❎) then
if self.state == "casting" and self.started then
GradientSlider.update(self.power_gauge)
elseif self.state == "fishing" then
sfx(62)
self.started = true
Fish.update(self.fish)
if self.fish.timer <= 0 then
self.state = "lost"
end
end
else
if self.state == "fishing" and self.started then
GradientSlider.reduce(self.fish.tension_slider)
elseif self.state == "casting" then
sfx(61)
self.state = "fishing"
self.started = false
self.fish = generate_fish(
self.area_data,
GradientSlider.get_stage(self.power_gauge)
)
if (self.fish == nil) self.state = "lost"
if self.fish then
if self.fish.rarity <= 2 then
music(0)
elseif self.fish.rarity == 3 then
music(8)
elseif self.fish.rarity > 3 then
music(19)
end
end
GradientSlider.reset(self.power_gauge)
end
end
if self.state == "fishing" and self.fish.ticks >= global_data_table.gauge_data.req_tension_ticks then
if self.fish then
if self.fish.rarity <= 2 then
sfx(33)
elseif self.fish.rarity == 3 then
sfx(29)
elseif self.fish.rarity > 3 then
sfx(27)
end
end
self.state = "detail"
GradientSlider.reset(self.fish.tension_slider)
end
end
function FishingArea:reset()
self.started = false
self.fish = nil
self.state = "none"
self.flag = false
music(-1)
sfx(-1)
end
function generate_fish(area, stage)
local possible_fishes = {}
local stage_gauge = stage + current_rod.power
for fish in all(area.fishes) do
if stage_gauge >= fish.min_gauge_requirement and stage_gauge < fish.max_gauge_requirement then
add(possible_fishes, fish)
end
end
if (#possible_fishes == 0) return nil
local fish = possible_fishes[flr(rnd(#possible_fishes))+1]
local name, spriteID, weight, size, rarity = unpack(fish.stats)
size, weight = generate_weight_size_with_bias(weight, size)
return Fish:new(
name, fish.description, spriteID, weight, size, rarity, fish.units, fish.gradient, fish.successIDs
)
end
function generate_weight_size_with_bias(weight, size)
local bias = global_data_table.biases.size
local new_size = round_to(mid(size + rnd(bias) - bias/2, 0.1, size + bias), 2)
local new_weight = round_to(weight * new_size * 0.3 * global_data_table.biases.weight, 2)
return new_size, new_weight
end
Vec = {}
function Vec:new(dx, dy)
local obj = nil
if type(dx) == "table" then
obj = {x=dx[1],y=dx[2]}
else
obj={x=dx,y=dy}
end
setmetatable(obj, self)
self.__index = self
self.__add = function(a, b)
return Vec:new(a.x+b.x,a.y+b.y)
end
self.__sub = function(a, b)
return Vec:new(a.x-b.x,a.y-b.y)
end
self.__mul = function(a, scalar)
return Vec:new(a.x*scalar,a.y*scalar)
end
self.__div = function(a, scalar)
return Vec:new(a.x/scalar,a.y/scalar)
end
self.__eq = function(a, b)
return (a.x==b.x and a.y==b.y)
end
self.__tostring = function(vec)
return "("..vec.x..", "..vec.y..")"
end
self.__concat = function(vec, other)
return (type(vec) == "table") and Vec.__tostring(vec)..other or vec..Vec.__tostring(other)
end
return obj
end
function Vec:unpack()
return self.x, self.y
end
function Vec:clamp(min, max)
self.x, self.y = mid(self.x, min, max), mid(self.y, min, max)
end
function Vec:magnitude()
return sqrt(self.x^2 + self.y^2)
end
function Vec:normalize()
local length = Vec.magnitude(self)
return Vec:new(self.x / length, self.y / length)
end
function Vec:heading()
local theta = self.y/self.x
return sin(theta)/cos(theta)
end
function Vec:limit(value)
return Vec:new(min(self.x, value), min(self.y, value))
end
function distance(a, b)
return sqrt((a.x-b.x)^2 + (a.y-b.y)^2)
end
function normalize(val)
return (type(val) == "table") and Vec:new(normalize(val.x), normalize(val.y)) or flr(mid(val, -1, 1))
end
function lerp(start, last, rate)
return start + (last - start) * rate
end
Menu = {}
function Menu:new(
menu_name, previous_menu, position_,
menu_content, menu_info_draw_call,
base_color, border_color, text_color, menu_thickness)
obj = {
name = menu_name,
prev = previous_menu,
position = position_,
selector = Animator:new(global_data_table.animation_data.menu_selector, true),
up_arrow = Animator:new(global_data_table.animation_data.up_arrow, true),
down_arrow = Animator:new(global_data_table.animation_data.down_arrow, true),
content = menu_content,
content_draw = menu_info_draw_call,
rect = BorderRect:new(
position_,
Vec:new(min(10 + 5*longest_menu_str(menu_content), 128-position_.x-menu_thickness*2), 38),
border_color,
base_color,
menu_thickness
),
text = text_color,
pos = 1,
enable = false,
ticks = 5,
max_ticks = 5,
dir = 0
}
setmetatable(obj, self)
self.__index = self
return obj
end
function Menu:draw()
if (not self.enable) return
local top, bottom = self.pos-1, self.pos+1
if (top < 1) top = #self.content
if (bottom > #self.content) bottom = 1
if (self.content_draw) self.content_draw(self.pos, self.position, self.content[self.pos].color)
BorderRect.draw(self.rect)
Animator.draw(self.selector, Vec.unpack(self.position + Vec:new(2, 15)))
local arrow_offset = (self.rect.size.x + self.rect.position.x)\2-self.up_arrow.sprite_size\2
Animator.draw(self.up_arrow, arrow_offset, self.position.y-self.rect.thickness)
Animator.draw(self.down_arrow, arrow_offset, self.rect.size.y-self.rect.thickness)
local base_pos_x = self.position.x+10
local menu_scroll_data = {self.dir, self.ticks / self.max_ticks, self.position}
if self.ticks < self.max_ticks then
if self.dir > 0 then
print_with_outline(
self.content[top].text,
combine_and_unpack(menu_scroll(12, 10, 7, unpack(menu_scroll_data)),
self.content[top].color)
)
elseif self.dir < 0 then
print_with_outline(
self.content[bottom].text,
combine_and_unpack(menu_scroll(12, 10, 27, unpack(menu_scroll_data)),
self.content[bottom].color)
)
end
else
print_with_outline(self.content[top].text, base_pos_x, self.position.y+7, unpack(self.content[top].color))
print_with_outline(self.content[bottom].text, base_pos_x, self.position.y+27, unpack(self.content[bottom].color))
end
print_with_outline(
self.content[self.pos].text,
combine_and_unpack(menu_scroll(10, 12, 17, unpack(menu_scroll_data)),
self.content[self.pos].color)
)
end
function Menu:update()
if (not self.enable) return
Animator.update(self.selector)
Animator.update(self.up_arrow)
Animator.update(self.down_arrow)
if (self.ticks >= self.max_ticks) return
self.ticks += 1
end
function Menu:move()
if (not self.enable) return
if (self.ticks < self.max_ticks) return
local _, dy = controls()
if (dy == 0) return
sfx(58)
self.pos += dy
self.dir = dy
if (self.pos < 1) self.pos = #self.content
if (self.pos > #self.content) self.pos = 1
self.ticks = 0
end
function Menu:invoke()
if (self == nil) return
local cont = self.content[self.pos]
if (cont.callback == nil) return
if cont.args then
cont.callback(unpack(cont.args))
else
cont.callback()
end
sfx(59)
end
function Menu:update_content(content)
self.content = content
BorderRect.resize(
self.rect,
self.rect.position,
Vec:new(5*longest_menu_str(content), 38)
)
end
function menu_scroll(dx1, dx2, dy, dir, rate, position)
local dy1, dy3 = dy-10, dy+10
local lx = lerp(position.x+dx1, position.x+dx2, rate)
local ly = position.y + dy
if dir < 0 then
ly = lerp(position.y + dy1, ly, rate)
elseif dir > 0 then
ly = lerp(position.y + dy3, ly, rate)
end
return {lx, ly}
end
Animator = {} -- updated from tower_defence
function Animator:new(animation_data, continuous_)
obj = {
data = animation_data.data,
sprite_size = animation_data.size or 8,
spin_enable = animation_data.rotation,
theta = 0,
animation_frame = 1,
frame_duration = animation_data.ticks_per_frame,
tick = 0,
continuous = continuous_
}
setmetatable(obj, self)
self.__index = self
return obj
end
function Animator:update()
self.tick = (self.tick + 1) % self.frame_duration
self.theta = (self.theta + 5) % 360
if (self.tick ~= 0) return false
if Animator.finished(self) then
if (self.continuous) Animator.reset(self)
return true
end
self.animation_frame += 1
return false
end
function Animator:finished()
return self.animation_frame >= #self.data
end
function Animator:draw(dx, dy)
local position,frame = Vec:new(dx, dy),self.data[self.animation_frame]
if (frame.offset) position += Vec:new(frame.offset)
if self.spin_enable then
draw_sprite_rotated(frame.sprite, position, self.sprite_size, self.theta)
else
spr(Animator.get_sprite(self),combine_and_unpack({Vec.unpack(position)}, {self.sprite_size\8, self.sprite_size\8}))
end
end
function Animator:get_sprite()
return self.data[self.animation_frame].sprite
end
function Animator:reset()
self.animation_frame = 1
end
Inventory = {}
function Inventory:new(selector_spr_id, unknown_spr_id, size_, max_entries, border_rect_data, offset_)
obj = {
selector_id = selector_spr_id,
unknown_id = unknown_spr_id,
size = size_,
entry_amount = max_entries,
rect = BorderRect:new(unpack(border_rect_data)),
data = {},
spacing = 4,
pos = 0,
min_pos = 0,
max_pos = size_.x*size_.y,
grid_size = size_.x*size_.y,
offset = offset_ or Vec:new(-4,-4),
disabled_icon = 198
}
setmetatable(obj, self)
self.__index = self
return obj
end
function Inventory:draw(asdf)
BorderRect.draw(self.rect)
for y=1, self.size.y do
for x=1, self.size.x do
local position = Vec:new(x*16+self.spacing*x, y*16+self.spacing*y) + self.offset
local index = self.min_pos + (x-1) + (y-1)*self.size.x
local entry = self.data[index]
if entry == nil or entry.is_hidden then
entry = self.unknown_id
else
entry = entry.sprite_id
end
rectfill(position.x-1, position.y-1, position.x + 16, position.y + 16, 0)
spr(entry, position.x, position.y, 2, 2)
if self.data[index] and self.data[index].is_disabled then
spr(self.disabled_icon, position.x, position.y, 2, 2)
end
end
end
local pos_offset = self.pos - self.min_pos
local x = pos_offset%self.size.x
local y = pos_offset\self.size.x
local pos = Vec:new(x*16+self.spacing*x, y*16+self.spacing*y)+Vec:new(20, 20)+self.offset
spr(self.selector_id, pos.x, pos.y, 2, 2)
end
function Inventory:update()
local dx, dy = controls()
self.pos += dx
self.pos += dy*self.size.x
if self.pos >= self.entry_amount then
self.pos -= self.entry_amount
self.min_pos = 0
self.max_pos = self.grid_size
elseif self.pos < 0 then
self.pos += self.entry_amount
self.min_pos = self.entry_amount-self.grid_size
self.max_pos = self.entry_amount
else
if self.pos >= self.max_pos then
self.min_pos += self.size.x
self.max_pos += self.size.x
elseif self.pos <= self.min_pos then
self.min_pos -= self.size.x
self.max_pos -= self.size.x
end
self.max_pos = mid(self.max_pos, self.grid_size, self.entry_amount)
self.min_pos = mid(self.min_pos, 0, self.entry_amount-self.grid_size)
end
end
function Inventory:add_entry(index, sprite, name_, extra_data, hidden, pickable)
self.data[index] = {
is_hidden=hidden,
is_disabled=false,
is_pickable=pickable or false,
sprite_id = sprite,
name = name_,
data = extra_data
}
end
function Inventory:get_entry(name)
if type(name) == "string" then
for i=0, #self.data do
if (self.data[i].name == name) return self.data[i]
end
else
return self.data[name]
end
end
function Inventory:get_data()
local data = {}
for i=0, #self.data do
local entry = self.data[i]
if entry and not entry.is_hidden then
add(data, {
id = i,
data = entry.data
})
end
end
return data
end
function Inventory:get_random_sprite()
local entry = self.data[flr(rnd(#self.data))]
while not entry.is_pickable do
entry = self.data[flr(rnd(#self.data))]
end
return entry.sprite_id
end
function Inventory:check_if_disabled()
return self.data[self.pos].is_disabled
end
function Inventory:check_if_hidden()
local entry = self.data[self.pos]
return entry == nil or entry.is_hidden
end
Boid = {}
function Boid:new(sprite, x, y)
local angle = flr(rnd()*360)
obj = {
sprite_id = sprite,
position = Vec:new(x, y),
velocity = Vec:new(cos(angle), sin(angle)),
acceleration = Vec:new(0, 0),
r = 2,
max_speed = 1,
max_force = 0.03,
desired_sep = 15,
neighbor_dist = 30,
tick = 0,
max_ticks = 10
}
setmetatable(obj, self)
self.__index = self
return obj
end
function Boid:update()
self.velocity = Vec.limit(self.velocity + self.acceleration, self.max_speed)
self.position += self.velocity
self.acceleration *= 0
end
function Boid:seek(target)
local desired = target - self.position
local desired_norm = Vec.normalize(desired)
desired *= self.max_speed
return Vec.limit(desired - self.velocity, self.max_force)
end
function Boid:draw()
local pos = lerp(self.position, self.position + Vec.limit(self.velocity + self.acceleration, self.max_speed), self.tick/self.max_ticks)
spr(self.sprite_id, pos.x, pos.y, 2, 2)
end
function Boid:border()
if (self.position.x < 0) self.position.x = 127
if (self.position.y < 0) self.position.y = 127
if (self.position.x > 127) self.position.x = 0
if (self.position.y > 127) self.position.y = 0
end
function Boid:flock(boids)
local sep = Boid.separate(self, boids)
local ali = Boid.align(self, boids)
local coh = Boid.cohesion(self, boids)
sep *= 1.5
self.acceleration += sep
self.acceleration += ali
self.acceleration += coh
end
function Boid:separate(boids)
local steer = Vec:new(0, 0)
local count = 0
for other in all(boids) do
local dist = distance(self.position, other.position)
if dist > 0 and dist < self.desired_sep then
local diff = self.position - other.position
diff = Vec.normalize(diff)
diff /= dist
steer += diff
count += 1
end
end
if count > 0 then
steer /= count
end
if Vec.magnitude(steer) > 0 then
steer = Vec.normalize(steer)
steer *= self.max_speed
steer -= self.velocity
steer = Vec.limit(steer, self.max_force)
end
return steer
end
function Boid:align(boids)
local sum = Vec:new(0, 0)
local count = 0
for boid in all(boids) do
local dist = distance(self.position, boid.position)
if dist > 0 and dist < self.neighbor_dist then
sum += boid.velocity
count += 1
end
end
if count > 0 then
sum /= count
sum = Vec.normalize(sum)
sum *= self.max_speed
return Vec.limit(sum - self.velocity, self.max_force)
else
return Vec:new(0, 0)
end
end
function Boid:cohesion(boids)
local sum = Vec:new(0, 0)
local count = 0
for boid in all(boids) do
local dist = distance(self.position, boid.position)
if dist > 0 and dist < self.neighbor_dist then
sum += boid.position
count += 1