-
Notifications
You must be signed in to change notification settings - Fork 1
/
ggj2019_leaderboard.p8
1213 lines (1114 loc) · 48.1 KB
/
ggj2019_leaderboard.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 16
__lua__
-- debug
debug_stop_tick = false
enable_music = true
-- states
menu = 0
tutorial = 1
game = 2
gameover = 3
credits = 4
leaderboard = 5
add_score = 6
-- gamestate = menu
gamestate = menu
-- gameplay globals
posts = {}
tutorial_posts = {}
safe_stickers = {}
dirty_stickers = {}
score = 0
countdown = 1
high_scores = {}
-- add score globals
as_index = 1
as_name = {}
as_name[1] = 1
as_name[2] = 1
as_name[3] = 1
-- animation globals
falling_hearts = {}
menu_lock = false
-- game animation globals
swipe_direction = 0
is_animating_feed = false
is_animating_swipe = false
posts_y_offset = 0
posts_x_offset = 0
is_camera_shaking = false
camera_shake_cooldown = 0
music_is_playing = false
music_speed = 1
-- const globals
database = {}
text_y_offset = -2
camera_shake_intensity = 5
camera_shake_duration = 0.5
countdown_speed = 0.0015
profile_pics = 8
post_pics = 4
blinking_speed = 2
high_scores_count = 5
-- text stuff
uint_to_char = {
a = 1,
b = 2,
c = 3,
d = 4,
e = 5,
f = 6,
g = 7,
h = 8,
i = 9,
j = 10,
k = 11,
l = 12,
m = 13,
n = 14,
o = 15,
p = 16,
q = 17,
r = 18,
s = 19,
t = 20,
u = 21,
v = 22,
w = 23,
x = 24,
y = 25,
z = 26
}
char_to_uint = {
"a", "b", "c", "d", "e", "f",
"g", "h", "i", "j", "k", "l",
"m", "n", "o", "p", "q", "r",
"s", "t", "u", "v", "w", "x",
"y", "z"
}
-- when the index is zero it doesn't give error
char_to_uint[0] = "!"
function load_database()
database = {}
-- first row, second row, third row, is not porn
insert_post("donna calda", "a 2 km", "da te", false) -- no
insert_post("vendesi", "soprammobili", "usati", true) -- si
insert_post("clicca qui", "per il", "ca**o", false) -- no
insert_post("passata di", "pomodoro", "tre per due", true)
insert_post("vendo", "la droga", "", false) -- no
insert_post("qui foto", "di gattini", "", true) -- si
insert_post("qui foto", "di", "cagnolini", true) -- si
insert_post("biscotti", "in offerta", "", true) -- si
insert_post("sito", "bellissimo", "sui memini", true) -- si
insert_post("guardate che", "belle le", "mie tette", false) -- no
insert_post("nuovissimi", "giochi per", "playstation", true)
insert_post("altri", "memini", "divertenti", true) -- si
insert_post("qui battute", "sui coder", "", true) -- si
-- insert_post("game of", "thrones", "streaming", true)
insert_post("leggi", "hentai", "online", false) -- no
insert_post("nuovo modo", "allungamento", "del pene", false) -- no
insert_post("visite", "gratuite", "urologo", true) -- si
insert_post("nuova dieta", "di kylie", "jenner", true) -- si
insert_post("qui kim", "kardashian", "nuda", false) -- no
insert_post("jason momoa", "leaked", "photo", false) -- no
insert_post("10 motivi", "per smettere", "di fumare", true)
insert_post("le migliori", "10 mete", "europee", true) -- si
insert_post("mobili", "ikea in", "iper offerta", true) -- si <--- "super offerta" sforava :(
insert_post("uomo caldo", "a 3 km", "da te", false) -- no
insert_post("coppia di", "scambisti", "cerca donna", false) -- no
insert_post("vibratori", "rosa", "in sconto", false) -- no
insert_post("sito con", "video", "molto fetish", false) -- no
insert_post("coppia di", "scambisti", "cerca uomo", false)
insert_post("sito per", "articoli", "da pesca", true) -- si
insert_post("sito per", "oggetti", "cinesissimi", true) -- si
insert_post("fammi vedere", "i tuoi", "piedini", false) -- no 13
insert_post("nuove", "ricettine su", "vrdbasilico", true) -- si <--- "verdebasilico" non entrava sorry :(
insert_post("prevendita", "concerto di", "gg d'alessio", true) -- si <--- ho dovuto tagliarla :(
insert_post("vendita", "accessori di", "hello kitty", true) -- si 16
insert_post("video ose'", "per", "omosessuali", false)
insert_post("foto di", "peni", "extra-large", false)
insert_post("rihanna", "leaked", "photo", false)
insert_post("sito di", "barzellette", "divertenti", true)
end
function load_tutorial_posts()
insert_tutorial_post("sei rob, il", "nuovo moderatore", "di tambler")
insert_tutorial_post("il tuo lavoro e'", "eliminiare i", "contenuti espliciti")
insert_tutorial_post("fai swipe", "a destra per", "approvare il post")
insert_tutorial_post("fai swipe", "a sinistra per", "eliminare il post")
insert_tutorial_post("se sbagli sarai", "licenziato!!!", "")
end
function load_stickers()
safe_stickers = {}
add(safe_stickers, 2)
add(safe_stickers, 3)
add(safe_stickers, 6)
add(safe_stickers, 10)
add(safe_stickers, 11)
add(safe_stickers, 13)
add(safe_stickers, 14)
add(safe_stickers, 15)
dirty_stickers = {}
add(dirty_stickers, 1)
-- add(dirty_stickers, 4) <- shit, ambibuos
add(dirty_stickers, 5)
add(dirty_stickers, 7)
add(dirty_stickers, 8)
add(dirty_stickers, 9)
add(dirty_stickers, 12)
end
-- start init stuff
function insert_post(first, second, third, valid)
local post = {}
post.first_row = first
post.second_row = second
post.third_row = third
post.is_valid = valid
post.profile_id = get_random_profile_pic()
post.pic_id = get_random_post_pic()
add_sticker(post)
add_sprite_variations(post)
-- the big tit is very rare
if not post.is_valid then
post.show_big_tit = flr(rnd(50)) == 1
end
add(database, post)
end
function insert_tutorial_post(first, second, third)
local post = {}
post.first_row = first
post.second_row = second
post.third_row = third
post.is_valid = valid
add(tutorial_posts, post)
end
function generate_posts()
for x = 1, 4 do
add(posts, database[get_random_post_id()])
end
end
-- end init stuff
function pop_and_push_post()
-- i need to pop post after the animation finishes
posts[1] = posts[2]
posts[2] = posts[3]
posts[3] = posts[4]
posts[4] = database[get_random_post_id()]
end
function pop_and_push_tutorial()
-- i need to pop post after the animation finishes
tutorial_posts[1] = tutorial_posts[2]
tutorial_posts[2] = tutorial_posts[3]
tutorial_posts[3] = tutorial_posts[4]
tutorial_posts[4] = tutorial_posts[5]
tutorial_posts[5] = nil
end
function get_random_post_id()
return flr(rnd(#database)) + 1
end
function get_random_profile_pic()
return flr(rnd(profile_pics)) + 1
end
function get_random_post_pic()
return flr(rnd(post_pics)) + 1
end
function process_buttons()
if not is_animating_swipe and not menu_lock then
-- left arrow key
if btnp(0) then
swipe_direction = -1
is_animating_swipe = true
sfx_correct()
menu_lock = true
end
-- right arrow key
if btnp(1) then
swipe_direction = 1
is_animating_swipe = true
sfx_correct()
menu_lock = true
end
else
menu_lock = false
end
end
function process_feed_animation()
if is_animating_feed then
posts_y_offset -= 10
end
if posts_y_offset <= -40 then
-- here is where the animation ends
is_animating_feed = false
post_animation_ended()
posts_x_offset = 0
posts_y_offset = 0
end
end
function process_swipe_animation(direction)
if is_animating_swipe then
posts_x_offset += 16 * swipe_direction
end
if posts_x_offset <= -160 or posts_x_offset >= 160 then
is_animating_feed = true
is_animating_swipe = false
end
end
function do_camera_shake()
camera_shake_cooldown = camera_shake_duration
end
function decrease_countdown()
if not is_animating_swipe then
countdown -= countdown_speed * (score + 1)
end
end
function post_animation_ended()
if gamestate == tutorial then
pop_and_push_tutorial()
end
if gamestate == game then
evaluate_content(posts[1])
pop_and_push_post()
end
end
function evaluate_content(post)
if post.is_valid and swipe_direction == 1
or not post.is_valid and swipe_direction == -1 then
score += 1
countdown = 1
else
-- do_camera_shake()
countdown = 0
sfx_wrong()
end
end
function evaluate_gameover()
if countdown <= 0 then
change_state(gameover)
sfx_wrong()
end
end
function change_state(new_state)
menu_lock = true
gamestate = new_state
if new_state == game then
reset_game_state()
start_game_music()
end
end
function reset_game_state()
load_database()
generate_posts()
score = 0
countdown = 1
swipe_direction = 0
is_animating_feed = false
is_animating_swipe = false
posts_y_offset = 0
posts_x_offset = 0
as_index = 1
as_name[1] = 1
as_name[2] = 1
as_name[3] = 1
end
function reset_game_state_and_tutorial()
reset_game_state()
load_tutorial_posts()
end
function add_sticker(post)
post.sticker_x = rnd(24)
post.sticker_y = rnd(24)
if post.is_valid then
post.sticker_id = get_safe_sticker()
else
post.sticker_id = get_dirty_sticker()
end
end
function add_sprite_variations(post)
post.flip_x = rnd(2) > 1
end
function get_safe_sticker()
return safe_stickers[flr(rnd(#safe_stickers)) + 1]
end
function get_dirty_sticker()
return dirty_stickers[flr(rnd(#dirty_stickers)) + 1]
end
-- start game draw stuff
function draw_background()
rectfill(0, 0, 128, 128, 1)
end
function draw_bar()
rectfill(0, 0, 128, 16, 1)
line(0, 16, 128, 16, 12)
-- search bar
rectfill(12, 4, 116, 12, 0)
print("cerca su tambler", 14, 6, 7)
end
function draw_post(x_offset, y_offset, post)
-- post bg
rectfill(
32 + x_offset,
8 + y_offset,
120 + x_offset,
40 + y_offset,
7)
-- profile pic
-- rectfill(
-- 8 + x_offset,
-- 8 + y_offset,
-- 24 + x_offset,
-- 24 + y_offset,
-- 0)
draw_profile_pic(
post.profile_id,
8 + x_offset,
8 + y_offset)
-- image
rectfill(
32 + x_offset,
8 + y_offset,
64 + x_offset,
40 + y_offset,
0)
if not post.show_big_tit then
draw_post_pic(
post,
32 + x_offset,
8 + y_offset)
-- draw sticker
draw_sticker(post, 32 + x_offset, 8 + y_offset)
else
draw_big_tit(
post,
32 + x_offset,
8 + y_offset)
end
-- text
print(
post.first_row,
72 + x_offset,
16 + y_offset + text_y_offset)
print(
post.second_row,
72 + x_offset,
24 + y_offset + text_y_offset)
print(
post.third_row,
72 + x_offset,
32 + y_offset + text_y_offset)
end
function draw_posts()
local y_offset = posts_y_offset + 16
local x_offset = posts_x_offset
-- max 11 char for row
-- horrible code must refactor
draw_post(x_offset, 0 + y_offset, posts[1])
draw_post(0, 40 + y_offset, posts[2])
draw_post(0, 80 + y_offset, posts[3])
draw_post(0, 120 + y_offset, posts[4])
end
function draw_debug_stuff()
-- print(posts[0].first_row, 0, 0, 7)
-- print(posts_x_offset, 0, 0, 7)
-- print(flr(rnd(#database)), 0, 0, 7)
-- print(posts[1].flip_x, 0, 0, 7)
end
function draw_camera_shake()
if camera_shake_cooldown > 0 then
camera(
rnd(camera_shake_intensity) - (camera_shake_intensity / 2),
rnd(camera_shake_intensity) - (camera_shake_intensity / 2))
-- change_colors()
camera_shake_cooldown -= 0.1
else
camera()
-- pal()
end
end
function change_colors()
for i = 0, 16 do
pal(i, rnd(16))
end
end
function draw_countdown_bar()
local height = 12
rectfill(0, 128 - height, 128, 128, 0)
rectfill(0, 128 - height, 128 * countdown, 128, 7)
line(0, 128 - height, 128, 128 - height, 0)
end
function draw_sticker(post, offset_x, offset_y)
spr(
post.sticker_id,
post.sticker_x + offset_x,
post.sticker_y + offset_y)
end
-- end game draw stuff
-- start other update stuff
function process_menu_screen()
if btnp(1) and not menu_lock then
change_state(tutorial)
elseif btnp(0) and not menu_lock then
change_state(credits)
elseif btnp(2) and not menu_lock then
change_state(leaderboard)
else
menu_lock = false
end
end
function process_tutorial_input()
if btnp(1) and not menu_lock then
change_state(game)
else
menu_lock = false
end
end
function process_gameover_screen()
if check_if_high_score() then
change_state(add_score)
end
if btnp(2) and not menu_lock then
reset_game_state()
change_state(game)
elseif btnp(4) and not menu_lock then
reset_game_state_and_tutorial()
change_state(menu)
else
menu_lock = false
end
end
function process_credits_screen()
if btnp(1) and not menu_lock then
change_state(menu)
else
menu_lock = false
end
end
function process_leaderboard()
if btnp(3) and not menu_lock then
change_state(menu)
else
menu_lock = false
end
end
function process_add_score()
if btnp(0) then
as_index -= 1
-- cannot go before index 1
if (as_index <= 1) as_index = 1
end
if btnp(1) then
as_index += 1
end
if btnp(2) then
as_name[as_index] -= 1
as_name[as_index] %= 27
-- this shit cannot be zero!
if (as_name[as_index] == 0) as_name[as_index] = 26
end
if btnp(3) then
as_name[as_index] += 1
as_name[as_index] %= 27
-- this shit cannot be zero!
if (as_name[as_index] == 0) as_name[as_index] = 1
end
if as_index > 3 then
-- first add score
-- then reset state
add_to_high_scores()
reset_game_state()
change_state(leaderboard)
end
end
function evaluate_end_tutorial()
if tutorial_posts[1] == nil then
change_state(game)
end
end
-- end other update stuff
-- start other draw stuff
function draw_menu_screen()
rectfill(0, 0, 128, 128, 12)
falling_hearts_draw()
sspr(0, 96, 128, 32, 0, 27)
-- subtitle
credits_text = "(pulisci l'internet)"
print(credits_text, h_center(credits_text), 63, 7)
-- start text
blinking_text_centered("fai swipe a dx per iniziare", 80)
-- credits text
credits_text = "fai swipe a sx per i credits"
print(credits_text, h_center(credits_text), 94, 5)
-- leaderboard text
leaderboard_text = "fai swipe su per i punteggi"
print(leaderboard_text, h_center(leaderboard_text), 108, 5)
end
function draw_tutorial_screen()
rectfill(0, 0, 128, 128, 0)
print("tutorial", 60, 60, 7)
print("fai swipe a dx per continuare", 15, 80, 7)
end
function draw_gameover_screen()
local y_offset = -4
rectfill(0, 0, 128, 128, 1)
draw_text_wave(" game over ", 26 + y_offset)
draw_text_center("sei stato cacciato!", 52 + y_offset)
draw_text_center("il tuo punteggio e': "..score, 78 + y_offset)
blinking_text_centered("fai swipe su per riprovare", 104 + y_offset)
end
function draw_credits_screen()
local y_offset = 2
rectfill(0, 0, 128, 128, 12)
falling_hearts_draw()
draw_text_wave(" tambler the game ", 14 + y_offset)
draw_text_center("a pierettini production", 36 + y_offset)
draw_text_center("art: piera falcone", 54 + y_offset)
draw_text_center("code: giorgio pomettini", 72 + y_offset)
draw_text_center("music: tecla zorzi", 90 + y_offset)
blinking_text_centered("fai swipe a dx per continuare", 108 + y_offset)
end
function draw_text_wave(text, y)
for i = 0, #text do
wave_amount = 3
char_offset = i * (120 / #text)
char_y = y + (sin(time() + (i / #text))) * wave_amount
print(sub(text, i, i), char_offset, char_y, 7)
end
end
function draw_text_center(text, y)
print(text, h_center(text), y, 7)
end
function h_center(text)
return 64 - #text * 2
end
function draw_tutorial_post(x_offset, y_offset, post)
-- post bg
rectfill(
32 + x_offset,
8 + y_offset,
120 + x_offset,
40 + y_offset,
7)
-- profile pic
-- rectfill(
-- 8 + x_offset,
-- 8 + y_offset,
-- 24 + x_offset,
-- 24 + y_offset,
-- 0)
draw_profile_pic(
5,
8 + x_offset,
8 + y_offset)
-- text
print(
post.first_row,
40 + x_offset,
16 + y_offset + text_y_offset, 0)
print(
post.second_row,
40 + x_offset,
24 + y_offset + text_y_offset, 0)
print(
post.third_row,
40 + x_offset,
32 + y_offset + text_y_offset, 0)
end
function draw_tutorial_posts()
local y_offset = posts_y_offset + 16
local x_offset = posts_x_offset
-- horrible code must refactor
-- very horrible!!!
if tutorial_posts[1] != nil then
draw_tutorial_post(
x_offset,
0 + y_offset,
tutorial_posts[1])
end
for i = 2, #tutorial_posts + 1 do
if tutorial_posts[i] != nil then
draw_tutorial_post(
0,
(40 * (i - 1)) + y_offset,
tutorial_posts[i])
end
end
end
function draw_profile_pic(id, x, y)
-- rendering bug?
sspr(id * 16, 15, 16, 16, x, y)
end
function draw_post_pic(post, x, y)
sspr(post.pic_id * 32, 32, 32, 32, x, y, 32, 32, post.flip_x)
end
function draw_big_tit(post, x, y)
sspr(0, 64, 32, 32, x, y, 32, 32, post.flip_x)
end
function blinking_text_centered(text, y)
if (time() * blinking_speed) % 2 > 1 then
print(text, h_center(text), y, 7)
else
print(text, h_center(text), y, 5)
end
end
function blinking_text(text, x, y)
if (time() * blinking_speed) % 2 > 1 then
print(text, x, y, 7)
else
print(text, x, y, 5)
end
end
function falling_hearts_init()
falling_hearts = {}
for i = 1, 20 do
heart = {}
heart.x = rnd(128)
heart.y = rnd(128) - 128
heart.speed = 1 + rnd(1)
add(falling_hearts, heart)
end
end
function falling_hearts_draw()
for i = 1, 20 do
falling_hearts[i].y += falling_hearts[i].speed
print("♥", falling_hearts[i].x, falling_hearts[i].y, 8)
if (falling_hearts[i].y > 128) then
falling_hearts[i].y = 0
end
end
end
-- end other draw stuff
-- start music/sfx stuff
function start_menu_music()
if enable_music then
music(10)
end
end
function start_game_music()
if enable_music then
if not music_is_playing then
music(0)
music_is_playing = true
end
end
end
function sfx_correct()
sfx(38)
end
function sfx_wrong()
sfx(39)
end
-- end music/sfx stuff
-- start score stuff
function set_scores_default()
for i = 1, high_scores_count do
score = {}
score.name = "rob"
score.score = ((high_scores_count - i) + 1) * 10
add(high_scores, score)
end
end
function print_score_table()
for i = 1, high_scores_count do
print(high_scores[i].name.." "..high_scores[i].score)
end
end
function print_cartridge_content()
for i = 0, 15 do
print(dget(i))
end
end
function get_scores()
-- high scores are saved in memory like this:
-- name 1
-- name 1
-- name 1
-- score 1
-- name 2
-- name 2
-- name 2
-- score 2
high_scores = {}
for i = 1, high_scores_count do
local cart_index = i - 1
high_scores[i] = {}
high_scores[i].name = ""
high_scores[i].name = high_scores[i].name..char_to_uint[dget(0 + (cart_index * 4))]
high_scores[i].name = high_scores[i].name..char_to_uint[dget(1 + (cart_index * 4))]
high_scores[i].name = high_scores[i].name..char_to_uint[dget(2 + (cart_index * 4))]
high_scores[i].score = dget(3 + (cart_index * 4), high_scores[i].score)
end
end
function set_scores()
for i = 1, high_scores_count do
local cart_index = i - 1
dset(0 + (cart_index * 4), uint_to_char[sub(high_scores[i].name, 1, 1)])
dset(1 + (cart_index * 4), uint_to_char[sub(high_scores[i].name, 2, 2)])
dset(2 + (cart_index * 4), uint_to_char[sub(high_scores[i].name, 3, 3)])
dset(3 + (cart_index * 4), high_scores[i].score)
end
end
function check_if_high_score()
return score > high_scores[high_scores_count].score
end
function add_to_high_scores()
local entry = {}
-- horrible, horrible code
-- i'm so bad
-- please don't look at this code
-- please
-- i'm better than this
entry.name = char_to_uint[as_name[1]]..char_to_uint[as_name[2]]..char_to_uint[as_name[3]]
entry.score = score
add(high_scores, entry)
sort_high_scores()
set_scores()
end
function sort_high_scores()
function by_last(a, b)
return a.score > b.score
end
qsort(high_scores, by_last)
end
function draw_leaderboard()
local x_offset = -4
local y_offset = 2
local text_y_offset = 30
cls()
rectfill(0, 0, 128, 128, 12)
falling_hearts_draw()
draw_text_wave(" best scores ", 14 + y_offset)
color(7)
for i = 1, high_scores_count do
print(high_scores[i].name, 42 + x_offset, (i * 12) + text_y_offset)
print(high_scores[i].score, 84 + x_offset, (i * 12) + text_y_offset)
end
blinking_text_centered("fai swipe giu per continuare", 110 + y_offset)
end
function draw_add_score()
local x_offset = -2
local y_offset = -4
cls()
rectfill(0, 0, 128, 128, 12)
falling_hearts_draw()
draw_text_wave("sei in classifica!", 26 + y_offset)
draw_text_center("inserisci il tuo nome", 52 + y_offset)
print(char_to_uint[as_name[1]], 54 + x_offset, 78 + y_offset)
if as_index > 1 then
print(char_to_uint[as_name[2]], 64 + x_offset, 78 + y_offset)
end
if as_index > 2 then
print(char_to_uint[as_name[3]], 74 + x_offset, 78 + y_offset)
end
blinking_text_centered("fai swipe dx per avanzare", 104 + y_offset)
end
-- end score stuff
-- a: array to be sorted in-place
-- c: comparator (optional, defaults to ascending)
-- l: first index to be sorted (optional, defaults to 1)
-- r: last index to be sorted (optional, defaults to #a)
function qsort(a,c,l,r)
c,l,r=c or ascending,l or 1,r or #a
if l<r then
if c(a[r],a[l]) then
a[l],a[r]=a[r],a[l]
end
local lp,rp,k,p,q=l+1,r-1,l+1,a[l],a[r]
while k<=rp do
if c(a[k],p) then
a[k],a[lp]=a[lp],a[k]
lp+=1
elseif not c(a[k],q) then
while c(q,a[rp]) and k<rp do
rp-=1
end
a[k],a[rp]=a[rp],a[k]
rp-=1
if c(a[k],p) then
a[k],a[lp]=a[lp],a[k]
lp+=1
end
end
k+=1
end
lp-=1
rp+=1
a[l],a[lp]=a[lp],a[l]
a[r],a[rp]=a[rp],a[r]
qsort(a,c,l,lp-1 )
qsort(a,c, lp+1,rp-1 )
qsort(a,c, rp+1,r)
end
end
-- start pico8 reserved functions
function _init()
-- start debug
cartdata("tambler_1")
-- set_scores_default()
-- set_scores()
get_scores()
-- print_score_table()
-- print(check_if_high_score())
-- end debug
load_stickers()
load_database()
generate_posts()
load_tutorial_posts()
start_menu_music()
falling_hearts_init()
end
function _update()
-- start debug stuff
if (debug_stop_tick == true) return
-- end debug stuff
if gamestate == menu then
process_menu_screen()
end
if gamestate == tutorial then
process_buttons()
process_feed_animation()
process_swipe_animation()
evaluate_end_tutorial()
end
if gamestate == game then
process_buttons()
process_feed_animation()
process_swipe_animation()
decrease_countdown()
evaluate_gameover()
end
if gamestate == gameover then
process_gameover_screen()
end
if gamestate == credits then
process_credits_screen()
end
if gamestate == add_score then
process_add_score()
end
if gamestate == leaderboard then
process_leaderboard()
end
end
function _draw()
-- start debug stuff
if (debug_stop_tick == true) return
-- end debug stuff
if gamestate == menu then
draw_menu_screen()
end
if gamestate == tutorial then
draw_background()
draw_tutorial_posts()
blinking_text_centered("fai swipe a dx per avanzare", 9)
end