feat: simple selection system
This commit is contained in:
parent
f3cfaf9ac2
commit
649bb561da
8 changed files with 129 additions and 7 deletions
|
@ -8,6 +8,8 @@ function Battler:new(world, x, y, z)
|
||||||
self.speed = 3
|
self.speed = 3
|
||||||
self.isActive = false
|
self.isActive = false
|
||||||
self.debugActiveTimer = 0
|
self.debugActiveTimer = 0
|
||||||
|
|
||||||
|
self.isSelected = false
|
||||||
end
|
end
|
||||||
|
|
||||||
function Battler:destroy()
|
function Battler:destroy()
|
||||||
|
|
|
@ -24,6 +24,11 @@ function Ennemy:draw()
|
||||||
love.graphics.setColor(1, 1, 1, 1)
|
love.graphics.setColor(1, 1, 1, 1)
|
||||||
|
|
||||||
self.owner:drawHUD(x - 14, y - 38)
|
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
|
end
|
||||||
|
|
||||||
function Ennemy:receiveDatas()
|
function Ennemy:receiveDatas()
|
||||||
|
|
|
@ -178,6 +178,9 @@ end
|
||||||
function Parent:drawShadow()
|
function Parent:drawShadow()
|
||||||
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
local x, y = self.world.map:gridToPixel(self.x, self.y, true)
|
||||||
self.assets.images["actorsShadow"]:draw(x, y, 0, 1, 1, 12, 5)
|
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
|
end
|
||||||
|
|
||||||
function Parent:drawHUD()
|
function Parent:drawHUD()
|
||||||
|
|
|
@ -2,6 +2,7 @@ local FighterParent = require "scenes.battlesystem.controllers.fighters.parent"
|
||||||
local HeroFighter = FighterParent:extend()
|
local HeroFighter = FighterParent:extend()
|
||||||
|
|
||||||
local StatusBar = require "scenes.battlesystem.gui.statusbar"
|
local StatusBar = require "scenes.battlesystem.gui.statusbar"
|
||||||
|
local SelectionSystem = require "scenes.battlesystem.controllers.fighters.systems.selection"
|
||||||
|
|
||||||
local POSITIONS = {3, 1, 5}
|
local POSITIONS = {3, 1, 5}
|
||||||
local HEROES_LINE = 3;
|
local HEROES_LINE = 3;
|
||||||
|
@ -11,6 +12,12 @@ function HeroFighter:new(owner, character, id)
|
||||||
self.super.new(self, owner, true, id)
|
self.super.new(self, owner, true, id)
|
||||||
|
|
||||||
self.statusbar = StatusBar(self)
|
self.statusbar = StatusBar(self)
|
||||||
|
|
||||||
|
self.currentAction = ""
|
||||||
|
self.actionArgument = ""
|
||||||
|
self.target = nil
|
||||||
|
|
||||||
|
self.selection = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:updateAssets(dt)
|
function HeroFighter:updateAssets(dt)
|
||||||
|
@ -18,7 +25,9 @@ function HeroFighter:updateAssets(dt)
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:update(dt)
|
function HeroFighter:update(dt)
|
||||||
|
if (self.selection ~= nil) then
|
||||||
|
self.selection:update(dt)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function HeroFighter:getAbstract()
|
function HeroFighter:getAbstract()
|
||||||
|
@ -32,6 +41,9 @@ end
|
||||||
|
|
||||||
function HeroFighter:startAction()
|
function HeroFighter:startAction()
|
||||||
core.debug:print("cbs/heroFighter", "launching the action menu")
|
core.debug:print("cbs/heroFighter", "launching the action menu")
|
||||||
|
self.currentAction = ""
|
||||||
|
self.actionArgument = ""
|
||||||
|
self.target = nil
|
||||||
self.turnSystem.scene.menu:set( self )
|
self.turnSystem.scene.menu:set( self )
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -44,6 +56,21 @@ function HeroFighter:doNothing()
|
||||||
self:setInactive()
|
self:setInactive()
|
||||||
end
|
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
|
-- DRAW FUNCTIONS
|
||||||
function HeroFighter:drawIcon(x, y)
|
function HeroFighter:drawIcon(x, y)
|
||||||
local iconID = 1
|
local iconID = 1
|
||||||
|
|
|
@ -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
|
|
@ -3,7 +3,7 @@ local VillainFighter = FighterParent:extend()
|
||||||
|
|
||||||
local SimpleHPBar = require "scenes.battlesystem.gui.simplehpbar"
|
local SimpleHPBar = require "scenes.battlesystem.gui.simplehpbar"
|
||||||
|
|
||||||
local POSITIONS = {3, 1, 5}
|
local POSITIONS = {1, 3, 5}
|
||||||
local ENNEMY_LINE = 10;
|
local ENNEMY_LINE = 10;
|
||||||
|
|
||||||
function VillainFighter:new(owner, ennemy, id)
|
function VillainFighter:new(owner, ennemy, id)
|
||||||
|
|
|
@ -6,6 +6,10 @@ function FighterControllerParent:new(turnSystem)
|
||||||
self.list = {}
|
self.list = {}
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function FighterControllerParent:get(id)
|
||||||
|
return self.list[id]
|
||||||
|
end
|
||||||
|
|
||||||
function FighterControllerParent:add(fighter)
|
function FighterControllerParent:add(fighter)
|
||||||
table.insert(self.list, fighter)
|
table.insert(self.list, fighter)
|
||||||
end
|
end
|
||||||
|
|
|
@ -10,6 +10,8 @@ local SubMenuWidget = BattleWidget:extend()
|
||||||
local BackMenuWidget = BattleWidget:extend()
|
local BackMenuWidget = BattleWidget:extend()
|
||||||
local SkillWidget = BattleWidget:extend()
|
local SkillWidget = BattleWidget:extend()
|
||||||
|
|
||||||
|
local AttackWidget = ActionWidget:extend()
|
||||||
|
|
||||||
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
local MENUPOS_X1, MENUPOS_X2, MENUPOS_Y = 32, 32, 110
|
||||||
local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
local MENU_WIDTH, MENU_ITEM_HEIGHT = 148, 17
|
||||||
local MENU_ITEM_NUMBER = 6
|
local MENU_ITEM_NUMBER = 6
|
||||||
|
@ -33,11 +35,12 @@ function MenuConstructor:build(character)
|
||||||
self:buildObjectMenu(character)
|
self:buildObjectMenu(character)
|
||||||
|
|
||||||
self.scene.menusystem:setSoundFromSceneAssets("mBeep")
|
self.scene.menusystem:setSoundFromSceneAssets("mBeep")
|
||||||
|
self.scene.menusystem:activate()
|
||||||
end
|
end
|
||||||
|
|
||||||
function MenuConstructor:buildBaseMenu(character)
|
function MenuConstructor:buildBaseMenu(character)
|
||||||
CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
CharacterMenu(self.scene, "BaseMenu", MENUPOS_X1 - 16, MENUPOS_Y)
|
||||||
ActionWidget(character, "BaseMenu", "attack")
|
AttackWidget(character, "BaseMenu")
|
||||||
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
SubMenuWidget(character, "BaseMenu", "skills", "SkillMenu")
|
||||||
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
SubMenuWidget(character, "BaseMenu", "objects", "ObjectMenu")
|
||||||
ActionWidget(character, "BaseMenu", "defend")
|
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
|
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)
|
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.cursorTexture = love.graphics.newImage("assets/gui/cursor-menulist.png")
|
||||||
self.cursorTransition = 1
|
self.cursorTransition = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
function CharacterMenu:update(dt)
|
function CharacterMenu:update(dt)
|
||||||
|
@ -197,10 +200,10 @@ function BattleWidget:drawCanvas()
|
||||||
end
|
end
|
||||||
|
|
||||||
function BattleWidget:action()
|
function BattleWidget:action()
|
||||||
self:sendCharacterData()
|
|
||||||
|
|
||||||
self.scene:flushKeys()
|
self.scene:flushKeys()
|
||||||
self.scene.menusystem:reset()
|
self.scene.menusystem:deactivate()
|
||||||
|
|
||||||
|
self:sendCharacterData()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- External functions
|
-- External functions
|
||||||
|
@ -221,6 +224,19 @@ function ActionWidget:sendCharacterData()
|
||||||
self.character:doNothing()
|
self.character:doNothing()
|
||||||
end
|
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
|
-- SubMenuWidget
|
||||||
-- A simple widget to change menu
|
-- A simple widget to change menu
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue