-
Notifications
You must be signed in to change notification settings - Fork 9
/
pushback.p8
2094 lines (1903 loc) · 69.9 KB
/
pushback.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 8
__lua__
-- pushback
-- you need to push them back!
cartdata("pushback_high_scores")
alphabet = "abcdefghijklmnopqrstuvwxyz "
-- constants {
-- coordinate systems
sp_world = 0
sp_local = 1
sp_screen_native = 2
sp_screen_center = 3
-- block kinds
bk_goon = 8
bk_pushable_box = 11
-- shiftable
ss_inert = 0
ss_shiftable = 1
ss_pushable = 2
g_goon_sprite = 70
g_pusher_sprite = 74
g_current_level = 1
g_current_score = 0
st_playing = 0
st_menu = 2
st_freeze = 3
g_freeze_frame = nil
g_freeze_framecount = nil
-- }
-- function clear_scores()
-- for i=0,63 do
-- dset(i, 1)
-- end
-- end
-- clear_scores()
-- next iteration:
-- - [tabled] facial expression on goon
-- - some way to get health back (heart box)
-- - super pellet?
function make_rain(x, y, angle, length, col, speed)
local start=g_tick
return {
x=x,
y=y,
space=sp_screen_native,
angle=angle,
length=length,
to_x = length*cos(angle),
to_y = length*sin(angle),
col=col,
speed=speed,
offset=0,
update=function(t)
t.offset=t.speed*elapsed(start_rain)
end,
draw=function(t)
local x=t.x
local y=(t.offset+t.y)%128
line(
x,
y,
x+t.to_x,
y+t.to_y,
t.col
)
end
}
end
function make_title()
start_rain = g_tick
local speeds={0.4,1.4}
for i=0,50 do
local speed=speeds[flr(rnd(2))+1]
add_gobjs(
make_rain(rnd(128), rnd(128), 0.25, 4, 1, rnd(1)+speed)
)
end
add_gobjs({
x=30,
y=20,
created=g_tick,
off_right_x = 2,
off_right_y = 1,
off_left_x = -2,
off_left_y = -1,
next_flash=300+flr(rnd(60)),
update=function(t)
local flash_mod = elapsed(t.created) % t.next_flash
if flash_mod == 0 or flash_mod == 10 then
set_freeze_frame(rnd(6))
if elapsed(t.created) % t.next_flash == 10 then
t.next_flash = 300 + flr(rnd(60))
end
end
end,
draw=function(t)
-- background
rectfill(-t.x, 33, 124-t.x, 58, 11)
rectfill(-t.x, 34, 124-t.x, 57, 0)
-- title text
for i=0,4 do
sspr(i*8, 32, 8, 8, i*14, 0, 16, 16)
sspr(i*8, 40, 8, 8, i*14, 16, 16, 16)
end
local amount = elapsed(t.created) / 240
local off = 10*sin(amount)
local off_pre = 10*sin(elapsed(t.created+10)/240)
local off_post = 10*sin(elapsed(t.created-18)/240)
local s = 9
local grimace=sin(1.25*amount)
local eye_dart = cos(2.5*amount)
if grimace > 0.25 then
eye_dart = cos(6.5*amount)
s = 10
end
local eye_dir = 13
if eye_dart > 0 then
eye_dir = 15
end
for i=12,15 do
local c = 7
if i > 13 then
c = 6
end
if i == eye_dir then
c = 1
end
if s != 12 then
pal(i, c)
end
end
local y_off = 43
for i=2,5 do
pal(i, 8)
end
spr(s, 24+off, y_off)
pal()
-- green block
spr(g_pusher_sprite,24+off_pre+20, y_off)
spr(g_pusher_sprite,24+off_post-20, y_off)
-- goons
local off_pre = 10*sin(elapsed(t.created+15)/240)
pushc(-(24+off_pre+30+t.off_right_x), -(y_off+t.off_right_y))
draw_goon()
popc()
local off_post = 10*sin(elapsed(t.created-21)/240)
pushc(-(24+off_post-30+t.off_left_x),- (y_off+t.off_left_y))
draw_goon()
popc()
end
})
local speeds={2.4,4.4}
for i=0,10 do
local speed=speeds[flr(rnd(2))+1]
add_gobjs(
make_rain(rnd(128), rnd(128), 0.25, 4, 6, rnd(1)+speed)
)
end
end
function _init()
stdinit()
make_title()
add_gobjs(
make_menu(
{
'go',
'high scores',
},
function (t, i, s)
add (
s,
make_trans(
function()
if i == 0 then
game_start()
else
g_current_score = 10
add_gobjs(make_high_score_list())
end
end
)
)
end
)
)
end
function _update60()
stdupdate()
end
function color_opaque_pixels(tgt_color)
local lines_to_color = 127
if g_dying and g_freeze_frame then
local frames_elapsed = elapsed(g_freeze_frame)
lines_to_color = rescale(frames_elapsed, 0, g_freeze_framecount, 0, 127)
end
for i=0,127 do
for j=0,lines_to_color do
if pget(i, j) != 0 then
pset(i, j, tgt_color)
end
end
end
end
function _draw()
stddraw()
if g_state == st_freeze then
targetc = 7
if g_dying then
targetc = 2
end
color_opaque_pixels(targetc)
else
if g_being_attacked then
color_opaque_pixels(8)
if elapsed(g_being_attacked) > 3 then
g_being_attacked = false
end
end
end
-- frozen objects draw after color operations
drawobjs(g_frozen_objs)
end
-- @{ useful utility function for getting started
function add_gobjs(thing)
add(g_objs, thing)
return thing
end
-- @}
function make_cell(x,y)
return {
x=1+9*(x-1)+1,
y=1+9*(y-1)+1,
space=sp_local,
grid_x=x,
grid_y=y,
containing=nil,
world_coords=function(t, from_center)
local result = vecadd(g_board, t)
if from_center == true then
result = vecadd(result, vecmake(3,3))
end
return result
end,
mark_for_contain=function(t, c, amt)
t.containing = c
if c.container then
c.container.containing = nil
end
mark_for_move(c, t, amt)
c.container = t
end,
draw=function(t)
rect(0,0,7,7, 5)
end
}
end
function make_goon(x, y)
-- goons are red for now
local newgoon = make_merge_box(bk_goon)
g_board:mark_cell_for_contain(x, y, newgoon, 1)
add(g_board.watch_cells, newgoon)
newgoon.time_last_move = g_tick
newgoon.shiftable = ss_pushable
newgoon.brain = br_move_at_player
g_goon_count += 1
return newgoon
end
function _pop_lowest_rank_in(some_list)
local lowest = some_list[1]
local lowest_rank = lowest.rank
for i=2,#some_list do
if some_list[i].rank < lowest_rank then
lowest = some_list[i]
lowest_rank = lowest.rank
end
end
del(some_list, lowest)
return lowest.cell
end
function neighbor_cells_of(x, y)
local neighbors = {}
-- + - x
if x > 1 then
add(neighbors, g_board.all_cells[x - 1][y])
end
if x < g_board.size_x then
add(neighbors, g_board.all_cells[x + 1][y])
end
-- + - y
if y > 1 then
add(neighbors, g_board.all_cells[x][y - 1])
end
if y < g_board.size_y then
add(neighbors, g_board.all_cells[x][y + 1])
end
return neighbors
end
function distance_to_player_heuristic(from_cell)
local dx = abs(from_cell.grid_x - g_player_piece.grid_x)
local dy = abs(from_cell.grid_y - g_player_piece.grid_y)
return (dx+dy)
end
function compute_path(from_cell, to_cell)
local frontier = {{cell=from_cell, rank=0}}
local came_from = {}
local cost_so_far = {}
came_from[from_cell] = nil
cost_so_far[from_cell] = 0
local move_cost = 1
while #frontier > 0 do
local current_cell = _pop_lowest_rank_in(frontier)
if current_cell == to_cell then
return came_from, cost_so_far
end
local new_cost = cost_so_far[current_cell] + move_cost
for _, next in pairs(current_cell.neighbors) do
if (
not (cell_is_not_empty(next) and next != to_cell)
)
and
(
cost_so_far[next] == nil or new_cost < cost_so_far[next]
) then
cost_so_far[next] = new_cost
local priority = new_cost + distance_to_player_heuristic(to_cell, next)
add(frontier, {cell=next, rank=priority})
came_from[next] = current_cell
end
end
end
return came_from, cost_so_far
end
function make_lose(t)
-- freeze the screen -- make trans back to menu?
-- @todo: better feedback that game is over
set_freeze_frame(240)
g_dying = true
add(g_frozen_objs,make_text(16, 6))
add_gobjs(make_trans(function() _game_over() end))
end
function rescale(current, from_low, from_hi, to_low, to_hi)
if not to_hi then
to_hi = 1
end
if not to_low then
to_low = 0
end
clamp(current, from_low, from_hi)
return (
((current - from_low) / (from_hi - from_low)) * (to_hi - to_low) + to_low
)
end
-- todo: could use a bit more sauce
function make_game_over_screen(score)
return {
x=-20,
y=-6,
space=sp_screen_center,
draw=function(t)
rect(0, 0, 38, 14, 8)
print("game over", 2, 2, 2)
print("score: "..score, 2, 8, 12)
end
}
end
function find_new_score_loc(scores, score)
if #scores >= 5 and scores[5][2] >= score then
return nil
end
ind = 1
for scr_tpl in all(scores) do
if score > scr_tpl[2] then
return ind
end
ind += 1
end
return ind
end
function load_high_score_table()
local highscore_table = {}
-- initials
for entry=0, 19, 4 do
local initials = ""
for i=0, 2 do
local current = dget(entry+i)
initials = initials .. sub(alphabet, current, current)
end
local score = dget(entry+3)
add(highscore_table, {initials, score})
end
return highscore_table
end
function save_score(scores, new_score_loc, initials, score)
new_scores = {}
for i=1, max(#scores, new_score_loc) do
if i == new_score_loc then
add(new_scores, {initials, score})
-- print(i..": ".."new: "..initials[1]..initials[2]..initials[3].. " ".. score)
end
if i <= #scores then
add(new_scores, {intified(scores[i][1]), scores[i][2]})
-- print(i..": "..scores[i][1])
end
end
for i=1, #new_scores do
for l=0,2 do
dset(4*(i-1)+l, new_scores[i][1][l+1])
-- print((i-1)*4+l)
end
dset(4*(i-1)+3, new_scores[i][2])
-- print(3+(i-1)*4)
end
end
function make_enter_score(score)
-- load the previous high scores
local scores = load_high_score_table()
local new_score_loc = find_new_score_loc(scores, score)
-- assume that score saved to table is sorted
if not new_score_loc then
-- show high score list
add_gobjs(make_retry(np))
add_gobjs(make_high_score_list(scores))
return
end
return {
x=0,
y=0,
initials = {1, 1, 1},
initial_str="aaa",
current_letter=0,
update=function(t)
if btnn(0) then
t.current_letter = max(t.current_letter - 1, 0)
end
if btnn(1) then
t.current_letter = min(t.current_letter + 1, 3)
end
-- down
if t.current_letter < 3 then
if btnn(3) then
t.initials[t.current_letter + 1] = min(
27,
t.initials[t.current_letter+1] + 1
)
if t.initials[t.current_letter + 1] == 27 then
t.initials[t.current_letter + 1] = 1
end
end
-- up
if btnn(2) then
t.initials[t.current_letter + 1] = max(
0,
t.initials[t.current_letter+1] - 1
)
if t.initials[t.current_letter + 1] == 0 then
t.initials[t.current_letter + 1] = 26
end
end
else
if btnn(4) or btnn(5) then
save_score(scores, new_score_loc, t.initials, score)
add_gobjs(make_retry())
add_gobjs(make_high_score_list())
del(g_go, t)
end
end
t.initial_str = ""
for i=1,3 do
t.initial_str = (t.initial_str..sub(alphabet, t.initials[i], t.initials[i]))
end
end,
draw=function(t)
-- background
rect(45,79,90,96,0)
rectfill(46,80,89,95,5)
print(t.initial_str,55,82,12)
print("high score!", 47, 90, 12)
if t.current_letter == 3 then
pal(1, 11)
end
spr(225, 67, 80, 2, 2)
if t.current_letter == 3 then
pal(1, 1)
end
-- cursor
if t.current_letter < 3 then
rect(54+4*t.current_letter, 81, 54+4*t.current_letter+4, 87, 11)
end
end
}
end
function _game_over()
local final_score = g_current_score
reset()
add_gobjs(make_enter_score(g_current_score))
end
function digits(num)
local result = 1
while (num/10 >= 1) do
result += 1
num = flr(num/10)
end
return result
end
function make_high_score_list(scores)
if not scores then
scores = load_high_score_table()
end
return {
x=40,
y=20,
ndigits=digits(scores[1][2]),
scores=scores,
draw=function(t)
cursor(0, 0)
rectfill(0,0, 2+(8+t.ndigits)*4+3, 2+6*5-1, 5)
rectfill(-1,-1, 3+(8+t.ndigits)*4, 2+6*5-2, 6)
rect(-2,-2, 2+(8+t.ndigits)*4+2, 2+6*5-2, 0)
for i, stuff in pairs(scores) do
if i == 1 then
color(8)
else
color(0)
end
print("["..i.."] "..stuff[1]..": "..stuff[2])
end
end
}
end
function intified(str)
result = {}
for i=1,3 do
for l=1,26 do
if sub(str, i, i) == sub(alphabet, l, l) then
add(result, l)
end
end
end
return result
end
function make_retry()
add_gobjs(make_game_over_screen(g_current_score))
add_gobjs(
make_menu(
{
"play again",
"main menu"
},
function (t, i, s)
add(
s,
make_trans(
function()
if i == 0 then
game_start()
else
_init()
end
end
)
)
end
)
)
end
function attack_player()
g_being_attacked = g_tick
shake_screen(15, 10, 3)
g_health -= 1
end
function br_move_at_player(t)
if t.attacking != nil and elapsed(t.attacking) % 60 == 0 then
attack_player(t)
end
local path, _ = compute_path(t.container, g_player_piece.container)
-- attack if next to the player
if path[g_player_piece.container] == t.container then
if t.attacking == nil then
t.attacking = g_tick
end
elseif t.attacking != nil then
t.attacking = nil
t.shake_offset = nil
end
if t.attacking then
t.shake_offset = vecrand(2, true)
end
if elapsed(t.time_last_move) > 45 and true then
t.time_last_move = g_tick
local current = g_player_piece.container
while path != {} and path[current] != nil do
last = current
current = path[current]
del(path, current)
if (
path[current] == t.container
and current == g_player_piece.container
) then
return
end
if (
path[current] == t.container
and current != g_player_piece.container
) then
current:mark_for_contain(t)
return
end
end
end
end
--[[
this needs to be refactored. instead a "want to move" buffer, then sweep and
resolve approach should be used.
]]--
function mark_for_move(t, to_cell, amt)
if amt and amt == 1 then
vecset(t, to_cell)
else
t.from_loc = vecmake(t.x, t.y)
t.to_loc = vecmake(to_cell.x, to_cell.y)
t.to_amount = amt or 0
add(g_board.dust,make_dust(t.from_loc))
end
t.grid_x = to_cell.grid_x
t.grid_y = to_cell.grid_y
end
function draw_goon()
local spr_offset=0
if g_tick % 10 <= 5 then
spr_offset=2
end
spr(g_goon_sprite+spr_offset, -4, -4,2,2)
end
function make_merge_box(block_kind)
return {
x=0,
y=0,
space=sp_local,
container=nil,
to_amount=1,
block_kind = block_kind,
shiftable=ss_shiftable,
brain=nil,
neighbor=function(t, inc_x, inc_y)
return (
g_board.all_cells[
t.container.grid_x+inc_x
][
t.container.grid_y+inc_y
].containing
)
end,
update=function(t)
if t.brain then
t:brain()
end
if t.from_loc and t.to_loc then
t.to_amount += 0.1
local interp_amount = smootherstep(0, 1, t.to_amount)
vecset(t, veclerp(t.from_loc, t.to_loc, interp_amount))
if t.to_amount == 1 then
t.from_loc = nil
t.to_loc = nil
end
end
if t.block_kind == bk_pushable_box then
t.shake_offset = nil
for x_dir = -1, 1, 2 do
if blocks_to_edge(t.container.grid_x, x_dir, 'x') == 1 then
local next_block = g_board:block(
t.container.grid_x + x_dir,
t.container.grid_y
)
if next_block and next_block.block_kind == bk_goon then
t.shake_offset = vecrand(2, true)
end
end
end
for y_dir = -1, 1, 2 do
if blocks_to_edge(t.container.grid_y, y_dir, 'y') == 1 then
local next_block = g_board:block(
t.container.grid_x,
t.container.grid_y + y_dir
)
if next_block and next_block.block_kind == bk_goon then
t.shake_offset = vecrand(2, true)
end
end
end
end
end,
draw=function(t)
local offset = t.shake_offset
if offset == nil then
offset = null_v
end
pushc(offset.x, offset.y)
if t.block_kind == bk_goon then
draw_goon()
else
spr(g_pusher_sprite, 0, 0)
end
popc()
end
}
end
function make_player_controller(player)
return {
x=0,
y=0,
space=sp_world,
player=player or 0,
update=function(t)
if not g_board then
return
end
-- input @{
if not (g_state == st_playing) then
return
end
local dir = vecmake(0,0)
local did_shift = false
if btnn(0, t.player) then
did_shift = g_board:shift_cells(1, 0)
dir.x=1
elseif btnn(1, t.player) then
did_shift = g_board:shift_cells(-1, 0)
dir.x = -1
elseif btnn(2, t.player) then
did_shift = g_board:shift_cells(0,1)
dir.y = 1
elseif btnn(3, t.player) then
did_shift = g_board:shift_cells(0,-1)
dir.y = -1
end
-- @}
if did_shift then
local eye_dir = 12
if dir.x == 1 then
eye_dir = 13
elseif dir.y == -1 then
eye_dir = 14
elseif dir.x == -1 then
eye_dir = 15
end
g_player_piece.eye_dir = eye_dir
end
end,
}
end
function empty_cells_on_edges(valid_edges)
local empty_cells = {}
for i=1,g_board.size_x do
for j=1,g_board.size_y do
-- only check border cells
if (
not valid_edges
or i==1 or i==g_board.size_x
or j==1 or j==g_board.size_y
) then
if (
not valid_edges
or (valid_edges.x ~= 0 and i == valid_edges.x)
or (valid_edges.y ~= 0 and j == valid_edges.y)
) then
if not block_is_not_empty(i, j) then
add(empty_cells, {i, j})
end
end
end
end
end
return empty_cells
end
-- if valid_edges is null, this will put boxes anywhere on the grid
function random_empty_cell(valid_edges)
local empty_cells = empty_cells_on_edges(valid_edges)
local num_empty_cells = #empty_cells
return empty_cells[flr(rnd(num_empty_cells))+1]
end
function cell_is_not_empty(cell)
return cell.containing != nil
end
function make_dust(loc)
local offsets={}
for i=1,3 do
add(offsets, {rnd(7), rnd(7)})
end
return {
x=loc.x,
y=loc.y,
space=sp_local,
start=g_tick,
offsets=offsets,
showing=#offsets,
update=function(t)
local e = elapsed(t.start)
if e > 10 then
del(g_board.dust, t)
end
if e % 3 == 0 then
t.showing -= 1
end
end,
draw=function(t)
for i=1,#t.offsets do
if i <= t.showing then
local o = t.offsets[i]
rect(o[1],o[2],o[1]+1,o[2]+1,6)
end
end
end
}
end
function make_level_transition()
g_current_level += 1
g_state = st_menu
make_level_complete()
end
function make_text(nspr, nchars)
return {
x=-(7*nchars)/2,
y=-4,
space=sp_screen_center,
start=g_tick,
draw=function(t)
for i=0,nchars do
local offset = 8*sin((elapsed(t.start+2*i)%90)/90)
spr(nspr+i, i*6, offset)
end
end
}
end
function make_level_complete()
add_gobjs(make_text(32, 5))
add_gobjs(make_scoreboard())
add_gobjs(
make_menu(
{
'continue!',
},
function(t,i,s)
add(
s,
make_trans(
function()
reset(false)
make_level()
end
)
)
end
)
)
end
function block_is_empty(i, j)
return (
i > 0 and i <= g_board.size_x and
j > 0 and j <= g_board.size_y and
not cell_is_not_empty(g_board.all_cells[i][j])
)
end
function block_is_not_empty(i, j)
return (
i > 0 and i <= g_board.size_x and
j > 0 and j <= g_board.size_y and
cell_is_not_empty(g_board.all_cells[i][j])
)
end
-- compute the number of blocks until the block edge
-- if dir is positive, go to the highest coordinate, negative goes towards 0
function blocks_to_edge(dim, dir, axis)
-- blocks_to_edge(1, 1) -> 4 || grid size: 5, 5
-- blocks_to_edge(2, 1) -> 3 || grid size: 5, 5
-- blocks_to_edge(3, 1) -> 2 || grid size: 5, 5
-- blocks_to_edge(4, 1) -> 1
-- blocks_to_edge(5, 1) -> 0
-- blocks_to_edge(1, -1) -> 0 || grid size: 5, 5
-- blocks_to_edge(2, -1) -> 1 || grid size: 5, 5
-- blocks_to_edge(3, -1) -> 2 || grid size: 5, 5
-- blocks_to_edge(4, -1) -> 3
-- blocks_to_edge(5, -1) -> 4
local size = 1
if dir > 0 then
size = g_board.size_x
if axis == 'y' then
size = g_board.size_y
end
end
return dir * (size - dim)
end
function shift_push_buffer(t, push_buffer, x_dir, y_dir)
local did_shift = false
if #push_buffer > 0 then