From c1bec0947d71ef0900b68300ec1ad351600307ff Mon Sep 17 00:00:00 2001 From: heav Date: Mon, 27 Mar 2023 11:39:03 +0000 Subject: t spin detection and sound effects. --- game/heav_optimal_shapes.lua | 4 ++++ game/init.lua | 9 ++++++++- game/playfield.lua | 3 +++ game/polyomino.lua | 18 ++++++++++++++++++ game/sfx.lua | 1 + 5 files changed, 34 insertions(+), 1 deletion(-) diff --git a/game/heav_optimal_shapes.lua b/game/heav_optimal_shapes.lua index 663a7d1..eb517ea 100644 --- a/game/heav_optimal_shapes.lua +++ b/game/heav_optimal_shapes.lua @@ -29,6 +29,10 @@ M.semicolon = poly.def("heav.semicolon", [[ ##. ]]) +M.dot = poly.def("heav.dot", [[ + # +]]) + M.amongus = poly.def("heav.amongus", [[ ....###.. ...#####. diff --git a/game/init.lua b/game/init.lua index 3276caf..3f7c111 100644 --- a/game/init.lua +++ b/game/init.lua @@ -25,6 +25,7 @@ function M.new(params) new.field = playfield.new(params.lines or 20, params.columns or 10) new.hold = false new.can_hold = true + new.t_spun = false new.gfx = gfx.new(new) new.gravity_delay = 0.5 new.lock_delay = params.lock_delay or 0.5 @@ -93,8 +94,14 @@ function M:place_piece() if not self.piece:can_move(-1, 0) then self.piece:place() evloop.queue "game.lock_cancel" + local cleared = self.field:remove_cleared() + if cleared > 0 then + if self.piece.t_spun then + local sound = ({"tspinsingle","tspindouble","tspintriple"})[cleared] + sfx.play(sound) + end + end self:next_piece() - self.field:remove_cleared() return true else return false diff --git a/game/playfield.lua b/game/playfield.lua index 0f89d1a..9c85dba 100644 --- a/game/playfield.lua +++ b/game/playfield.lua @@ -50,13 +50,16 @@ end function M:remove_cleared() local line = 1 + local cleared_lines = 0 while line < self.lines * 2 do if self:line_cleared(line) then self:remove_line(line) + cleared_lines = cleared_lines + 1 else line = line + 1 end end + return cleared_lines end return M diff --git a/game/polyomino.lua b/game/polyomino.lua index ddafd48..1407863 100644 --- a/game/polyomino.lua +++ b/game/polyomino.lua @@ -8,6 +8,9 @@ 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}}} new.cells = {} + new.last_rotated = false + new.t_spun = false + new.last_kick_id = 0 for l in shape:gmatch "[^%s]+" do local line = {} new.size = #l @@ -125,6 +128,16 @@ function piece:place() self.placed = true end +function piece:t_spin_check() + if self.poly.name ~= "tetr.T" then return false end + if self.last_kick_id == 5 then return true end + local check_points = {{0,0},{2,2},{0,2},{2,0}} + local corners_total = 0 + for i, v in ipairs(check_points) do + if self.field.cells[self.line+v[1]][self.column+v[2]] then corners_total = corners_total + 1 end + end + return corners_total >= 3 +end function piece:rotate(ccw) local rotation = self.rotation + (ccw and -1 or 1) if rotation > 4 then @@ -157,6 +170,9 @@ function piece:rotate(ccw) self.rotation = rotation self.line = ty self.column = tx + self.last_rotated = true + self.last_kick_id = i + self.t_spun = self:t_spin_check() return true end end @@ -167,6 +183,8 @@ function piece:move(lines, columns) if self:can_move(lines, columns) then self.line = self.line + lines or 0 self.column = self.column + columns or 0 + self.last_rotated = false + self.t_spun = false return true end return false diff --git a/game/sfx.lua b/game/sfx.lua index 291c945..cd6ae2e 100644 --- a/game/sfx.lua +++ b/game/sfx.lua @@ -1,5 +1,6 @@ local sounds = { "harddrop", + "tspinsingle", "tspindouble", "tspintriple", } local sources = {} -- cgit v1.2.3