mirror of
https://github.com/SashLilac/cambridge.git
synced 2024-11-22 17:19:02 -06:00
Allowed gamemode and ruleset objects to control each other
Also added GameMode:onExit(), which triggers on game exit or retry
This commit is contained in:
parent
cb2b693bcb
commit
8a459b68ba
@ -7,10 +7,10 @@ require 'load.save'
|
|||||||
function GameScene:new(game_mode, ruleset, inputs)
|
function GameScene:new(game_mode, ruleset, inputs)
|
||||||
self.retry_mode = game_mode
|
self.retry_mode = game_mode
|
||||||
self.retry_ruleset = ruleset
|
self.retry_ruleset = ruleset
|
||||||
self.secret_inputs = copy(inputs)
|
self.secret_inputs = inputs
|
||||||
self.game = game_mode(self.secret_inputs)
|
self.game = game_mode(self.secret_inputs)
|
||||||
self.ruleset = ruleset()
|
self.ruleset = ruleset(self.game)
|
||||||
self.game:initialize(self.ruleset, self.secret_inputs)
|
self.game:initialize(self.ruleset)
|
||||||
self.inputs = {
|
self.inputs = {
|
||||||
left=false,
|
left=false,
|
||||||
right=false,
|
right=false,
|
||||||
@ -118,9 +118,11 @@ function GameScene:onInputPress(e)
|
|||||||
highscore_entry = self.game:getHighscoreData()
|
highscore_entry = self.game:getHighscoreData()
|
||||||
highscore_hash = self.game.hash .. "-" .. self.ruleset.hash
|
highscore_hash = self.game.hash .. "-" .. self.ruleset.hash
|
||||||
submitHighscore(highscore_hash, highscore_entry)
|
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()
|
scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs) or ModeSelectScene()
|
||||||
elseif e.input == "retry" then
|
elseif e.input == "retry" then
|
||||||
switchBGM(nil)
|
switchBGM(nil)
|
||||||
|
self.game:onExit()
|
||||||
scene = GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs)
|
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
|
elseif e.input == "pause" and not (self.game.game_over or self.game.completed) then
|
||||||
self.paused = not self.paused
|
self.paused = not self.paused
|
||||||
|
@ -95,9 +95,8 @@ function GameMode:getSkin()
|
|||||||
return "2tie"
|
return "2tie"
|
||||||
end
|
end
|
||||||
|
|
||||||
function GameMode:initialize(ruleset, secret_inputs)
|
function GameMode:initialize(ruleset)
|
||||||
-- generate next queue
|
-- generate next queue
|
||||||
self:new(secret_inputs)
|
|
||||||
self.used_randomizer = (
|
self.used_randomizer = (
|
||||||
ruleset.pieces == self.randomizer.possible_pieces and
|
ruleset.pieces == self.randomizer.possible_pieces and
|
||||||
self.randomizer or
|
self.randomizer or
|
||||||
@ -107,6 +106,7 @@ function GameMode:initialize(ruleset, secret_inputs)
|
|||||||
BagRandomizer(ruleset.pieces)
|
BagRandomizer(ruleset.pieces)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
self.ruleset = ruleset
|
||||||
for i = 1, math.max(self.next_queue_length, 1) do
|
for i = 1, math.max(self.next_queue_length, 1) do
|
||||||
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
table.insert(self.next_queue, self:getNextPiece(ruleset))
|
||||||
end
|
end
|
||||||
@ -333,6 +333,8 @@ function GameMode:onGameComplete()
|
|||||||
self:onGameOver()
|
self:onGameOver()
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function GameMode:onExit() end
|
||||||
|
|
||||||
-- DAS functions
|
-- DAS functions
|
||||||
|
|
||||||
function GameMode:startRightDAS()
|
function GameMode:startRightDAS()
|
||||||
|
@ -39,8 +39,8 @@ Ruleset.pieces = 7
|
|||||||
|
|
||||||
-- Component functions.
|
-- Component functions.
|
||||||
|
|
||||||
function Ruleset:new()
|
function Ruleset:new(game_mode)
|
||||||
|
self.game = game_mode
|
||||||
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