From 1234e783548d5af8ef63deeb6cf5e21ad053378d Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 21 Feb 2021 10:41:05 -0500 Subject: [PATCH] Refactored immobile detection --- tetris/modes/gamemode.lua | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index 2ef3208..bcb2e0a 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -136,31 +136,13 @@ function GameMode:update(inputs, ruleset) self:chargeDAS(inputs, self:getDasLimit(), self:getARR()) -- set attempt flags - if inputs["left"] or inputs["right"] then - self:onAttemptPieceMove(self.piece, self.grid) - if self.immobile_spin_bonus and self.piece ~= nil then - if not self.piece:isMoveBlocked(self.grid, { x=-1, y=0 }) and - not self.piece:isMoveBlocked(self.grid, { x=1, y=0 }) then - self.piece.spin = false - end - end - end - if + if inputs["left"] or inputs["right"] then self:onAttemptPieceMove(self.piece, self.grid) end + if ( inputs["rotate_left"] or inputs["rotate_right"] or inputs["rotate_left2"] or inputs["rotate_right2"] or inputs["rotate_180"] - then + ) then self:onAttemptPieceRotate(self.piece, self.grid) - if self.immobile_spin_bonus and self.piece ~= nil then - if self.piece:isDropBlocked(self.grid) and - self.piece:isMoveBlocked(self.grid, { x=-1, y=0 }) and - self.piece:isMoveBlocked(self.grid, { x=1, y=0 }) and - self.piece:isMoveBlocked(self.grid, { x=0, y=-1 }) then - self.piece.spin = true - else - self.piece.spin = false - end - end end if self.piece == nil then @@ -244,7 +226,19 @@ function GameMode:update(inputs, ruleset) end if self.piece.locked == true then + -- spin detection, immobile only for now + if self.immobile_spin_bonus and ( + self.piece:isDropBlocked(self.grid) and + self.piece:isMoveBlocked(self.grid, { x=-1, y=0 }) and + self.piece:isMoveBlocked(self.grid, { x=1, y=0 }) and + self.piece:isMoveBlocked(self.grid, { x=0, y=-1 }) + ) then + self.piece.spin = true + end + self.grid:applyPiece(self.piece) + + -- mark squares (can be overridden) if self.square_mode then self.squares = self.squares + self.grid:markSquares() end