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-01-05 20:59:50 -06:00
|
|
|
self.secret_inputs = copy(inputs)
|
|
|
|
self.game = game_mode(self.secret_inputs)
|
2019-05-22 22:57:34 -05:00
|
|
|
self.ruleset = ruleset()
|
2021-01-05 20:59:50 -06:00
|
|
|
self.game:initialize(self.ruleset, self.secret_inputs)
|
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
|
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,
|
|
|
|
})
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
function GameScene:update()
|
2020-12-20 14:08:53 -06:00
|
|
|
if love.window.hasFocus() and not self.paused then
|
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()
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function GameScene:render()
|
|
|
|
love.graphics.setColor(1, 1, 1, 1)
|
|
|
|
love.graphics.draw(
|
|
|
|
backgrounds[self.game:getBackground()],
|
|
|
|
0, 0, 0,
|
|
|
|
0.5, 0.5
|
|
|
|
)
|
|
|
|
|
|
|
|
-- game frame
|
2021-01-11 14:52:11 -06:00
|
|
|
if self.game.grid.width == 10 and self.game.grid.height == 24 then
|
2021-01-11 14:17:32 -06:00
|
|
|
love.graphics.draw(misc_graphics["frame"], 48, 64)
|
|
|
|
end
|
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
love.graphics.setColor(0, 0, 0, 200)
|
2021-01-11 14:46:43 -06:00
|
|
|
love.graphics.rectangle(
|
|
|
|
"fill", 64, 80,
|
|
|
|
16 * self.game.grid.width, 16 * (self.game.grid.height - 4)
|
|
|
|
)
|
2021-01-10 21:40:13 -06:00
|
|
|
|
2021-01-11 21:40:48 -06:00
|
|
|
if self.game.grid.width ~= 10 or self.game.grid.height ~= 24 then
|
2021-01-11 14:17:32 -06:00
|
|
|
love.graphics.setColor(174/255, 83/255, 76/255, 1)
|
|
|
|
love.graphics.setLineWidth(8)
|
|
|
|
love.graphics.line(
|
|
|
|
60,76,
|
|
|
|
68+16*self.game.grid.width,76,
|
2021-01-11 14:46:43 -06:00
|
|
|
68+16*self.game.grid.width,84+16*(self.game.grid.height-4),
|
|
|
|
60,84+16*(self.game.grid.height-4),
|
2021-01-11 14:17:32 -06:00
|
|
|
60,76
|
|
|
|
)
|
|
|
|
love.graphics.setColor(203/255, 137/255, 111/255, 1)
|
|
|
|
love.graphics.setLineWidth(4)
|
|
|
|
love.graphics.line(
|
|
|
|
60,76,
|
|
|
|
68+16*self.game.grid.width,76,
|
2021-01-11 14:46:43 -06:00
|
|
|
68+16*self.game.grid.width,84+16*(self.game.grid.height-4),
|
|
|
|
60,84+16*(self.game.grid.height-4),
|
2021-01-11 14:17:32 -06:00
|
|
|
60,76
|
|
|
|
)
|
2021-01-12 13:32:10 -06:00
|
|
|
love.graphics.setLineWidth(1)
|
2021-01-11 14:17:32 -06:00
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
|
|
|
|
self.game:drawGrid()
|
|
|
|
self.game:drawPiece()
|
|
|
|
self.game:drawNextQueue(self.ruleset)
|
|
|
|
self.game:drawScoringInfo()
|
|
|
|
|
|
|
|
-- ready/go graphics
|
2020-10-27 06:17:00 -05:00
|
|
|
|
2019-05-22 22:57:34 -05:00
|
|
|
if self.game.ready_frames <= 100 and self.game.ready_frames > 52 then
|
|
|
|
love.graphics.draw(misc_graphics["ready"], 144 - 50, 240 - 14)
|
|
|
|
elseif self.game.ready_frames <= 50 and self.game.ready_frames > 2 then
|
|
|
|
love.graphics.draw(misc_graphics["go"], 144 - 27, 240 - 14)
|
|
|
|
end
|
|
|
|
|
|
|
|
self.game:drawCustom()
|
|
|
|
|
2020-12-16 21:21:26 -06:00
|
|
|
love.graphics.setFont(font_3x5_2)
|
|
|
|
if config.gamesettings.display_gamemode == 1 then
|
|
|
|
love.graphics.printf(self.game.name .. " - " .. self.ruleset.name, 0, 460, 640, "left")
|
|
|
|
end
|
2020-12-20 14:08:53 -06:00
|
|
|
|
|
|
|
love.graphics.setFont(font_3x5_3)
|
|
|
|
if self.paused then love.graphics.print("PAUSED!", 80, 100) end
|
2021-01-14 20:51:47 -06:00
|
|
|
|
|
|
|
if self.game.completed then
|
|
|
|
self.game:onGameComplete()
|
|
|
|
elseif self.game.game_over then
|
|
|
|
self.game:onGameOver()
|
|
|
|
end
|
2019-05-22 22:57:34 -05:00
|
|
|
end
|
|
|
|
|
2020-11-08 14:55:06 -06:00
|
|
|
function GameScene:onInputPress(e)
|
2021-01-24 13:55:35 -06: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-01-05 20:59:50 -06: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-01-05 20:59:50 -06: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
|
2020-12-20 15:55:34 -06:00
|
|
|
if self.paused then pauseBGM()
|
|
|
|
else resumeBGM() end
|
2020-11-08 15:19:01 -06:00
|
|
|
elseif e.input == "menu_back" then
|
2020-11-06 19:49:44 -06: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
|