Piece class now handles negative gravity correctly

This commit is contained in:
Ishaan Bhardwaj 2021-02-21 09:52:50 -05:00
parent 1dfe68ccff
commit 3cf5daeb2e

View File

@ -127,13 +127,21 @@ function Piece:addGravity(gravity, grid, classic_lock)
self.lock_delay = self.lock_delay + 1 self.lock_delay = self.lock_delay + 1
end end
else 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
if gravity >= 0 then
local new_frac_gravity = new_gravity - dropped_squares local new_frac_gravity = new_gravity - dropped_squares
self.gravity = new_frac_gravity self.gravity = new_frac_gravity
self:dropSquares(dropped_squares, grid) self:dropSquares(dropped_squares, grid)
if self:isDropBlocked(grid) then if self:isDropBlocked(grid) then
playSE("bottom") playSE("bottom")
end 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 end
return self return self
end end