summaryrefslogtreecommitdiff
path: root/game/polyomino.lua
diff options
context:
space:
mode:
Diffstat (limited to 'game/polyomino.lua')
-rw-r--r--game/polyomino.lua18
1 files changed, 14 insertions, 4 deletions
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