PAIRS moved to modpack, Race 40 moved to game

Duality A1, KRS, Texy-World added
pull/4/head
Ishaan Bhardwaj 2021-02-21 23:18:55 -05:00
parent 303e844608
commit fa23e21f9d
5 changed files with 584 additions and 0 deletions

View File

@ -0,0 +1,65 @@
local MarathonA1Game = require 'tetris.modes.marathon_a1'
local Grid = require 'tetris.components.grid'
local SplitHistoryRandomizer = require 'tetris.randomizers.split_history'
local DualityA1Game = MarathonA1Game:extend()
DualityA1Game.name = "Duality A1"
DualityA1Game.hash = "DualityA1"
DualityA1Game.tagline = "Control two boards at once!"
function DualityA1Game:new()
DualityA1Game.super:new()
self.randomizer = SplitHistoryRandomizer()
self.other_grid = Grid(10, 24)
self.next_queue_length = 2
end
function DualityA1Game:updateScore(level, drop_bonus, cleared_lines)
if not self.clear then
if self.grid:checkForBravo(cleared_lines) then
self.bravo = 4
self.bravos = self.bravos + 1
else self.bravo = 1 end
if cleared_lines > 0 then
self.combo = self.combo + (cleared_lines - 1) * 2
self.score = self.score + (
(math.ceil((level + cleared_lines) / 4) + drop_bonus) *
cleared_lines * self.combo * self.bravo
)
else
self.combo = 1
end
self.drop_bonus = 0
end
if cleared_lines ~= 0 then return end
self.grid, self.other_grid = self.other_grid, self.grid
end
function DualityA1Game:afterLineClear(cleared_row_count)
self.grid, self.other_grid = self.other_grid, self.grid
end
local function fadeOut(game, block, x, y, age)
local opacity = (game.are - (game:getARE() / 2)) / (game:getARE() / 2)
return 0.5, 0.5, 0.5, opacity, opacity
end
local function fadeIn(game, block, x, y, age)
local opacity = (game.are - (game:getARE() / 2)) / (game:getARE() / 2)
return 0.5, 0.5, 0.5, 1 - opacity, 1 - opacity
end
function DualityA1Game:drawGrid()
if self.lcd == 0 and self.are > 0 then
self.grid:drawCustom(fadeIn, self)
self.other_grid:drawCustom(fadeOut, self)
else
self.grid:draw()
end
if self.piece ~= nil and self.level < 100 then
self:drawGhostPiece()
end
end
return DualityA1Game

View File

@ -0,0 +1,40 @@
local Randomizer = require 'tetris.randomizers.randomizer'
local SplitHistoryRandomizer = Randomizer:extend()
function SplitHistoryRandomizer:initialize()
self.history = {"Z", "Z", "Z", "Z", "Z", "Z", "Z", "Z"}
self.piece_count = 0
end
function SplitHistoryRandomizer:generatePiece()
if self.piece_count < 2 then
self.piece_count = self.piece_count + 1
return self:updateHistory(({"L", "J", "I", "T"})[math.random(4)])
else
local shapes = {"I", "J", "L", "O", "S", "T", "Z"}
for i = 1, 4 do
local x = math.random(7)
if not inHistory(shapes[x], self.history) or i == 4 then
return self:updateHistory(shapes[x])
end
end
end
end
function SplitHistoryRandomizer:updateHistory(shape)
table.remove(self.history, 1)
table.insert(self.history, shape)
return shape
end
function inHistory(piece, history)
for i = 1, 7, 2 do
if history[i] == piece then
return true
end
end
return false
end
return SplitHistoryRandomizer

184
tetris/rulesets/krs.lua Normal file
View File

