From 649bb561dade1b8f4e95f9431b354e720a05518b Mon Sep 17 00:00:00 2001 From: Kazhnuz Date: Sun, 19 Jul 2020 21:41:14 +0200 Subject: [PATCH] feat: simple selection system --- .../scenes/battlesystem/actors/battler.lua | 2 + .../scenes/battlesystem/actors/ennemy.lua | 5 ++ .../scenes/battlesystem/actors/parent.lua | 3 + .../controllers/fighters/character.lua | 29 ++++++++- .../fighters/systems/selection.lua | 65 +++++++++++++++++++ .../controllers/fighters/villain.lua | 2 +- .../battlesystem/controllers/parent.lua | 4 ++ .../scenes/battlesystem/menu.lua | 26 ++++++-- 8 files changed, 129 insertions(+), 7 deletions(-) create mode 100644 sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua diff --git a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua index c531968..89913a7 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/battler.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/battler.lua @@ -8,6 +8,8 @@ function Battler:new(world, x, y, z) self.speed = 3 self.isActive = false self.debugActiveTimer = 0 + + self.isSelected = false end function Battler:destroy() diff --git a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua index 8d08b3c..742767a 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/ennemy.lua @@ -24,6 +24,11 @@ function Ennemy:draw() love.graphics.setColor(1, 1, 1, 1) self.owner:drawHUD(x - 14, y - 38) + + if (self.isSelected) then + local height = 32 + self.assets.images["cursorpeak"]:draw(x - 7, y - 24 - 32) + end end function Ennemy:receiveDatas() diff --git a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua index 2a095b0..e2c8110 100644 --- a/sonic-radiance.love/scenes/battlesystem/actors/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/actors/parent.lua @@ -178,6 +178,9 @@ end function Parent:drawShadow() local x, y = self.world.map:gridToPixel(self.x, self.y, true) self.assets.images["actorsShadow"]:draw(x, y, 0, 1, 1, 12, 5) + if (self.isSelected == true) then + self.assets.sprites["cursorground"]:drawAnimation(x - 2, y - 1, 0, 1, 1, 12, 5) + end end function Parent:drawHUD() diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua index daf4220..68d76f7 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/character.lua @@ -2,6 +2,7 @@ local FighterParent = require "scenes.battlesystem.controllers.fighters.parent" local HeroFighter = FighterParent:extend() local StatusBar = require "scenes.battlesystem.gui.statusbar" +local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection" local POSITIONS = {3, 1, 5} local HEROES_LINE = 3; @@ -11,6 +12,12 @@ function HeroFighter:new(owner, character, id) self.super.new(self, owner, true, id) self.statusbar = StatusBar(self) + + self.currentAction = "" + self.actionArgument = "" + self.target = nil + + self.selection = nil end function HeroFighter:updateAssets(dt) @@ -18,7 +25,9 @@ function HeroFighter:updateAssets(dt) end function HeroFighter:update(dt) - + if (self.selection ~= nil) then + self.selection:update(dt) + end end function HeroFighter:getAbstract() @@ -32,6 +41,9 @@ end function HeroFighter:startAction() core.debug:print("cbs/heroFighter", "launching the action menu") + self.currentAction = "" + self.actionArgument = "" + self.target = nil self.turnSystem.scene.menu:set( self ) end @@ -44,6 +56,21 @@ function HeroFighter:doNothing() self:setInactive() end +function HeroFighter:attack() + self.currentAction = "attack" + self.selection = SelectionSystem(self, self.owner.turnSystem.ennemies) +end + +function HeroFighter:receiveTarget(target) + self.selection = nil + self:setInactive() +end + +function HeroFighter:goBackToMenu() + self.owner.turnSystem.scene.menusystem:activate() + self.selection = nil +end + -- DRAW FUNCTIONS function HeroFighter:drawIcon(x, y) local iconID = 1 diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua new file mode 100644 index 0000000..2d57620 --- /dev/null +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua @@ -0,0 +1,65 @@ +local SelectionSystem = Object:extend() + +function SelectionSystem:new(owner, fighterList) + self.fighterList = fighterList + self.owner = owner + self.assets = self.owner.assets + self.selectedTarget = 1 +end + +function SelectionSystem:update(dt) + --Faire en sorte que cela permette de choisir la cible + local keys = self.owner.turnSystem.scene:getKeys(1) + self:purgeTarget() + if (keys["up"].isPressed) then + if (self.selectedTarget == 1) then + self.selectedTarget = self.fighterList:count() + else + self.selectedTarget = self.selectedTarget - 1 + end + self.assets.sfx["mBeep"]:play() + end + if (keys["down"].isPressed) then + if (self.selectedTarget == self.fighterList:count()) then + self.selectedTarget = 1 + else + self.selectedTarget = self.selectedTarget + 1 + end + self.assets.sfx["mBeep"]:play() + end + + self:updateTarget() + + if (keys["A"].isPressed) then + self.assets.sfx["mSelect"]:play() + self:selectTarget() + end + + if (keys["B"].isPressed) then + self.assets.sfx["mBack"]:play() + self:goBack() + end + +end + +function SelectionSystem:purgeTarget() + local target = self.fighterList:get(self.selectedTarget) + target.actor.isSelected = false +end + +function SelectionSystem:updateTarget() + local target = self.fighterList:get(self.selectedTarget) + target.actor.isSelected = true +end + +function SelectionSystem:selectTarget() + self:purgeTarget() + self.owner:receiveTarget(self.fighterList:get(self.selectedTarget)) +end + +function SelectionSystem:goBack() + self:purgeTarget() + self.owner:goBackToMenu() +end + +return SelectionSystem diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua index 45ac549..c8a9c6b 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/fighters/villain.lua @@ -3,7 +3,7 @@ local VillainFighter = FighterParent:extend() local SimpleHPBar = require "scenes.battlesystem.gui.simplehpbar" -local POSITIONS = {3, 1, 5} +local POSITIONS = {1, 3, 5} local ENNEMY_LINE = 10; function VillainFighter:new(owner, ennemy, id) diff --git a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua index de032d3..b9659fa 100644 --- a/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua +++ b/sonic-radiance.love/scenes/battlesystem/controllers/parent.lua @@ -6,6 +6,10 @@ function FighterControllerParent:new(turnSystem) self.list = {} end +function FighterControllerParent:get(id) + return self.list[id] +end + function FighterControllerParent:add(fighter) table.insert(self.list, fighter) end diff --git a/sonic-radiance.love/scenes/battlesystem/menu.lua b/sonic-radiance.love/scenes/battlesystem/menu.lua index 00cd9b6..cea0beb 100644 --- a/sonic-radiance.love/scenes/battlesystem/menu.lua +++ b/sonic-radiance.love/scenes/battlesystem/menu.lua @@ -10,6 +10,8 @@ local SubMenuWidget = BattleWidget:extend() local BackMenuWidget = BattleWidget:extend() local SkillWidget = BattleWidget:extend() +local AttackWidget = ActionWidget:extend() + local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110 local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17 local MENU_ITEM_NUMBER = 6 @@ -33,11 +35,12 @@ function MenuConstructor:build(character) self:buildObjectMenu(character) self.scene.menusystem:setSoundFromSceneAssets("mBeep") + self.scene.menusystem:activate() end function MenuConstructor:buildBaseMenu(character) CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y) - ActionWidget(character, "BaseMenu", "attack") + AttackWidget(character, "BaseMenu") SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu") SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu") ActionWidget(character, "BaseMenu", "defend") @@ -101,7 +104,7 @@ function CharacterMenu:new(scene, name, x, y) local w, h = MENU_WIDTH, MENU_ITEM_NUMBER * MENU_ITEM_HEIGHT CharacterMenu.super.new(self, scene.menusystem, name, x, y, w, h, MENU_ITEM_NUMBER) self.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png") - self.cursorTransition = 1 + self.cursorTransition = 0 end function CharacterMenu:update(dt) @@ -197,10 +200,10 @@ function BattleWidget:drawCanvas() end function BattleWidget:action() - self:sendCharacterData() - self.scene:flushKeys() - self.scene.menusystem:reset() + self.scene.menusystem:deactivate() + + self:sendCharacterData() end -- External functions @@ -221,6 +224,19 @@ function ActionWidget:sendCharacterData() self.character:doNothing() end +-- AttackWidget +-- The basic action widget + +function AttackWidget:new(character, menu_name) + self.actionType = "attack" + ActionWidget.super.new(self, character, menu_name, "attack", "") +end + +function AttackWidget:sendCharacterData() + self.character:attack() +end + + -- SubMenuWidget -- A simple widget to change menu