From 0393396d74e6925ba479f9972f4bdd281eaf77df Mon Sep 17 00:00:00 2001 From: Joe Z Date: Sun, 7 Jul 2019 17:25:35 -0400 Subject: [PATCH] Made instant DAS respect instant gravity. --- tetris/components/piece.lua | 5 ++++- tetris/rulesets/ruleset.lua | 14 +++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/tetris/components/piece.lua b/tetris/components/piece.lua index 1ae0790..1d82c23 100644 --- a/tetris/components/piece.lua +++ b/tetris/components/piece.lua @@ -78,12 +78,15 @@ function Piece:setRelativeRotation(rot) return self end -function Piece:moveInGrid(step, squares, grid) +function Piece:moveInGrid(step, squares, grid, instant) local moved = false for x = 1, squares do if grid:canPlacePiece(self:withOffset(step)) then moved = true self:setOffset(step) + if instant then + self:dropToBottom(grid) + end else break end diff --git a/tetris/rulesets/ruleset.lua b/tetris/rulesets/ruleset.lua index 7c11c10..81f332f 100644 --- a/tetris/rulesets/ruleset.lua +++ b/tetris/rulesets/ruleset.lua @@ -128,16 +128,16 @@ function Ruleset:attemptWallkicks(piece, new_piece, rot_dir, grid) -- do nothing in default ruleset end -function Ruleset:movePiece(piece, grid, move) +function Ruleset:movePiece(piece, grid, move, instant) local x = piece.position.x if move == "left" then - piece:moveInGrid({x=-1, y=0}, 1, grid) - elseif move == "speedleft" then - piece:moveInGrid({x=-1, y=0}, 10, grid) + piece:moveInGrid({x=-1, y=0}, 1, grid, false) elseif move == "right" then - piece:moveInGrid({x=1, y=0}, 1, grid) + piece:moveInGrid({x=1, y=0}, 1, grid, false) + elseif move == "speedleft" then + piece:moveInGrid({x=-1, y=0}, 10, grid, instant) elseif move == "speedright" then - piece:moveInGrid({x=1, y=0}, 10, grid) + piece:moveInGrid({x=1, y=0}, 10, grid, instant) end if piece.position.x ~= x then self:onPieceMove(piece, grid) @@ -212,7 +212,7 @@ function Ruleset:processPiece( hard_drop_enabled, additive_gravity ) self:rotatePiece(inputs, piece, grid, prev_inputs, false) - self:movePiece(piece, grid, move) + self:movePiece(piece, grid, move, gravity >= 20) self:dropPiece( inputs, piece, grid, gravity, drop_speed, drop_locked, hard_drop_locked, hard_drop_enabled, additive_gravity