-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathclearing-blocks.lua
139 lines (126 loc) · 4.26 KB
/
clearing-blocks.lua
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
-->8
-- clearing blocks
function yield_n_times(n)
local i
for i=1,n do
yield()
end
end
function calculate_points_scored(blocks_cleared)
return (level+1)*((blocks_cleared-2)^2)
end
function let_pieces_settle()
--todo do this as a coroutine too
local falling=true
while falling do
falling=false
-- todo make this happen over multiple frames
for_all_tiles(function(y, x)
if board[y][x] ~= empty then
if block_can_fall_left(y,x) then
move_piece(y, x, y-1, x_for_next_row(y,x))
falling=true
end
end
end)
if falling then
yield_n_times(2)
end
local falling_right = false
for_all_tiles(function(y, x)
if board[y][x] ~= empty then
if block_can_fall_right(y,x) then
move_piece(y, x, y-1, x_for_next_row(y,x)+1)
falling=true
falling_right=true
end
end
end)
if falling_right then
yield_n_times(2)
end
end
end
function find_blocks_to_delete()
local blocks_to_delete = {} -- y,x pairs
for_all_tiles(function(y,x)
local current_piece = board[y][x]
if current_piece ~= empty then
local one_row_up_x = x_for_next_row(y, x)
-- square!
if current_piece == board[y+1][one_row_up_x] and current_piece == board[y+1][one_row_up_x+1] and current_piece == board[y+2][x] then
add(blocks_to_delete,{y=y,x=x})
add(blocks_to_delete,{y=y+1,x=one_row_up_x})
add(blocks_to_delete,{y=y+1,x=one_row_up_x+1})
add(blocks_to_delete,{y=y+2,x=x})
end
-- line going left!
if current_piece == board[y+1][one_row_up_x] and current_piece == board[y+2][x-1] then
add(blocks_to_delete,{y=y,x=x})
add(blocks_to_delete,{y=y+1,x=one_row_up_x})
add(blocks_to_delete,{y=y+2,x=x-1})
end
-- line going right!
if current_piece == board[y+1][one_row_up_x+1] and current_piece == board[y+2][x+1] then
add(blocks_to_delete,{y=y,x=x})
add(blocks_to_delete,{y=y+1,x=one_row_up_x+1})
add(blocks_to_delete,{y=y+2,x=x+1})
end
end
end)
return blocks_to_delete
end
function hit_bottom()
hard_dropping = false
combo_size = 0
y_shift -= shimmy_coefficient/2
sfx(11)
blocks_clearing=cocreate(function()
yield_n_times(3)
let_pieces_settle()
yield_n_times(3)
local cleared_things = true -- todo this is a lie at this moment
local scored_this_turn = 0
while cleared_things do
cleared_things = false
local blocks_to_delete = find_blocks_to_delete()
local cleared_this_iteration = 0 --todo this makes cleared_things pointless
for b in all(blocks_to_delete) do
cleared_things = true
if board[b.y][b.x] ~= empty then
cleared_this_iteration += 1
particles_for_block_clear(b.y, b.x, board[b.y][b.x])
end
board[b.y][b.x] = empty
end
if cleared_things then
combo_size += 1
local combo_multiplier = mid(1, combo_size, 4)
cleared += cleared_this_iteration
scored_this_turn += combo_multiplier * calculate_points_scored(cleared_this_iteration, level)
if #blocks_to_delete < 4 then
small_clear_sound()
else
big_clear_sound()
end
end
yield_n_times(3)
if cleared_things then
let_pieces_settle()
end
end
if combo_size > 1 then
drawing_combo_text = cocreate(draw_combo_text)
yield_n_times(2)
combo_reward_sound()
end
score += scored_this_turn
level = flr(cleared/30)
if level == 15 then
game_state = "won"
music(10)
else
new_player_quad()
end
end)
end