diff options
author | the lemons <citrons@mondecitronne.com> | 2023-03-25 01:35:17 -0500 |
---|---|---|
committer | the lemons <citrons@mondecitronne.com> | 2023-03-25 01:35:17 -0500 |
commit | 914283a631b10f289da85bce8e491e91b796d3f8 (patch) | |
tree | ba5bbfebc54f62f8c14da013a008972c0f543564 | |
parent | 1c167b5d959491301144f68d80edcaee35647330 (diff) |
add line clears
-rw-r--r-- | main.lua | 1 | ||||
-rw-r--r-- | playfield.lua | 31 |
2 files changed, 23 insertions, 9 deletions
@@ -52,6 +52,7 @@ local function gravity() piece = nil end end + field:remove_cleared() end local interval = 0.5 diff --git a/playfield.lua b/playfield.lua index 22a32cb..4f0023d 100644 --- a/playfield.lua +++ b/playfield.lua @@ -23,23 +23,36 @@ function M:cell_full(line, column) end end -function M:line_full(line) - for column = 1, w do - if self.cells[line][column] then - return true +function M:line_cleared(line) + for column = 1, self.columns do + if not self:cell_full(line, column) then + return false end end - return false + return true end - -function M:shift_down(line) +function M:remove_line(line) + for line = line, self.lines * 2 do + self.cells[line] = self.cells[line + 1] + end end -function M:shift_up(line) +function M:insert_line(line) + for line = self.lines * 2, -line + 1 do + self.cells[line] = self.cells[line - 1] + end end -function M:clear_full() +function M:remove_cleared() + local line = 1 + while line < self.lines * 2 do + if self:line_cleared(line) then + self:remove_line(line) + else + line = line + 1 + end + end end return M |