Fix basic rotation and add attempt to do 2nd wallkick before failed

This commit is contained in:
SweetSea
2024-10-27 06:05:19 +07:00
parent 7eb445e2c6
commit af659a69fe

View File

@@ -4,7 +4,7 @@ local Piece = require 'game.piece'
local Rotation = Object:extend()
Rotation.spawn_positions = {
I = { x=2, y= 0 },
I = { x=2, y= -2 },
J = { x=2, y= 0 },
L = { x=2, y= 0 },
O = { x=2, y= 0 },
@@ -219,12 +219,12 @@ Rotation.block_offsets = {
{x=2, y=3}, {x=3, y=3}, {x=4, y=3}, {x=5, y=3},
},
{
{x=2, y=0}, {x=3, y=0},
{x=2, y=1}, {x=3, y=1},
{x=0, y=2}, {x=1, y=2}, {x=2, y=2}, {x=3, y=2},
{x=0, y=3}, {x=1, y=3}, {x=2, y=3}, {x=3, y=3},
{x=0, y=4}, {x=1, y=4},
{x=0, y=5}, {x=1, y=5},
{x=4, y=0}, {x=5, y=0},
{x=4, y=1}, {x=5, y=1},
{x=2, y=2}, {x=3, y=2}, {x=4, y=2}, {x=5, y=2},
{x=2, y=3}, {x=3, y=3}, {x=4, y=3}, {x=5, y=3},
{x=2, y=4}, {x=3, y=4},
{x=2, y=5}, {x=3, y=5},
},
{
{x=0, y=0}, {x=1, y=0}, {x=2, y=0}, {x=3, y=0},
@@ -233,12 +233,12 @@ Rotation.block_offsets = {
{x=2, y=3}, {x=3, y=3}, {x=4, y=3}, {x=5, y=3},
},
{
{x=2, y=0}, {x=3, y=0},
{x=2, y=1}, {x=3, y=1},
{x=0, y=2}, {x=1, y=2}, {x=2, y=2}, {x=3, y=2},
{x=0, y=3}, {x=1, y=3}, {x=2, y=3}, {x=3, y=3},
{x=0, y=4}, {x=1, y=4},
{x=0, y=5}, {x=1, y=5},
{x=4, y=0}, {x=5, y=0},
{x=4, y=1}, {x=5, y=1},
{x=2, y=2}, {x=3, y=2}, {x=4, y=2}, {x=5, y=2},
{x=2, y=3}, {x=3, y=3}, {x=4, y=3}, {x=5, y=3},
{x=2, y=4}, {x=3, y=4},
{x=2, y=5}, {x=3, y=5},
},
}
}
@@ -334,6 +334,8 @@ function Rotation:attemptWallkicks(piece, new_piece, rot_dir, grid, lastdir)
elseif sides.bottom then kick = {x=0,y=-1}
end
-- Attempt to push the piece 2 blocks away since it is in double size
local kick_double = {x=kick[x]*2,kick[y]*2}
if grid:canPlacePiece(new_piece:withOffset({x=0,y=0})) then
self:onPieceRotate(piece, grid)
@@ -341,6 +343,9 @@ function Rotation:attemptWallkicks(piece, new_piece, rot_dir, grid, lastdir)
elseif grid:canPlacePiece(new_piece:withOffset(kick)) then
self:onPieceRotate(piece, grid)
piece:setRelativeRotation(rot_dir):setOffset(kick)
elseif grid:canPlacePiece(new_piece:withOffset(kick_double)) then
self:onPieceRotate(piece, grid)
piece:setRelativeRotation(rot_dir):setOffset(kick_double)
end
end