add demo dynamic light on dev_mana cast
This commit is contained in:
parent
e088fddf48
commit
ab37f6816d
@ -89,6 +89,7 @@ local function new(data)
|
|||||||
t.t = 0
|
t.t = 0
|
||||||
t.state = "running"
|
t.state = "running"
|
||||||
t.finish = function()
|
t.finish = function()
|
||||||
|
if t.state ~= "running" then return end
|
||||||
t.state = "waiting"
|
t.state = "waiting"
|
||||||
t:bubbleUp()
|
t:bubbleUp()
|
||||||
for _, anim in ipairs(t.children) do
|
for _, anim in ipairs(t.children) do
|
||||||
|
|||||||
@ -1,7 +1,6 @@
|
|||||||
--- Умеет асинхронно ждать какое-то время (для анимаций)
|
--- Умеет асинхронно ждать какое-то время (для анимаций)
|
||||||
--- @class ResidentSleeperBehavior : Behavior
|
--- @class ResidentSleeperBehavior : Behavior
|
||||||
--- @field animationNode? AnimationNode
|
--- @field animationNode? AnimationNode
|
||||||
--- @field endsAt? number
|
|
||||||
local behavior = {}
|
local behavior = {}
|
||||||
behavior.__index = behavior
|
behavior.__index = behavior
|
||||||
behavior.id = "residentsleeper"
|
behavior.id = "residentsleeper"
|
||||||
@ -10,19 +9,13 @@ function behavior.new() return setmetatable({}, behavior) end
|
|||||||
|
|
||||||
function behavior:update(dt)
|
function behavior:update(dt)
|
||||||
if not self.animationNode then return end
|
if not self.animationNode then return end
|
||||||
if love.timer.getTime() >= self.endsAt then
|
self.animationNode:update(dt)
|
||||||
self.animationNode:finish()
|
|
||||||
self.animationNode = nil
|
|
||||||
self.endsAt = nil
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--- @param ms number time to wait in milliseconds
|
|
||||||
--- @param node AnimationNode
|
--- @param node AnimationNode
|
||||||
function behavior:sleep(ms, node)
|
function behavior:sleep(node)
|
||||||
if self.animationNode then node:finish() end
|
if self.animationNode then self.animationNode:finish() end
|
||||||
self.animationNode = node
|
self.animationNode = node
|
||||||
self.endsAt = love.timer.getTime() + ms / 1000
|
|
||||||
end
|
end
|
||||||
|
|
||||||
return behavior
|
return behavior
|
||||||
|
|||||||
@ -8,6 +8,7 @@
|
|||||||
--- Да, это Future/Promise/await/async
|
--- Да, это Future/Promise/await/async
|
||||||
|
|
||||||
local AnimationNode = require "lib.animation_node"
|
local AnimationNode = require "lib.animation_node"
|
||||||
|
local easing = require "lib.utils.easing"
|
||||||
|
|
||||||
--- @class Spell Здесь будет много бойлерплейта, поэтому тоже понадобится спеллмейкерский фреймворк, который просто вернет готовый Spell
|
--- @class Spell Здесь будет много бойлерплейта, поэтому тоже понадобится спеллмейкерский фреймворк, который просто вернет готовый Spell
|
||||||
--- @field tag string
|
--- @field tag string
|
||||||
@ -90,6 +91,13 @@ function regenerateMana:cast(caster, target)
|
|||||||
print(caster.id, "has regenerated mana and gained initiative")
|
print(caster.id, "has regenerated mana and gained initiative")
|
||||||
local sprite = caster:has(Tree.behaviors.sprite)
|
local sprite = caster:has(Tree.behaviors.sprite)
|
||||||
if not sprite then return true end
|
if not sprite then return true end
|
||||||
|
|
||||||
|
local light = require "lib/character/character".spawn("Light Effect")
|
||||||
|
light:addBehavior {
|
||||||
|
Tree.behaviors.light.new { color = Vec3 { 0.6, 0.3, 0.3 }, intensity = 4 },
|
||||||
|
Tree.behaviors.residentsleeper.new(),
|
||||||
|
Tree.behaviors.positioned.new(caster:has(Tree.behaviors.positioned).position + Vec3 { 0.5, 0.5 }),
|
||||||
|
}
|
||||||
AnimationNode {
|
AnimationNode {
|
||||||
function(node)
|
function(node)
|
||||||
sprite:animate("hurt", node)
|
sprite:animate("hurt", node)
|
||||||
@ -97,6 +105,14 @@ function regenerateMana:cast(caster, target)
|
|||||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
||||||
}:run()
|
}:run()
|
||||||
|
|
||||||
|
AnimationNode {
|
||||||
|
function(node)
|
||||||
|
light:has(Tree.behaviors.residentsleeper):sleep(node)
|
||||||
|
end,
|
||||||
|
duration = 400,
|
||||||
|
onEnd = function() light:die() end
|
||||||
|
}:run()
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -140,8 +156,9 @@ function attack:cast(caster, target)
|
|||||||
},
|
},
|
||||||
AnimationNode {
|
AnimationNode {
|
||||||
function(node)
|
function(node)
|
||||||
targetCharacter:has(Tree.behaviors.residentsleeper):sleep(200, node)
|
targetCharacter:has(Tree.behaviors.residentsleeper):sleep(node)
|
||||||
end,
|
end,
|
||||||
|
duration = 200,
|
||||||
children = {
|
children = {
|
||||||
AnimationNode {
|
AnimationNode {
|
||||||
function(node)
|
function(node)
|
||||||
|
|||||||
13
main.lua
13
main.lua
@ -39,12 +39,6 @@ function love.load()
|
|||||||
Tree.level.turnOrder:add(id)
|
Tree.level.turnOrder:add(id)
|
||||||
end
|
end
|
||||||
|
|
||||||
character.spawn("My Light")
|
|
||||||
:addBehavior {
|
|
||||||
Tree.behaviors.light.new { color = Vec3 { 88, 34, 13 }, intensity = 10 },
|
|
||||||
Tree.behaviors.positioned.new(),
|
|
||||||
Tree.behaviors.cursor.new()
|
|
||||||
}
|
|
||||||
|
|
||||||
Tree.level.turnOrder:endRound()
|
Tree.level.turnOrder:endRound()
|
||||||
print("Now playing:", Tree.level.turnOrder.current)
|
print("Now playing:", Tree.level.turnOrder.current)
|
||||||
@ -61,13 +55,6 @@ function love.update(dt)
|
|||||||
|
|
||||||
Tree.controls:cache()
|
Tree.controls:cache()
|
||||||
|
|
||||||
if t1 > 2 then
|
|
||||||
local foodor = Tree.level.characters[1]
|
|
||||||
if not foodor then return end
|
|
||||||
print("Killing Foodor")
|
|
||||||
foodor:die()
|
|
||||||
end
|
|
||||||
|
|
||||||
local t2 = love.timer.getTime()
|
local t2 = love.timer.getTime()
|
||||||
lt = string.format("%.3f", (t2 - t1) * 1000)
|
lt = string.format("%.3f", (t2 - t1) * 1000)
|
||||||
end
|
end
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user