diff --git a/scene/game.lua b/scene/game.lua index 83d3a5f..7200c90 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -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 diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index f54a68f..2ef3208 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -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() diff --git a/tetris/rulesets/ruleset.lua b/tetris/rulesets/ruleset.lua index 3eb109e..1f3cbaa 100644 --- a/tetris/rulesets/ruleset.lua +++ b/tetris/rulesets/ruleset.lua @@ -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 {