mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 07:49:02 -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:getNextPiece(ruleset)
|
||||
|
||||
return {
|
||||
skin = "2tie",
|
||||
shape = self.randomizer:nextPiece(),
|
||||
skin = self:getSkin(),
|
||||
shape = (
|
||||
ruleset.pieces == self.randomizer.possible_pieces and
|
||||
self.randomizer:nextPiece() or
|
||||
ruleset.fallback_randomizer:nextPiece()
|
||||
),
|
||||
orientation = ruleset:getDefaultOrientation(),
|
||||
}
|
||||
end
|
||||
|
||||
function GameMode:getSkin()
|
||||
return "2tie"
|
||||
end
|
||||
|
||||
function GameMode:initialize(ruleset, secret_inputs)
|
||||
-- generate next queue
|
||||
self:new(secret_inputs)
|
||||
@ -445,11 +452,11 @@ function GameMode:initializeNextPiece(inputs, ruleset, piece_data, generate_next
|
||||
table.remove(self.next_queue, 1)
|
||||
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
||||
end
|
||||
self:playNextSound()
|
||||
self:playNextSound(ruleset)
|
||||
end
|
||||
|
||||
function GameMode:playNextSound()
|
||||
playSE("blocks", self.next_queue[1].shape)
|
||||
function GameMode:playNextSound(ruleset)
|
||||
playSE("blocks", ruleset.next_sounds[self.next_queue[1].shape])
|
||||
end
|
||||
|
||||
function GameMode:getHighScoreData()
|
||||
|
@ -86,12 +86,8 @@ function PhantomMania2Game:getGarbageLimit()
|
||||
else return 8 end
|
||||
end
|
||||
|
||||
function PhantomMania2Game:getNextPiece(ruleset)
|
||||
return {
|
||||
skin = self.level >= 1000 and "bone" or "2tie",
|
||||
shape = self.randomizer:nextPiece(),
|
||||
orientation = ruleset:getDefaultOrientation(),
|
||||
}
|
||||
function PhantomMania2Game:getSkin()
|
||||
return self.level >= 1000 and "bone" or "2tie"
|
||||
end
|
||||
|
||||
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()
|
||||
|
||||
function Randomizer:new()
|
||||
self.possible_pieces = 7
|
||||
self:initialize()
|
||||
end
|
||||
|
||||
|
@ -1,5 +1,6 @@
|
||||
local Object = require 'libs.classic'
|
||||
local Piece = require 'tetris.components.piece'
|
||||
local Bag7Randomizer = require "tetris.randomizers.bag7"
|
||||
|
||||
local Ruleset = Object:extend()
|
||||
|
||||
@ -22,10 +23,24 @@ Ruleset.harddrop_lock = false
|
||||
|
||||
Ruleset.enable_IRS_wallkicks = 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.
|
||||
|
||||
function Ruleset:new()
|
||||
|
||||
if config.gamesettings.piece_colour == 1 then
|
||||
blocks["bone"] = (not self.world) and
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user