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

66 lines
1.6 KiB
Lua
Raw Normal View History

2020-07-19 21:41:14 +02:00
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