mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 17:59:01 -06:00
Ruleset and randomizer refactoring (Read comments)
You can now specify an arbitrary number of pieces for a ruleset. The randomizers will adjust accordingly. Expect a pento ruleset in the modpack soon! Also, gamemode skin selection has been refactored.
This commit is contained in:
parent
ced40297cc
commit
1fdd091456
@ -72,14 +72,21 @@ function GameMode:getLineClearDelay() return 40 end
|
|||||||
function GameMode:getDasLimit() return 15 end
|
function GameMode:getDasLimit() return 15 end
|
||||||
|
|
||||||
function GameMode:getNextPiece(ruleset)
|
function GameMode:getNextPiece(ruleset)
|
||||||
|
|
||||||
return {
|
return {
|
||||||
skin = "2tie",
|
skin = self:getSkin(),
|
||||||
shape = self.randomizer:nextPiece(),
|
shape = (
|
||||||
|
ruleset.pieces == self.randomizer.possible_pieces and
|
||||||
|
self.randomizer:nextPiece() or
|
||||||
|
ruleset.fallback_randomizer:nextPiece()
|
||||||
|
),
|
||||||
orientation = ruleset:getDefaultOrientation(),
|
orientation = ruleset:getDefaultOrientation(),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function GameMode:getSkin()
|
||||||
|
return "2tie"
|
||||||
|
end
|
||||||
|
|
||||||
function GameMode:initialize(ruleset, secret_inputs)
|
function GameMode:initialize(ruleset, secret_inputs)
|
||||||
-- generate next queue
|
-- generate next queue
|
||||||
self:new(secret_inputs)
|
self:new(secret_inputs)
|
||||||
@ -445,11 +452,11 @@ function GameMode:initializeNextPiece(inputs, ruleset, piece_data, generate_next
|
|||||||
table.remove(self.next_queue, 1)
|
table.remove(self.next_queue, 1)
|
||||||
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
||||||
end
|
end
|
||||||
self:playNextSound()
|
self:playNextSound(ruleset)
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:playNextSound()
|
function GameMode:playNextSound(ruleset)
|
||||||
playSE("blocks", self.next_queue[1].shape)
|
playSE("blocks", ruleset.next_sounds[self.next_queue[1].shape])
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:getHighScoreData()
|
function GameMode:getHighScoreData()
|
||||||
|
@ -86,12 +86,8 @@ function PhantomMania2Game:getGarbageLimit()
|
|||||||
else return 8 end
|
else return 8 end
|
||||||
end
|
end
|
||||||
|
|
||||||
function PhantomMania2Game:getNextPiece(ruleset)
|
function PhantomMania2Game:getSkin()
|
||||||
return {
|
return self.level >= 1000 and "bone" or "2tie"
|
||||||
skin = self.level >= 1000 and "bone" or "2tie",
|
|
||||||
shape = self.randomizer:nextPiece(),
|
|
||||||
orientation = ruleset:getDefaultOrientation(),
|
|
||||||
}
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function PhantomMania2Game:hitTorikan(old_level, new_level)
|
function PhantomMania2Game:hitTorikan(old_level, new_level)
|
||||||
|
23
tetris/randomizers/bag.lua
Normal file
23
tetris/randomizers/bag.lua
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
local Randomizer = require 'tetris.randomizers.randomizer'
|
||||||
|
|
||||||
|
local BagRandomizer = Randomizer:extend()
|
||||||
|
|
||||||
|
function BagRandomizer:new(pieces)
|
||||||
|
self.bag = {}
|
||||||
|
self.pieces = pieces
|
||||||
|
for i = 1, self.pieces do
|
||||||
|
table.insert(self.bag, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function BagRandomizer:generatePiece()
|
||||||
|
if next(self.bag) == nil then
|
||||||
|
for i = 1, self.pieces do
|
||||||
|
table.insert(self.bag, i)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local x = math.random(table.getn(self.bag))
|
||||||
|
return table.remove(self.bag, x)
|
||||||
|
end
|
||||||
|
|
||||||
|
return BagRandomizer
|
@ -3,6 +3,7 @@ local Object = require 'libs.classic'
|
|||||||
local Randomizer = Object:extend()
|
local Randomizer = Object:extend()
|
||||||
|
|
||||||
function Randomizer:new()
|
function Randomizer:new()
|
||||||
|
self.possible_pieces = 7
|
||||||
self:initialize()
|
self:initialize()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
local Object = require 'libs.classic'
|
local Object = require 'libs.classic'
|
||||||
local Piece = require 'tetris.components.piece'
|
local Piece = require 'tetris.components.piece'
|
||||||
|
local Bag7Randomizer = require "tetris.randomizers.bag7"
|
||||||
|
|
||||||
local Ruleset = Object:extend()
|
local Ruleset = Object:extend()
|
||||||
|
|
||||||
@ -22,10 +23,24 @@ Ruleset.harddrop_lock = false
|
|||||||
|
|
||||||
Ruleset.enable_IRS_wallkicks = false
|
Ruleset.enable_IRS_wallkicks = false
|
||||||
Ruleset.are_cancel = false
|
Ruleset.are_cancel = false
|
||||||
|
Ruleset.fallback_randomizer = Bag7Randomizer()
|
||||||
|
|
||||||
|
Ruleset.next_sounds = {
|
||||||
|
I = "I",
|
||||||
|
L = "L",
|
||||||
|
J = "J",
|
||||||
|
S = "S",
|
||||||
|
Z = "Z",
|
||||||
|
O = "O",
|
||||||
|
T = "T"
|
||||||
|
}
|
||||||
|
|
||||||
|
Ruleset.pieces = 7
|
||||||
|
|
||||||
-- Component functions.
|
-- Component functions.
|
||||||
|
|
||||||
function Ruleset:new()
|
function Ruleset:new()
|
||||||
|
|
||||||
if config.gamesettings.piece_colour == 1 then
|
if config.gamesettings.piece_colour == 1 then
|
||||||
blocks["bone"] = (not self.world) and
|
blocks["bone"] = (not self.world) and
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user