@ -0,0 +1,184 @@
local SRS = require 'tetris.rulesets.ti_srs'
local KRS = SRS:extend()
KRS.name = "K.R.S."
KRS.hash = "KRS"
KRS.wallkicks_3x3 = {
[0]={
[1]={{-1,0},{-1,-1}},
[2]={{0,-1},{0,-2}},
[3]={{1,0},{1,-1}},
},
[1]={
[0]={{1,0},{1,1}},
[2]={{1,0},{1,-1}},
[3]={{2,0}},
},
[2]={
[0]={{0,1},{0,2}},
[1]={{-1,0},{-1,1}},
[3]={{1,0},{1,1}},
},
[3]={
[0]={{-1,0},{-1,1}},
[1]={{-2,0}},
[2]={{-1,0},{-1,-1}},
},
}
KRS.wallkicks_line = {
[0]={
[1]={{-1,0},{-1,-1},{1,0},{1,1}},
[2]={{0,-1},{0,-2}},
[3]={{1,0},{1,-1},{-1,0},{-1,1}},
},
[1]={
[0]={{1,0},{1,1},{-1,0},{-1,-1}},
[2]={{1,0},{1,-1},{-1,0},{-1,1}},
[3]={{2,0}},
},
[2]={
[0]={{0,1},{0,2}},
[1]={{-1,0},{-1,1},{1,0},{1,-1}},
[3]={{1,0},{1,1},{-1,0},{-1,-1}},
},
[3]={
[0]={{-1,0},{-1,1},{1,0},{1,-1}},
[1]={{-2,0}},
[2]={{-1,0},{-1,-1},{1,0},{1,1}},
},
}
function KRS:onPieceCreate(piece)
piece.das_kicked = false
piece.recovery_frames = self.game:getLockDelay() * 15
end
function KRS:onPieceDrop() end
function KRS:onPieceMove(piece)
while piece.lock_delay > 0 and piece.recovery_frames > 0 do
piece.recovery_frames = piece.recovery_frames - 1
piece.lock_delay = piece.lock_delay - 1
end
end
function KRS:onPieceRotate(piece)
while piece.lock_delay > 0 and piece.recovery_frames > 0 do
piece.recovery_frames = piece.recovery_frames - 1
piece.lock_delay = piece.lock_delay - 1
end
end
function KRS:canPieceMove(piece)
return not piece.das_kicked
end
function KRS:canPieceRotate(piece) return true end
function KRS:attemptRotate(new_inputs, piece, grid, initial)
piece.das_kicked = false
local rot_dir = 0
if (new_inputs["rotate_left"] or new_inputs["rotate_left2"]) then
rot_dir = 3
elseif (new_inputs["rotate_right"] or new_inputs["rotate_right2"]) then
rot_dir = 1
elseif (new_inputs["rotate_180"]) then
rot_dir = self:get180RotationValue()
end
if rot_dir == 0 then return end
if config.gamesettings.world_reverse == 3 or (self.world and config.gamesettings.world_reverse == 2) then
rot_dir = 4 - rot_dir
end
local new_piece = piece:withRelativeRotation(rot_dir)
if initial then
if grid:canPlacePiece(new_piece) then
piece:setRelativeRotation(rot_dir)
self:onPieceRotate(piece)
end
else
self:attemptWallkicks(piece, new_piece, rot_dir, grid, new_inputs)
end
end
function KRS:attemptWallkicks(piece, new_piece, rot_dir, grid, new_inputs)
local kicks = (
piece.shape == "I" and
KRS.wallkicks_line[piece.rotation][new_piece.rotation] or
KRS.wallkicks_3x3[piece.rotation][new_piece.rotation]
)
local priority = 0
if (
(new_inputs["left"]) or
(
self.game.das.direction == "left" and
(
self.game.das.frames >= self.game:getDasLimit() - self.game:getARR() or
piece:isMoveBlocked(grid, {x=-1, y=0})
)
)
) then
priority = -1
elseif (
(new_inputs["right"]) or
(
self.game.das.direction == "right" and
(
self.game.das.frames >= self.game:getDasLimit() - self.game:getARR() or
piece:isMoveBlocked(grid, {x=1, y=0})
)
)
) then
priority = 1
end
-- base rotation with offset
if grid:canPlacePiece(new_piece:withOffset({x=priority, y=0})) then
piece:setRelativeRotation(rot_dir)
piece:setOffset({x=priority, y=0})
self:onPieceRotate(piece)
piece.das_kicked = true
return
end
-- das kicks
for idx, offset in pairs(kicks) do
kicked_piece = new_piece:withOffset({x=offset[1]+priority, y=offset[2]})
if grid:canPlacePiece(kicked_piece) then
piece:setRelativeRotation(rot_dir)
piece:setOffset({x=offset[1]+priority, y=offset[2]})
self:onPieceRotate(piece)
piece.das_kicked = true
return
end
end
-- base rotation
if grid:canPlacePiece(new_piece) then
piece:setRelativeRotation(rot_dir)
self:onPieceRotate(piece)
return
end
-- regular kicks
for idx, offset in pairs(kicks) do
kicked_piece = new_piece:withOffset({x=offset[1], y=offset[2]})
if grid:canPlacePiece(kicked_piece) then
piece:setRelativeRotation(rot_dir)
piece:setOffset({x=offset[1], y=offset[2]})
self:onPieceRotate(piece)
return
end
end
end
function KRS:get180RotationValue() return 2 end
return KRS

