From 3cf5daeb2e6bc981820076189b62b16990b24498 Mon Sep 17 00:00:00 2001 From: Ishaan Bhardwaj Date: Sun, 21 Feb 2021 09:52:50 -0500 Subject: [PATCH] Piece class now handles negative gravity correctly --- tetris/components/piece.lua | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/tetris/components/piece.lua b/tetris/components/piece.lua index 457aba1..5a227c5 100644 --- a/tetris/components/piece.lua +++ b/tetris/components/piece.lua @@ -127,12 +127,20 @@ function Piece:addGravity(gravity, grid, classic_lock) self.lock_delay = self.lock_delay + 1 end else - local dropped_squares = math.floor(new_gravity) + local dropped_squares = math.floor(math.abs(new_gravity)) local new_frac_gravity = new_gravity - dropped_squares self.gravity = new_frac_gravity - self:dropSquares(dropped_squares, grid) - if self:isDropBlocked(grid) then - playSE("bottom") + if gravity >= 0 then + local new_frac_gravity = new_gravity - dropped_squares + self.gravity = new_frac_gravity + self:dropSquares(dropped_squares, grid) + if self:isDropBlocked(grid) then + playSE("bottom") + end + else + local new_frac_gravity = new_gravity + dropped_squares + self.gravity = new_frac_gravity + self:moveInGrid({ x = 0, y = -1 }, dropped_squares, grid) end end return self