From ea77b0aad8d6e4a56f81b314d9aa37e527a235d9 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sun, 26 Mar 2023 21:51:23 -0500 Subject: only reset lock delay when rotation succeeds --- game/init.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/game/init.lua b/game/init.lua index fe6d25f..c5925b1 100644 --- a/game/init.lua +++ b/game/init.lua @@ -53,8 +53,9 @@ function M:input_loop() elseif key == "down" then self.piece:move(-1, 0) elseif key == "up" then - self.piece:rotate() - evloop.queue "game.lock_cancel" + if self.piece:rotate() then + evloop.queue "game.lock_cancel" + end elseif key == "space" then local dropped = false while self.piece:move(-1, 0) do -- cgit v1.2.3 From 1e0c38bd730a5206160e07a8920aea3b95edcd0c Mon Sep 17 00:00:00 2001 From: the lemons Date: Sun, 26 Mar 2023 21:51:37 -0500 Subject: center polyominoes correctly --- game/polyomino.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/game/polyomino.lua b/game/polyomino.lua index 4294c7f..8696277 100644 --- a/game/polyomino.lua +++ b/game/polyomino.lua @@ -70,7 +70,7 @@ function M:drop(field) local new = setmetatable({poly = self}, piece) new.field = field new.line = field.lines - (self.bottom - 1) - new.column = math.floor(field.columns / 2 - self.size / 2 + 0.5) + new.column = math.floor(field.columns / 2 - self.size / 2 + 1) new.rotation = 1 if not new:can_occupy() then return -- cgit v1.2.3 From a966f45abf25dd486071a9552686e579de717417 Mon Sep 17 00:00:00 2001 From: the lemons Date: Sun, 26 Mar 2023 22:02:07 -0500 Subject: fix pieces locking midair --- game/init.lua | 11 ++++++++--- game/polyomino.lua | 18 ++++++++++++++---- 2 files changed, 22 insertions(+), 7 deletions(-) diff --git a/game/init.lua b/game/init.lua index c5925b1..1dba8b8 100644 --- a/game/init.lua +++ b/game/init.lua @@ -85,9 +85,14 @@ function M:input_loop() end function M:place_piece() - self.piece:place() - self.piece = nil - evloop.queue "game.lock_cancel" + if not self.piece:can_move(-1, 0) then + self.piece:place() + self.piece = nil + evloop.queue "game.lock_cancel" + return true + else + return false + end end function M:next_piece() diff --git a/game/polyomino.lua b/game/polyomino.lua index 8696277..9d9a295 100644 --- a/game/polyomino.lua +++ b/game/polyomino.lua @@ -96,6 +96,17 @@ function piece:can_occupy(line, column, rotation) return true end +function piece:can_move(lines, columns, rotation) + local rotation = self.rotation + (rotation or 0) + if rotation > 4 then + rotation = 1 + elseif rotation < 1 then + rotation = 4 + end + local line, column = self.line + lines or 0, self.column + columns or 0 + return self:can_occupy(line, column, rotation) +end + function piece:place() if self.placed then return @@ -126,10 +137,9 @@ function piece:rotate(ccw) end function piece:move(lines, columns) - local line, column = self.line + lines, self.column + columns - if self:can_occupy(line, column) then - self.line = line - self.column = column + if self:can_move(lines, columns) then + self.line = self.line + lines or 0 + self.column = self.column + columns or 0 return true end return false -- cgit v1.2.3