summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorheav <hheav3@gmail.com>2023-03-27 07:05:15 +0000
committerheav <hheav3@gmail.com>2023-03-27 07:05:15 +0000
commit8b6d7690c1bad22af49da31954ae4929dad5a9df (patch)
tree0115e2f6580557adca097da5d3c03e4bf51a77e7
parenta155c2b5b8433d259f53049a9e62d68a63969404 (diff)
add SRS.
-rw-r--r--game/gfx.lua13
-rw-r--r--game/init.lua2
-rw-r--r--game/polyomino.lua35
-rw-r--r--game/tetrominoes.lua26
4 files changed, 61 insertions, 15 deletions
diff --git a/game/gfx.lua b/game/gfx.lua
index d935fd9..a5a05a8 100644
--- a/game/gfx.lua
+++ b/game/gfx.lua
@@ -1,6 +1,7 @@
local evloop = require "evloop"
local viewport = require "viewport"
local tetrominoes = require "game/tetrominoes"
+local debug_gfx = require "game.debug_gfx"
local M = {}
M.__index = M
@@ -110,9 +111,8 @@ function M:draw_queue()
end
end
-function M:draw_piece(shadow)
- local piece = self.game.piece
- if shadow then
+function M:draw_piece_general(piece,shadow)
+ if shadow and shadow ~= "only visual" then
local old_piece = piece
piece = piece.poly:drop(self.game.field)
piece.line = old_piece.line
@@ -133,6 +133,10 @@ function M:draw_piece(shadow)
end
end
+function M:draw_piece(shadow)
+ self:draw_piece_general(self.game.piece, shadow)
+end
+
function M:draw_field()
local field = self.game.field
local _, x, y, w, h = self:field_dimensions()
@@ -155,6 +159,9 @@ function M:draw(dt)
if self.game.piece then
self:draw_piece(true) -- shadow.
end
+ for i=1, #debug_gfx.stack do
+ debug_gfx.stack[i](self)
+ end
end
function M:loop()
diff --git a/game/init.lua b/game/init.lua
index 19d10ee..a273d31 100644
--- a/game/init.lua
+++ b/game/init.lua
@@ -91,6 +91,7 @@ function M:place_piece()
self.piece:place()
evloop.queue "game.lock_cancel"
self:next_piece()
+ self.field:remove_cleared()
return true
else
return false
@@ -120,7 +121,6 @@ end
function M:gravity_loop()
local function loop()
evloop.sleep(self.gravity_delay)
- self.field:remove_cleared()
if self.piece and not self.piece:move(-1, 0) then
evloop.queue "game.lock"
end
diff --git a/game/polyomino.lua b/game/polyomino.lua
index ba6da92..ddafd48 100644
--- a/game/polyomino.lua
+++ b/game/polyomino.lua
@@ -1,6 +1,9 @@
local M = {}
M.__index = M
+local evloop = require "evloop"
+local debug_gfx = require "game.debug_gfx"
+
function M.def(name, shape, kick_table)
local new = setmetatable({name = name}, M)
new.kick_table = kick_table or {{{0, 0}}, {{0, 0}}, {{0, 0}}, {{0, 0}}}
@@ -129,11 +132,35 @@ function piece:rotate(ccw)
elseif rotation < 1 then
rotation = 4
end
- if not self:can_occupy(nil, nil, rotation) then
- return false
+ for i,v in ipairs(self.poly.kick_table[ccw and rotation or self.rotation]) do
+ local mul = ccw and -1 or 1
+ local ty = self.line + v[2] * mul
+ local tx = self.column + v[1] * mul
+
+ --[[ debug rotation
+ if i ~= 1 then
+ evloop.paused = true
+ local shadow = self.poly:drop(self.field)
+ shadow.line = ty
+ shadow.column = tx
+ shadow.rotation = rotation
+ debug_gfx.push(function(self)
+ self:draw_piece_general(shadow, "only visual")
+ end)
+ evloop.debug_sleep(0.6)
+ debug_gfx.pop()
+ evloop.paused = false
+ end
+ ]]
+
+ if self:can_occupy(ty, tx, rotation) then
+ self.rotation = rotation
+ self.line = ty
+ self.column = tx
+ return true
+ end
end
- self.rotation = rotation
- return true
+ return false
end
function piece:move(lines, columns)
diff --git a/game/tetrominoes.lua b/game/tetrominoes.lua
index 94d5b18..83529ef 100644
--- a/game/tetrominoes.lua
+++ b/game/tetrominoes.lua
@@ -3,48 +3,60 @@ local poly = require "game.polyomino"
local M = {}
M.__index = M
+local jlstz_kicks = {
+ {{0,0}, {-1,0}, {-1, 1}, {0,-2}, {-1,-2}},
+ {{0,0}, { 1,0}, { 1,-1}, {0, 2}, { 1, 2}},
+ {{0,0}, { 1,0}, { 1, 1}, {0,-2}, { 1,-2}},
+ {{0,0}, {-1,0}, {-1,-1}, {0, 2}, {-1, 2}},
+}
+
M.i = poly.def("tetr.I", [[
....
####
....
....
-]])
+]], {
+ {{0,0}, {-2,0}, {1,0}, {-2,-1}, {1,2}}, -- TODO: format this nicely if you dare.
+ {{0,0}, {-1,0}, {2,0}, {-1,2}, {2,-1}},
+ {{0,0}, {2,0}, {-1,0}, {2,1}, {-1,-2}},
+ {{0,0}, {1,0},{-2,0},{1,-2},{-2,1}},
+})
M.j = poly.def("tetr.J", [[
#..
###
...
-]])
+]], jlstz_kicks)
M.l = poly.def("tetr.L", [[
..#
###
...
-]])
+]], jlstz_kicks)
M.o = poly.def("tetr.O", [[
....
.##.
.##.
....
-]])
+]], jlstz_kicks)
M.s = poly.def("tetr.S", [[
.##
##.
...
-]])
+]], jlstz_kicks)
M.z = poly.def("tetr.Z", [[
##.
.##
...
-]])
+]], jlstz_kicks)
M.t = poly.def("tetr.T", [[
.#.
###
...
-]])
+]], jlstz_kicks)
return M