Allowed gamemode and ruleset objects to control each other
Also added GameMode:onExit(), which triggers on game exit or retrypull/16/head
parent
cb2b693bcb
commit
8a459b68ba
|
@ -7,10 +7,10 @@ require 'load.save'
|
|||
function GameScene:new(game_mode, ruleset, inputs)
|
||||
self.retry_mode = game_mode
|
||||
self.retry_ruleset = ruleset
|
||||
self.secret_inputs = copy(inputs)
|
||||
self.secret_inputs = inputs
|
||||
self.game = game_mode(self.secret_inputs)
|
||||
self.ruleset = ruleset()
|
||||
self.game:initialize(self.ruleset, self.secret_inputs)
|
||||
self.ruleset = ruleset(self.game)
|
||||
self.game:initialize(self.ruleset)
|
||||
self.inputs = {
|
||||
left=false,
|
||||
right=false,
|
||||
|
@ -118,9 +118,11 @@ function GameScene:onInputPress(e)
|
|||
highscore_entry = self.game:getHighscoreData()
|
||||
highscore_hash = self.game.hash .. "-" .. self.ruleset.hash
|
||||
submitHighscore(highscore_hash, highscore_entry)
|
||||
self.game:onExit()
|
||||
scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs) or ModeSelectScene()
|
||||
elseif e.input == "retry" then
|
||||
switchBGM(nil)
|
||||
self.game:onExit()
|
||||
scene = GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs)
|
||||
elseif e.input == "pause" and not (self.game.game_over or self.game.completed) then
|
||||
self.paused = not self.paused
|
||||
|
|
|
@ -95,9 +95,8 @@ function GameMode:getSkin()
|
|||
return "2tie"
|
||||
end
|
||||
|
||||
function GameMode:initialize(ruleset, secret_inputs)
|
||||
function GameMode:initialize(ruleset)
|
||||
-- generate next queue
|
||||
self:new(secret_inputs)
|
||||
self.used_randomizer = (
|
||||
ruleset.pieces == self.randomizer.possible_pieces and
|
||||
self.randomizer or
|
||||
|
@ -107,6 +106,7 @@ function GameMode:initialize(ruleset, secret_inputs)
|
|||
BagRandomizer(ruleset.pieces)
|
||||
)
|
||||
)
|
||||
self.ruleset = ruleset
|
||||
for i = 1, math.max(self.next_queue_length, 1) do
|
||||
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
||||
end
|
||||
|
@ -333,6 +333,8 @@ function GameMode:onGameComplete()
|
|||
self:onGameOver()
|
||||
end
|
||||
|
||||
function GameMode:onExit() end
|
||||
|
||||
-- DAS functions
|
||||
|
||||
function GameMode:startRightDAS()
|
||||
|
|
|
@ -39,8 +39,8 @@ Ruleset.pieces = 7
|
|||
|
||||
-- Component functions.
|
||||
|
||||
function Ruleset:new()
|
||||
|
||||
function Ruleset:new(game_mode)
|
||||
self.game = game_mode
|
||||
if config.gamesettings.piece_colour == 1 then
|
||||
blocks["bone"] = (not self.world) and
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue