sonic-radiance/sonic-radiance.love/scenes/battlesystem/controllers/fighters/systems/selection.lua

65 lines
1.6 KiB
Lua

local SelectionSystem = Object:extend()
function SelectionSystem:new(owner, fighterSide, onlyAlive)
self.fighterList = fighterSide:getTargets(onlyAlive)
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
else
self.selectedTarget = self.selectedTarget - 1
end
self.assets.sfx["mBeep"]:play()
end
if (keys["down"].isPressed) then
if (self.selectedTarget == #self.fighterList) 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[self.selectedTarget]
target.actor.isSelected = false
end
function SelectionSystem:updateTarget()
local target = self.fighterList[self.selectedTarget]
target.actor.isSelected = true
end
function SelectionSystem:selectTarget()
self:purgeTarget()
self.owner:receiveTarget(self.fighterList[self.selectedTarget])
end
function SelectionSystem:goBack()
self:purgeTarget()
self.owner:goBackToMenu()
end
return SelectionSystem