2019-05-22 22:57:34 -05:00
|
|
|
local GameScene = Scene:extend()
|
2020-11-10 16:37:59 -06:00
|
|
|
|
|
|
|
GameScene.title = "Game"
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
require 'load.save'
|
|
|
|
|
2021-01-05 20:59:50 -06:00
|
|
|
function GameScene:new(game_mode, ruleset, inputs)
|
2020-11-08 15:19:01 -06:00
|
|
|
self.retry_mode = game_mode
|
|
|
|
self.retry_ruleset = ruleset
|
2021-02-19 10:01:18 -06:00
|
|
|
self.secret_inputs = inputs
|
2021-01-05 20:59:50 -06:00
|
|
|
self.game = game_mode(self.secret_inputs)
|
2021-12-09 22:00:20 -06:00
|
|
|
self.game.secret_inputs = inputs
|
2021-02-19 10:01:18 -06:00
|
|
|
self.ruleset = ruleset(self.game)
|
|
|
|
self.game:initialize(self.ruleset)
|
2020-11-08 15:19:01 -06:00
|
|
|
self.inputs = {
|
|
|
|
left=false,
|
|
|
|
right=false,
|
|
|
|
up=false,
|
|
|
|
down=false,
|
|
|
|
rotate_left=false,
|
|
|
|
rotate_left2=false,
|
|
|
|
rotate_right=false,
|
|
|
|
rotate_right2=false,
|
|
|
|
rotate_180=false,
|
|
|
|
hold=false,
|
|
|
|
}
|
2020-12-20 14:08:53 -06:00
|
|
|
self.paused = false
|
2023-06-24 09:46:38 -05:00
|
|
|
self.game.pause_count = 0
|
|
|
|
self.game.pause_time = 0
|
2020-10-10 20:17:48 -05:00
|
|
|
DiscordRPC:update({
|
2020-11-06 19:49:44 -06:00
|
|
|
details = self.game.rpc_details,
|
|
|
|
state = self.game.name,
|
2021-09-25 23:02:35 -05:00
|
|
|
largeImageKey = "ingame-"..self.game:getBackground().."00"
|
2020-11-06 19:49:44 -06:00
|
|
|
})
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameScene:update()
|
2023-06-24 09:46:38 -05:00
|
|
|
if self.paused then
|
|
|
|
self.game.pause_time = self.game.pause_time + 1
|
|
|
|
else
|
2020-11-08 15:19:01 -06:00
|
|
|
local inputs = {}
|
|
|
|
for input, value in pairs(self.inputs) do
|
|
|
|
inputs[input] = value
|
|
|
|
end
|
2020-11-08 14:55:06 -06:00
|
|
|
self.game:update(inputs, self.ruleset)
|
2020-12-21 15:20:25 -06:00
|
|
|
self.game.grid:update()
|
2021-09-25 23:02:35 -05:00
|
|
|
DiscordRPC:update({
|
2021-12-09 20:51:41 -06:00
|
|
|
details = self.game.rpc_details,
|
|
|
|
state = self.game.name,
|
2021-09-25 23:02:35 -05:00
|
|
|
largeImageKey = "ingame-"..self.game:getBackground().."00"
|
|
|
|
})
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameScene:render()
|
2021-07-11 13:04:22 -05:00
|
|
|
self.game:draw(self.paused)
|
2023-06-24 09:46:38 -05:00
|
|
|
if self.game.pause_time > 0 or self.game.pause_count > 0 then
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.setFont(font_3x5_2)
|
|
|
|
love.graphics.printf(string.format(
|
|
|
|
"%d PAUSE%s (%s)",
|
|
|
|
self.game.pause_count,
|
|
|
|
self.game.pause_count == 1 and "" or "S",
|
|
|
|
formatTime(self.game.pause_time)
|
|
|
|
), 0, 0, 635, "right")
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2020-11-08 14:55:06 -06:00
|
|
|
function GameScene:onInputPress(e)
|
2021-07-11 13:04:22 -05:00
|
|
|
if (
|
|
|
|
self.game.game_over or self.game.completed
|
|
|
|
) and (
|
|
|
|
e.input == "menu_decide" or
|
|
|
|
e.input == "menu_back" or
|
|
|
|
e.input == "retry"
|
|
|
|
) then
|
2019-05-22 22:57:34 -05:00
|
|
|
highscore_entry = self.game:getHighscoreData()
|
|
|
|
highscore_hash = self.game.hash .. "-" .. self.ruleset.hash
|
|
|
|
submitHighscore(highscore_hash, highscore_entry)
|
2021-02-19 10:01:18 -06:00
|
|
|
self.game:onExit()
|
2022-04-01 17:43:35 -05:00
|
|
|
scene = e.input == "retry" and GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs) or ModeSelectScene()
|
2020-11-08 15:19:01 -06:00
|
|
|
elseif e.input == "retry" then
|
2021-01-16 08:34:41 -06:00
|
|
|
switchBGM(nil)
|
2021-02-19 10:01:18 -06:00
|
|
|
self.game:onExit()
|
2022-04-01 17:43:35 -05:00
|
|
|
scene = GameScene(self.retry_mode, self.retry_ruleset, self.secret_inputs)
|
2020-12-20 14:08:53 -06:00
|
|
|
elseif e.input == "pause" and not (self.game.game_over or self.game.completed) then
|
|
|
|
self.paused = not self.paused
|
2023-06-24 09:46:38 -05:00
|
|
|
if self.paused then
|
|
|
|
pauseBGM()
|
|
|
|
self.game.pause_count = self.game.pause_count + 1
|
|
|
|
else
|
|
|
|
resumeBGM()
|
|
|
|
end
|
2020-11-08 15:19:01 -06:00
|
|
|
elseif e.input == "menu_back" then
|
2021-02-19 14:58:00 -06:00
|
|
|
self.game:onExit()
|
2022-04-01 17:43:35 -05:00
|
|
|
scene = ModeSelectScene()
|
2020-11-08 15:19:01 -06:00
|
|
|
elseif e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
|
|
|
self.inputs[e.input] = true
|
|
|
|
end
|
2020-11-08 14:55:06 -06:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameScene:onInputRelease(e)
|
2020-11-08 15:19:01 -06:00
|
|
|
if e.input and string.sub(e.input, 1, 5) ~= "menu_" then
|
|
|
|
self.inputs[e.input] = false
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function submitHighscore(hash, data)
|
|
|
|
if not highscores[hash] then highscores[hash] = {} end
|
|
|
|
table.insert(highscores[hash], data)
|
|
|
|
saveHighscores()
|
|
|
|
end
|
|
|
|
|
|
|
|
return GameScene
|