From 706468dad6514d9ba0c6965730992f82bdae5ad0 Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 18 Apr 2021 19:09:01 +0200 Subject: [PATCH] feat: add initial difficulty system Fixes #87 --- .../game/abstractmobs/character.lua | 3 ++ sonic-radiance.love/game/difficulty.lua | 29 ++++++++++++++ sonic-radiance.love/game/init.lua | 4 ++ .../scenes/menus/options/init.lua | 11 ++++++ .../scenes/menus/options/menu.lua | 2 +- .../scenes/menus/options/widgets.lua | 38 +++++++++++++++++++ 6 files changed, 86 insertions(+), 1 deletion(-) create mode 100644 sonic-radiance.love/game/difficulty.lua diff --git a/sonic-radiance.love/game/abstractmobs/character.lua b/sonic-radiance.love/game/abstractmobs/character.lua index 3ede7ee..a8073df 100644 --- a/sonic-radiance.love/game/abstractmobs/character.lua +++ b/sonic-radiance.love/game/abstractmobs/character.lua @@ -86,6 +86,9 @@ function AbstractCharacter:setLevel(newlevel) end function AbstractCharacter:levelUp() + if (game.difficulty:get("levelUpHeal")) then + self:heal() + end self:setLevel(self.level + 1) end diff --git a/sonic-radiance.love/game/difficulty.lua b/sonic-radiance.love/game/difficulty.lua new file mode 100644 index 0000000..7d64639 --- /dev/null +++ b/sonic-radiance.love/game/difficulty.lua @@ -0,0 +1,29 @@ +local Difficulty = Object:extend() + +function Difficulty:new() + self.toggles = {} + self.toggles.hazardMakesKo = false + self.toggles.playerKoChar = true + self.toggles.easierBattles = false + self.toggles.checkPointRegen = false + self.toggles.levelUpHeal = false + self.toggles.allDamage = true +end + +function Difficulty:toggle(toggleName) + self.toggles[toggleName] = (self.toggles[toggleName] == false) +end + +function Difficulty:get(toggleName) + return self.toggles[toggleName] +end + +function Difficulty:getData() + return self.toggles +end + +function Difficulty:setData(toggles) + self.toggles = toggles +end + +return Difficulty \ No newline at end of file diff --git a/sonic-radiance.love/game/init.lua b/sonic-radiance.love/game/init.lua index 08dd3af..a8dd901 100644 --- a/sonic-radiance.love/game/init.lua +++ b/sonic-radiance.love/game/init.lua @@ -29,6 +29,7 @@ local Ennemies = require "game.ennemies" local Skills = require "game.skills" local Loot = require "game.loot" local CBSCore = require "game.battle" +local Difficulty = require "game.difficulty" local binser = require "core.modules.gamesystem.libs.binser" @@ -61,6 +62,7 @@ function Game:setData(data) self.actions = data.actions self.characters:setData(data.characters) self.loot:setData(data.loot) + self.difficulty:setData(data.difficulty) end function Game:getData() @@ -68,6 +70,7 @@ function Game:getData() data.gametime = self.gametime data.characters = self.characters:getData() data.loot = self.loot:getData() + data.difficulty = self.difficulty:getData() data.flags = self.flags data.destroyedGizmo = self.destroyedGizmo data.variables = self.variables @@ -143,6 +146,7 @@ function Game:resetData() self.skills = Skills(self) self.loot = Loot(self) self.cbs = CBSCore(self) + self.difficulty = Difficulty(self) self:initPosition() diff --git a/sonic-radiance.love/scenes/menus/options/init.lua b/sonic-radiance.love/scenes/menus/options/init.lua index 197e50c..a13d03c 100644 --- a/sonic-radiance.love/scenes/menus/options/init.lua +++ b/sonic-radiance.love/scenes/menus/options/init.lua @@ -16,6 +16,7 @@ function OptionsMenu:new() self:addSubMenu("audio", "Audio") --self:addSubMenu("langs", "langs") self:addSubMenu("inputs", "Inputs") + self:addSubMenu("difficulty", "Difficulty") Widgets.Resolution(self, "video") Widgets.Switch(self, "video", "fullscreen", "Fullscreen") @@ -23,6 +24,7 @@ function OptionsMenu:new() Widgets.Switch(self, "video", "vsync", "Vsync") self:addPlayerMenus() + self:addDifficultyMenu() --self:setLanguageMenu() @@ -61,6 +63,15 @@ function OptionsMenu:addSubMenu(name, fullname) self.menusystem.menus["main"]:addSubMenu(name, fullname) end +function OptionsMenu:addDifficultyMenu() + Widgets.DiffSwitch(self, "difficulty", "hazardMakesKo", "Hazards can make KO") + Widgets.DiffSwitch(self, "difficulty", "playerKoChar", "Play KO characters on maps") + Widgets.DiffSwitch(self, "difficulty", "easierBattles", "Easier battles") + Widgets.DiffSwitch(self, "difficulty", "checkPointRegen", "Checkpoints heal you") + Widgets.DiffSwitch(self, "difficulty", "levelUpHeal", "Gaining a level heal") + Widgets.DiffSwitch(self, "difficulty", "allDamage", "Hazards damage everybody") +end + function OptionsMenu:addPlayerMenus() for i,v in ipairs(core.input.data) do diff --git a/sonic-radiance.love/scenes/menus/options/menu.lua b/sonic-radiance.love/scenes/menus/options/menu.lua index 5bd7a85..1ec8937 100644 --- a/sonic-radiance.love/scenes/menus/options/menu.lua +++ b/sonic-radiance.love/scenes/menus/options/menu.lua @@ -1,7 +1,7 @@ local RadianceListMenu = require "game.modules.menus.list" local OptionMenu = RadianceListMenu.ListMenu:extend() -local WIDTH = 128+32 +local WIDTH = 128+108 local ITEMNUMBER = 6 function OptionMenu:new(scene, name) diff --git a/sonic-radiance.love/scenes/menus/options/widgets.lua b/sonic-radiance.love/scenes/menus/options/widgets.lua index 283c931..611b38c 100644 --- a/sonic-radiance.love/scenes/menus/options/widgets.lua +++ b/sonic-radiance.love/scenes/menus/options/widgets.lua @@ -15,6 +15,7 @@ widgets.PlayerSubMenu = RadianceListMenu.DualTextWidget:extend() widgets.Key = RadianceListMenu.DualTextWidget:extend() widgets.Audio = RadianceListMenu.DualTextWidget:extend() widgets.Delete = RadianceListMenu.DualTextWidget:extend() +widgets.DiffSwitch = RadianceListMenu.DualTextWidget:extend() local defTransitions = require "core.modules.transitions" local ConfirmDialog = require "game.modules.confirmdialog" @@ -259,4 +260,41 @@ function widgets.Audio:action() core.options:write() end +-- Switch widget (One widget to handle graphical switch) + +function widgets.DiffSwitch:new(scene, menu, keyname, label) + self.keyname = keyname + local label2 = self:getLabel() + widgets.Switch.super.new(self, scene, menu, label, label2) + self.order = 0 +end + +function widgets.DiffSwitch:modifyKey() + game.difficulty:toggle(self.keyname) +end + +function widgets.DiffSwitch:getKey() + return game.difficulty:get(self.keyname) +end + +function widgets.DiffSwitch:getLabel() + self.key = self:getKey() + local label = "" + if (self.key) then + label = "true" + else + label = "false" + end + + return core.lang:translate("commons", label) +end + +function widgets.DiffSwitch:action() + self:modifyKey() + self.scene.assets:playSFX("mSelect") + self.label2 = self:getLabel() + game:write() + self:invalidateCanvas() +end + return widgets