From 5606251ea7b33596166a0a211f33477d83077289 Mon Sep 17 00:00:00 2001 From: Oshisaure Date: Thu, 8 Oct 2020 04:56:46 +0100 Subject: [PATCH] Added extra buttons: - Implemented retry button* - Escape on mode select sends you to title screen - Escape on title screen closes the game - Added "Exit Game" entry on title screen, closes the game when selected *Pardon my angry comment in `scene/game.lua`. --- scene.lua | 1 + scene/exit.lua | 23 +++++++++++++++++++++++ scene/game.lua | 12 +++++++++++- scene/input_config.lua | 1 + scene/mode_select.lua | 2 ++ scene/title.lua | 3 +++ tetris/modes/big_a2.lua | 2 +- tetris/modes/gamemode.lua | 1 + 8 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 scene/exit.lua diff --git a/scene.lua b/scene.lua index 8711e1b..14a67b2 100644 --- a/scene.lua +++ b/scene.lua @@ -7,6 +7,7 @@ function Scene:update() end function Scene:render() end function Scene:onKeyPress() end +ExitScene = require "scene.exit" GameScene = require "scene.game" ModeSelectScene = require "scene.mode_select" InputConfigScene = require "scene.input_config" diff --git a/scene/exit.lua b/scene/exit.lua new file mode 100644 index 0000000..3ae1c55 --- /dev/null +++ b/scene/exit.lua @@ -0,0 +1,23 @@ +local ExitScene = Scene:extend() +require 'load.save' + +ExitScene.title = "Exit Game" + +function ExitScene:new() +end + +function ExitScene:update() + love.event.quit() +end + +function ExitScene:render() +end + +function ExitScene:changeOption(rel) +end + +function ExitScene:onKeyPress(e) +end + +return ExitScene + diff --git a/scene/game.lua b/scene/game.lua index 2df6660..6aaffd9 100644 --- a/scene/game.lua +++ b/scene/game.lua @@ -57,11 +57,21 @@ end function GameScene:onKeyPress(e) if (self.game.completed) and - e.scancode == "return" and e.isRepeat == false then + (e.scancode == "return" or e.scancode == "escape") and e.isRepeat == false then highscore_entry = self.game:getHighscoreData() highscore_hash = self.game.hash .. "-" .. self.ruleset.hash submitHighscore(highscore_hash, highscore_entry) scene = ModeSelectScene() + elseif (e.scancode == config.input.retry) then + -- fuck this, this is hacky but the way this codebase is setup prevents anything else + -- it seems like all the values that get touched in the child gamemode class + -- stop being linked to the values of the GameMode superclass because of how `mt.__index` works + -- not even sure this is the actual problem, but I don't want to have to rebuild everything about + -- the core organisation of everything. this hacky way will have to do until someone figures out something. + love.keypressed("escape", "escape", false) + love.keypressed("return", "return", false) + elseif e.scancode == "escape" then + scene = ModeSelectScene() end end diff --git a/scene/input_config.lua b/scene/input_config.lua index d232750..19d8e68 100644 --- a/scene/input_config.lua +++ b/scene/input_config.lua @@ -15,6 +15,7 @@ local configurable_inputs = { "rotate_right2", "rotate_180", "hold", + "retry", } function ConfigScene:new() diff --git a/scene/mode_select.lua b/scene/mode_select.lua index ac296f8..de8ab2c 100755 --- a/scene/mode_select.lua +++ b/scene/mode_select.lua @@ -100,6 +100,8 @@ function ModeSelectScene:onKeyPress(e) elseif (e.scancode == config.input["left"] or e.scancode == "left") or (e.scancode == config.input["right"] or e.scancode == "right") then self:switchSelect() + elseif e.scancode == "escape" then + scene = TitleScene() end end diff --git a/scene/title.lua b/scene/title.lua index f2a7514..0908a80 100644 --- a/scene/title.lua +++ b/scene/title.lua @@ -3,6 +3,7 @@ local TitleScene = Scene:extend() local main_menu_screens = { ModeSelectScene, InputConfigScene, + ExitScene, } function TitleScene:new() @@ -43,6 +44,8 @@ function TitleScene:onKeyPress(e) self:changeOption(-1) elseif (e.scancode == config.input["down"] or e.scancode == "down") and e.isRepeat == false then self:changeOption(1) + elseif e.scancode == "escape" and e.isRepeat == false then + love.event.quit() end end diff --git a/tetris/modes/big_a2.lua b/tetris/modes/big_a2.lua index 193ceb7..3d69caf 100755 --- a/tetris/modes/big_a2.lua +++ b/tetris/modes/big_a2.lua @@ -15,7 +15,7 @@ MarathonA2Game.tagline = "The points don't matter! Can you reach the invisible r function MarathonA2Game:new() - MarathonA2Game.super:new() + self.super:new() self.big_mode = true self.roll_frames = 0 self.combo = 1 diff --git a/tetris/modes/gamemode.lua b/tetris/modes/gamemode.lua index 68dc917..4cc3a30 100644 --- a/tetris/modes/gamemode.lua +++ b/tetris/modes/gamemode.lua @@ -68,6 +68,7 @@ end function GameMode:initialize(ruleset) -- generate next queue + self:new() for i = 1, self.next_queue_length do table.insert(self.next_queue, self:getNextPiece(ruleset)) end