feat(cbs): add a skill system, and adapt the basic attack to use it
This commit is contained in:
parent
1217ec0d10
commit
56e9af6ac3
8 changed files with 212 additions and 14 deletions
18
sonic-radiance.love/assets/sprites/gfx/hit.lua
Normal file
18
sonic-radiance.love/assets/sprites/gfx/hit.lua
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
return {
|
||||||
|
metadata = {
|
||||||
|
height = 32,
|
||||||
|
width = 32,
|
||||||
|
defaultAnim = "default",
|
||||||
|
ox = 16,
|
||||||
|
oy = 32,
|
||||||
|
},
|
||||||
|
animations = {
|
||||||
|
["default"] = {
|
||||||
|
startAt = 1,
|
||||||
|
endAt = 5,
|
||||||
|
loop = 1,
|
||||||
|
speed = 15,
|
||||||
|
pauseAtEnd = false,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
BIN
sonic-radiance.love/assets/sprites/gfx/hit.png
Normal file
BIN
sonic-radiance.love/assets/sprites/gfx/hit.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
53
sonic-radiance.love/datas/gamedata/skills/attack.lua
Normal file
53
sonic-radiance.love/datas/gamedata/skills/attack.lua
Normal file
|
@ -0,0 +1,53 @@
|
||||||
|
-- A basic file describing the basic attack, in order to make it customizable one
|
||||||
|
-- day ?
|
||||||
|
|
||||||
|
-- Also serve as a tutoriel for how to create a file attack and choregraphy
|
||||||
|
|
||||||
|
return {
|
||||||
|
name = "Attack", -- unused for this attack, but still usefull sometimes
|
||||||
|
cost = 00, -- the pp cost of the attack. Will be ignored if it's set
|
||||||
|
-- as character default attack
|
||||||
|
|
||||||
|
target = nil, -- which area can be selected as a target with the cursor.
|
||||||
|
-- if not nil : {ox, oy, shape, size, affectedByDirection}
|
||||||
|
|
||||||
|
targetNumber = 1, -- how many ennemy you can target with the attack.
|
||||||
|
|
||||||
|
effectArea = {1, 0, "point", 1, true}, -- which area is affected by the attack
|
||||||
|
-- if not nil : {ox, oy, shape, size, affectedByDirection}
|
||||||
|
|
||||||
|
choregraphy = { -- the main attack choregraphy
|
||||||
|
{'setAnimation', 'hit1', true},
|
||||||
|
{'addGFX', 'hitGFX', 0.75, 0, true, false},
|
||||||
|
{'sendDamage', 33, 100, false, false},
|
||||||
|
{'setAnimation', 'hit2', true},
|
||||||
|
{'addGFX', 'hitGFX', 0.75, 0, true, false},
|
||||||
|
{'sendDamage', 33, 100, false, false},
|
||||||
|
{'setAnimation', 'hit3', true},
|
||||||
|
{'addGFX', 'hitGFX', 0.75, 0, true, false},
|
||||||
|
{'sendDamage', 33, 100, false, false},
|
||||||
|
{'setAnimation', 'idle', false},
|
||||||
|
{'wait', 0.5}
|
||||||
|
},
|
||||||
|
|
||||||
|
onContact = { -- if the attack move and touch multiple ennemies, you can add
|
||||||
|
-- specific effect when you touch the ennemy.
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
--[[
|
||||||
|
CHOREGRAPHY POSSIBLE EFFECTS
|
||||||
|
-- "wait" :: Simply wait before doing the next command
|
||||||
|
-- :: {"wait", duration}
|
||||||
|
|
||||||
|
-- "setAnimation" :: Change the animation of the battler
|
||||||
|
-- {"setAnimation", animation, blockProcess}
|
||||||
|
|
||||||
|
-- "addGFX" :: Show a GFX relatively to the target position
|
||||||
|
-- :: (player if target is nil)
|
||||||
|
-- :: {"addGFX", "gfxname", x, y, affectedByDirection, blockProcess}
|
||||||
|
|
||||||
|
-- "sendDamage" :: Send Damage on the whole target Area
|
||||||
|
-- ::
|
||||||
|
-- :: {"sendDamage", damageEffect, accuracy, isSpecial, isAerial}
|
||||||
|
]]
|
29
sonic-radiance.love/scenes/battlesystem/actors/gfx.lua
Normal file
29
sonic-radiance.love/scenes/battlesystem/actors/gfx.lua
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
local Parent = require("scenes.battlesystem.actors.parent")
|
||||||
|
local GFX = Parent:extend()
|
||||||
|
|
||||||
|
function GFX:new(world, x, y, z, spritename, creator, blockProcess)
|
||||||
|
local width, height = world.assets.sprites[spritename]:getDimensions()
|
||||||
|
|
||||||
|
GFX.super.new(self, world, x, y, z)
|
||||||
|
self:setSprite(spritename, width/2, height, true)
|
||||||
|
self:cloneSprite()
|
||||||
|
self.creator = creator
|
||||||
|
self.blockProcess = blockProcess or false
|
||||||
|
|
||||||
|
self.direction = 1
|
||||||
|
end
|
||||||
|
|
||||||
|
function GFX:animationEnded(animation)
|
||||||
|
core.debug:print("gfx", 'Current animation "' .. animation .. '" have ended, destroying gfx')
|
||||||
|
self:destroy()
|
||||||
|
end
|
||||||
|
|
||||||
|
function GFX:draw()
|
||||||
|
self:drawSprite()
|
||||||
|
end
|
||||||
|
|
||||||
|
function GFX:drawShadow()
|
||||||
|
|
||||||
|
end
|
||||||
|
|
||||||
|
return GFX
|
|
@ -24,6 +24,7 @@ function Hero:new(world, x, y, charid, charnumber)
|
||||||
self.actionPerTurn = game.characters.list[self.charid].turns
|
self.actionPerTurn = game.characters.list[self.charid].turns
|
||||||
|
|
||||||
self:initSprite()
|
self:initSprite()
|
||||||
|
self:initChoregraphySystem()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- INFO FUNCTIONS
|
-- INFO FUNCTIONS
|
||||||
|
@ -58,6 +59,11 @@ function Hero:update(dt)
|
||||||
Hero.super.update(self, dt)
|
Hero.super.update(self, dt)
|
||||||
|
|
||||||
self.keys = self.scene:getKeys(1)
|
self.keys = self.scene:getKeys(1)
|
||||||
|
|
||||||
|
if (self.isChoregraphyActive) then
|
||||||
|
self:updateChoregraphy()
|
||||||
|
end
|
||||||
|
|
||||||
if (self.currentAction == "moving") then
|
if (self.currentAction == "moving") then
|
||||||
self:updateMoving(dt)
|
self:updateMoving(dt)
|
||||||
elseif (self.currentAction == "selectAttack") then
|
elseif (self.currentAction == "selectAttack") then
|
||||||
|
@ -148,7 +154,8 @@ function Hero:receiveSignal(action_type, id)
|
||||||
self.turnAction = "defend"
|
self.turnAction = "defend"
|
||||||
self:switchActiveBattler( )
|
self:switchActiveBattler( )
|
||||||
elseif (action_type == "attack") then
|
elseif (action_type == "attack") then
|
||||||
self:changeAnimation("hit1")
|
--self:changeAnimation("hit1")
|
||||||
|
self:startChoregraphy("attack")
|
||||||
else
|
else
|
||||||
self:switchActiveBattler( )
|
self:switchActiveBattler( )
|
||||||
end
|
end
|
||||||
|
@ -163,6 +170,8 @@ end
|
||||||
function Hero:timerResponse(timer)
|
function Hero:timerResponse(timer)
|
||||||
if timer == "switchActiveBattler" then
|
if timer == "switchActiveBattler" then
|
||||||
self.world:switchActiveBattler()
|
self.world:switchActiveBattler()
|
||||||
|
elseif timer == "wait" then
|
||||||
|
self.choregraphy.changeAction = true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -183,6 +192,101 @@ function Hero:switchActiveBattler()
|
||||||
self.tweens:newTimer(0.15, "switchActiveBattler")
|
self.tweens:newTimer(0.15, "switchActiveBattler")
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- CHOREGRAPHY FUNCTIONS
|
||||||
|
-- All functions related to the choregraphy system
|
||||||
|
|
||||||
|
function Hero:initChoregraphySystem()
|
||||||
|
self.choregraphy = {}
|
||||||
|
self.choregraphy.current = 0
|
||||||
|
self.choregraphy.isFinished = false
|
||||||
|
self.choregraphy.changeAction = true
|
||||||
|
self.choregraphy.data = {}
|
||||||
|
self.choregraphy.effectArea = nil
|
||||||
|
self.choregraphy.dx = self.x
|
||||||
|
self.choregraphy.dy = self.y
|
||||||
|
self.choregraphy.blockedBy = ""
|
||||||
|
|
||||||
|
self.isChoregraphyActive = false
|
||||||
|
end
|
||||||
|
|
||||||
|
function Hero:startChoregraphy(skill, dx, dy)
|
||||||
|
local skill = require("datas.gamedata.skills." .. skill)
|
||||||
|
self.choregraphy.current = 0
|
||||||
|
self.choregraphy.isFinished = false
|
||||||
|
self.choregraphy.changeAction = true
|
||||||
|
self.choregraphy.data = skill.choregraphy
|
||||||
|
self.choregraphy.effectArea = skill.effectArea
|
||||||
|
self.choregraphy.dx = dx or self.x
|
||||||
|
self.choregraphy.dy = dy or self.y
|
||||||
|
|
||||||
|
self.isChoregraphyActive = true
|
||||||
|
end
|
||||||
|
|
||||||
|
function Hero:updateChoregraphy(dt)
|
||||||
|
if (self.choregraphy.changeAction) then
|
||||||
|
self:switchAction()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Hero:switchAction()
|
||||||
|
self.choregraphy.current = self.choregraphy.current + 1
|
||||||
|
local nextAction = self.choregraphy.data[self.choregraphy.current]
|
||||||
|
if nextAction == nil then
|
||||||
|
self.isChoregraphyActive = false
|
||||||
|
self:switchActiveBattler()
|
||||||
|
else
|
||||||
|
self:doChoregraphyAction(nextAction)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Hero:doChoregraphyAction(choregraphyAction)
|
||||||
|
local type = choregraphyAction[1] or "unknown"
|
||||||
|
self.choregraphy.changeAction = true
|
||||||
|
|
||||||
|
if type == "wait" then
|
||||||
|
local duration = choregraphyAction[2] or 1
|
||||||
|
self:wait(duration)
|
||||||
|
elseif type == "setAnimation" then
|
||||||
|
local animation = choregraphyAction[2]
|
||||||
|
local blockProcess = choregraphyAction[3]
|
||||||
|
self:changeAnimation(animation)
|
||||||
|
if (blockProcess) then
|
||||||
|
self.choregraphy.blockedBy = animation
|
||||||
|
self.choregraphy.changeAction = false
|
||||||
|
end
|
||||||
|
elseif type == "sendDamage" then
|
||||||
|
local xx = self.x + self.direction
|
||||||
|
local yy = self.y
|
||||||
|
local power = choregraphyAction[2]
|
||||||
|
local accuracy = choregraphyAction[3]
|
||||||
|
local isSpecial = choregraphyAction[4]
|
||||||
|
local isAerial = choregraphyAction[5]
|
||||||
|
self:sendDamage(xx, yy, power, accuracy, isSpecial, isAerial)
|
||||||
|
elseif type == "addGFX" then
|
||||||
|
local sprite = choregraphyAction[2]
|
||||||
|
local dx = choregraphyAction[3]
|
||||||
|
local dy = choregraphyAction[4]
|
||||||
|
local affectedByDirection = choregraphyAction[5]
|
||||||
|
if (affectedByDirection) then
|
||||||
|
dx = dx * self.direction
|
||||||
|
end
|
||||||
|
local blockProcess = choregraphyAction[6]
|
||||||
|
|
||||||
|
local x = self.x
|
||||||
|
local y = self.y
|
||||||
|
local z = 0
|
||||||
|
|
||||||
|
self.world.obj.GFX(self.world, x + dx, y + dy, z, sprite, self, blockProcess)
|
||||||
|
else
|
||||||
|
core.debug:warning("cbs/hero", "unknown action type " .. type)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function Hero:wait(time)
|
||||||
|
self.tweens:newTimer(time, "wait")
|
||||||
|
self.choregraphy.changeAction = false
|
||||||
|
end
|
||||||
|
|
||||||
-- SPRITE FUNCTIONS
|
-- SPRITE FUNCTIONS
|
||||||
-- Handle the hero sprite
|
-- Handle the hero sprite
|
||||||
|
|
||||||
|
@ -195,17 +299,9 @@ function Hero:initSprite()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Hero:animationEnded(animation)
|
function Hero:animationEnded(animation)
|
||||||
if (animation == "hit1") then
|
if (animation == self.choregraphy.blockedBy) then
|
||||||
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
|
self.choregraphy.blockedBy = ""
|
||||||
self:changeAnimation("hit2")
|
self.choregraphy.changeAction = true
|
||||||
elseif (animation == "hit2") then
|
|
||||||
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
|
|
||||||
self:changeAnimation("hit3")
|
|
||||||
elseif (animation == "hit3") then
|
|
||||||
self:sendDamage(self.x + self.direction, self.y, 33, 100, false, false)
|
|
||||||
core.debug:print("cbs/hero", "normal combo finished, switching actor")
|
|
||||||
self:changeAnimation("idle")
|
|
||||||
self:switchActiveBattler( )
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,5 +4,6 @@ local baseURI = "scenes.battlesystem.actors."
|
||||||
|
|
||||||
entities.Hero = require(baseURI .. "hero")
|
entities.Hero = require(baseURI .. "hero")
|
||||||
entities.Ennemy = require(baseURI .. "ennemy")
|
entities.Ennemy = require(baseURI .. "ennemy")
|
||||||
|
entities.GFX = require(baseURI .. "gfx")
|
||||||
|
|
||||||
return entities
|
return entities
|
||||||
|
|
|
@ -28,7 +28,7 @@ function Parent:new(world, x, y, z)
|
||||||
self.isDestroyed = false
|
self.isDestroyed = false
|
||||||
|
|
||||||
self.tweens = TweenManager(self)
|
self.tweens = TweenManager(self)
|
||||||
|
|
||||||
self:setSprite()
|
self:setSprite()
|
||||||
self:register()
|
self:register()
|
||||||
end
|
end
|
||||||
|
|
|
@ -6,7 +6,8 @@ return {
|
||||||
{"borders", "assets/backgrounds/borders"},
|
{"borders", "assets/backgrounds/borders"},
|
||||||
},
|
},
|
||||||
["sprites"] = {
|
["sprites"] = {
|
||||||
{"cursorground", "assets/gui/cursor/ground"}
|
{"cursorground", "assets/gui/cursor/ground"},
|
||||||
|
{"hitGFX", "assets/sprites/gfx/hit"},
|
||||||
},
|
},
|
||||||
["textures"] = {
|
["textures"] = {
|
||||||
{"menucursor", "assets/gui/cursor-menulist.png"},
|
{"menucursor", "assets/gui/cursor-menulist.png"},
|
||||||
|
|
Loading…
Reference in a new issue