258
tetris/rulesets/pairs.lua Normal file
View File

@ -0,0 +1,258 @@
local Ruleset = require 'tetris.rulesets.ruleset'
local PAIRS = Ruleset:extend()
PAIRS.name = "PAIRS"
PAIRS.hash = "PAIRS"
PAIRS.world = true
PAIRS.spawn_positions = {
[1] = { x=4, y=4 },
[2] = { x=4, y=5 },
[3] = { x=4, y=5 },
[4] = { x=4, y=5 },
[5] = { x=5, y=5 },
[6] = { x=5, y=5 },
[7] = { x=5, y=5 },
[8] = { x=5, y=5 },
[9] = { x=5, y=5 },
[10] = { x=5, y=5 },
[11] = { x=4, y=5 },
[12] = { x=4, y=5 },
[13] = { x=4, y=5 },
[14] = { x=4, y=5 },
[15] = { x=4, y=5 },
[16] = { x=4, y=5 },
[17] = { x=4, y=5 },
[18] = { x=4, y=5 },
}
PAIRS.big_spawn_positions = {
[1] = { x=2, y=2 },
[2] = { x=2, y=3 },
[3] = { x=2, y=3 },
[4] = { x=2, y=3 },
[5] = { x=3, y=3 },
[6] = { x=3, y=3 },
[7] = { x=3, y=3 },
[8] = { x=3, y=3 },
[9] = { x=3, y=3 },
[10] = { x=3, y=3 },
[11] = { x=2, y=3 },
[12] = { x=2, y=3 },
[13] = { x=2, y=3 },
[14] = { x=2, y=3 },
[15] = { x=2, y=3 },
[16] = { x=2, y=3 },
[17] = { x=2, y=3 },
[18] = { x=2, y=3 },
}
PAIRS.next_sounds = {
[1] = "I",
[2] = "O",
[3] = "S",
[4] = "Z",
[5] = "L",
[6] = "J",
[7] = "Z",
[8] = "S",
[9] = "J",
[10] = "L",
[11] = "O",
[12] = "O",
[13] = "T",
[14] = "L",
[15] = "J",
[16] = "T",
[17] = "J",
[18] = "I"
}
PAIRS.colourscheme = {
[1] = "R",
[2] = "C",
[3] = "G",
[4] = "M",
[5] = "O",
[6] = "C",
[7] = "G",
[8] = "M",
[9] = "G",
[10] = "M",
[11] = "Y",
[12] = "B",
[13] = "M",
[14] = "O",
[15] = "B",
[16] = "G",
[17] = "C",
[18] = "R"
}
PAIRS.pieces = 18
PAIRS.block_offsets = {
[1]={
{ {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0}, {x=2, y=0} },
{ {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0}, {x=0, y=1}, {x=0, y=2} },
{ {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0}, {x=2, y=0} },
{ {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0}, {x=0, y=1}, {x=0, y=2} },
},
[2]={
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-1}, {x=-1, y=-1} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-1}, {x=-1, y=-1} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-1}, {x=-1, y=-1} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-1}, {x=-1, y=-1} },
},
[3]={
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-2}, {x=-1, y=0} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=1, y=0}, {x=-1, y=-2} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-2}, {x=-1, y=0} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=1, y=0}, {x=-1, y=-2} },
},
[4]={
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=0}, {x=-1, y=-2} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=0}, {x=1, y=-2} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=0}, {x=-1, y=-2} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=0}, {x=1, y=-2} },
},
[5]={
{ {x=1, y=-1}, {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0} },
{ {x=0, y=0}, {x=-1, y=-3}, {x=-1, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
{ {x=-2, y=0}, {x=-2, y=-1}, {x=-1, y=-1}, {x=0, y=-1}, {x=1, y=-1} },
{ {x=-1, y=-3}, {x=0, y=-3}, {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0} },
},
[6]={
{ {x=-2, y=-1}, {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0} },
{ {x=0, y=-3}, {x=-1, y=-3}, {x=-1, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
{ {x=1, y=0}, {x=-2, y=-1}, {x=-1, y=-1}, {x=0, y=-1}, {x=1, y=-1} },
{ {x=-1, y=0}, {x=0, y=-3}, {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0} },
},
[7]={
{ {x=-2, y=-1}, {x=-1, y=-1}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0} },
{ {x=0, y=-3}, {x=0, y=-2}, {x=-1, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
{ {x=-2, y=-1}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=1, y=0} },
{ {x=-1, y=0}, {x=0, y=-3}, {x=0, y=-2}, {x=0, y=-1}, {x=-1, y=-1} },
},
[8]={
{ {x=1, y=-1}, {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=0, y=-1} },
{ {x=0, y=0}, {x=-1, y=-3}, {x=-1, y=-2}, {x=-1, y=-1}, {x=0, y=-1} },
{ {x=-2, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1}, {x=1, y=-1} },
{ {x=-1, y=-3}, {x=-1, y=-2}, {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0} },
},
[9]={
{ {x=-1, y=-1}, {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0} },
{ {x=0, y=-2}, {x=-1, y=-3}, {x=-1, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
{ {x=0, y=0}, {x=-2, y=-1}, {x=-1, y=-1}, {x=0, y=-1}, {x=1, y=-1} },
{ {x=-1, y=-1}, {x=0, y=-3}, {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0} },
},
[10]={
{ {x=0, y=-1}, {x=-2, y=0}, {x=-1, y=0}, {x=0, y=0}, {x=1, y=0} },
{ {x=0, y=-1}, {x=-1, y=-3}, {x=-1, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
{ {x=-1, y=0}, {x=-2, y=-1}, {x=-1, y=-1}, {x=0, y=-1}, {x=1, y=-1} },
{ {x=-1, y=-2}, {x=0, y=-3}, {x=0, y=-2}, {x=0, y=-1}, {x=0, y=0} },
},
[11]={
{ {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=0, y=-1}, {x=-1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=1, y=-1}, {x=1, y=-2} },
{ {x=0, y=0}, {x=1, y=-1}, {x=1, y=0}, {x=0, y=-1}, {x=-1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=-1, y=-1}, {x=-1, y=0} },
},
[12]={
{ {x=0, y=0}, {x=1, y=-1}, {x=1, y=0}, {x=0, y=-1}, {x=-1, y=0} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=1, y=-1}, {x=1, y=0} },
{ {x=0, y=0}, {x=-1, y=0}, {x=1, y=-1}, {x=0, y=-1}, {x=-1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=-1, y=-1}, {x=-1, y=-2} },
},
[13]={
{ {x=0, y=0}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1}, {x=1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=1, y=0}, {x=1, y=-2} },
{ {x=0, y=-1}, {x=-1, y=0}, {x=1, y=0}, {x=-1, y=-1}, {x=1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=-1, y=0}, {x=-1, y=-2} },
},
[14]={
{ {x=0, y=-1}, {x=0, y=0}, {x=0, y=-2}, {x=-1, y=-1}, {x=1, y=0} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=0, y=-2}, {x=-1, y=0} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-1}, {x=-1, y=-2} },
{ {x=0, y=-1}, {x=1, y=-1}, {x=-1, y=-1}, {x=0, y=0}, {x=1, y=-2} },
},
[15]={
{ {x=0, y=-1}, {x=0, y=0}, {x=0, y=-2}, {x=-1, y=0}, {x=1, y=-1} },
{ {x=0, y=-1}, {x=-1, y=-1}, {x=1, y=-1}, {x=-1, y=-2}, {x=0, y=0} },
{ {x=0, y=-1}, {x=0, y=-2}, {x=0, y=0}, {x=1, y=-2}, {x=-1, y=-1} },
{ {x=0, y=-1}, {x=1, y=-1}, {x=-1, y=-1}, {x=1, y=0}, {x=0, y=-2} },
},
[16]={
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=-1, y=0}, {x=1, y=0} },
{ {x=-1, y=0}, {x=0, y=-1}, {x=-1, y=-2}, {x=-1, y=-1}, {x=1, y=-1} },
{ {x=0, y=0}, {x=0, y=-1}, {x=0, y=-2}, {x=-1, y=-2}, {x=1, y=-2} },
{ {x=1, y=0}, {x=0, y=-1}, {x=1, y=-2}, {x=-1, y=-1}, {x=1, y=-1} },
},
[17]={
{ {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=-1, y=-1}, {x=-1, y=-2} },
{ {x=0, y=-2}, {x=1, y=-2}, {x=-1, y=0}, {x=-1, y=-1}, {x=-1, y=-2} },
{ {x=0, y=-2}, {x=1, y=0}, {x=-1, y=-2}, {x=1, y=-1}, {x=1, y=-2} },
{ {x=0, y=0}, {x=1, y=0}, {x=-1, y=0}, {x=1, y=-1}, {x=1, y=-2} },
},
[18]={
{ {x=1, y=0}, {x=0, y=0}, {x=0, y=-1}, {x=-1, y=-1}, {x=-1, y=-2} },
{ {x=-1, y=0}, {x=-1, y=-1}, {x=0, y=-1}, {x=0, y=-2}, {x=1, y=-2} },
{ {x=-1, y=-2}, {x=0, y=-2}, {x=0, y=-1}, {x=1, y=-1}, {x=1, y=0} },
{ {x=1, y=-2}, {x=1, y=-1}, {x=0, y=-1}, {x=0, y=0}, {x=-1, y=0} },
},
}
PAIRS.wallkicks = {
{x=1, y=0}, {x=-1, y=0}, {x=2, y=0}, {x=-2, y=0}, {x=0, y=-1}
}
function PAIRS:attemptWallkicks(piece, new_piece, rot_dir, grid)
if (piece.shape == 2) then return end
local kicks = PAIRS.wallkicks
assert(piece.rotation ~= new_piece.rotation)
for idx, offset in pairs(kicks) do
kicked_piece = new_piece:withOffset(offset)
if grid:canPlacePiece(kicked_piece) then
self:onPieceRotate(piece, grid)
piece:setRelativeRotation(rot_dir)
piece:setOffset(offset)
return
end
end
end
function PAIRS:checkNewLow(piece)
for _, block in pairs(piece:getBlockOffsets()) do
local y = piece.position.y + block.y
if y > piece.lowest_y then
piece.lock_delay = 0
piece.lowest_y = y
end
end
end
function PAIRS:onPieceCreate(piece, grid)
piece.lowest_y = -math.huge
end
function PAIRS:onPieceDrop(piece, grid)
self:checkNewLow(piece)
end
function PAIRS:get180RotationValue()
return 3
end
function PAIRS:getAboveFieldOffset(shape, orientation)
if shape == 1 then
return 1
else
return 2
end
end
return PAIRS

View File

@ -0,0 +1,37 @@
local SRS = require 'tetris.rulesets.ti_srs'
local TexyWorld = SRS:extend()
TexyWorld.name = "Texy-World"
TexyWorld.hash = "TexyWorld"
function TexyWorld:attemptWallkicks(piece, new_piece, rot_dir, grid)
local kicks
if piece.shape == "O" then
return
elseif piece.shape == "I" then
kicks = SRS.wallkicks_line[piece.rotation][new_piece.rotation]
else
kicks = SRS.wallkicks_3x3[piece.rotation][new_piece.rotation]
end
assert(piece.rotation ~= new_piece.rotation)
for idx, temp_offset in pairs(kicks) do
offset = {
x=temp_offset.x*(rot_dir==3 and -1 or 1),
y=temp_offset.y
}
kicked_piece = new_piece:withOffset(offset)
if grid:canPlacePiece(kicked_piece) then
piece:setRelativeRotation(rot_dir)
piece:setOffset(offset)
self:onPieceRotate(piece, grid, offset.y < 0)
return
end
end
end
return TexyWorld