feat: simple selection system

This commit is contained in:
Kazhnuz 2020-07-19 21:41:14 +02:00
parent f3cfaf9ac2
commit 649bb561da
8 changed files with 129 additions and 7 deletions

View file

@ -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()

View file

@ -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()

View file

@ -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()

View file

@ -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

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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