add demo dynamic light on dev_mana cast

This commit is contained in:
PeaAshMeter 2026-01-17 18:26:13 +03:00
parent e088fddf48
commit ab37f6816d
4 changed files with 25 additions and 27 deletions

View File

@ -89,6 +89,7 @@ local function new(data)
t.t = 0
t.state = "running"
t.finish = function()
if t.state ~= "running" then return end
t.state = "waiting"
t:bubbleUp()
for _, anim in ipairs(t.children) do

View File

@ -1,7 +1,6 @@
--- Умеет асинхронно ждать какое-то время (для анимаций)
--- @class ResidentSleeperBehavior : Behavior
--- @field animationNode? AnimationNode
--- @field endsAt? number
local behavior = {}
behavior.__index = behavior
behavior.id = "residentsleeper"
@ -10,19 +9,13 @@ function behavior.new() return setmetatable({}, behavior) end
function behavior:update(dt)
if not self.animationNode then return end
if love.timer.getTime() >= self.endsAt then
self.animationNode:finish()
self.animationNode = nil
self.endsAt = nil
end
self.animationNode:update(dt)
end
--- @param ms number time to wait in milliseconds
--- @param node AnimationNode
function behavior:sleep(ms, node)
if self.animationNode then node:finish() end
function behavior:sleep(node)
if self.animationNode then self.animationNode:finish() end
self.animationNode = node
self.endsAt = love.timer.getTime() + ms / 1000
end
return behavior

View File

@ -8,15 +8,16 @@
--- Да, это Future/Promise/await/async
local AnimationNode = require "lib.animation_node"
local easing = require "lib.utils.easing"
--- @class Spell Здесь будет много бойлерплейта, поэтому тоже понадобится спеллмейкерский фреймворк, который просто вернет готовый Spell
--- @field tag string
--- @field update fun(self: Spell, caster: Character, dt: number): nil Изменяет состояние спелла
--- @field draw fun(self: Spell): nil Рисует превью каста, ничего не должна изменять в идеальном мире
--- @field cast fun(self: Spell, caster: Character, target: Vec3): boolean Вызывается в момент каста, изменяет мир. Возвращает bool в зависимости от того, получилось ли скастовать
local spell = {}
spell.__index = spell
spell.tag = "base"
local spell = {}
spell.__index = spell
spell.tag = "base"
function spell:update(caster, dt) end
@ -90,6 +91,13 @@ function regenerateMana:cast(caster, target)
print(caster.id, "has regenerated mana and gained initiative")
local sprite = caster:has(Tree.behaviors.sprite)
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 {
function(node)
sprite:animate("hurt", node)
@ -97,6 +105,14 @@ function regenerateMana:cast(caster, target)
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
}:run()
AnimationNode {
function(node)
light:has(Tree.behaviors.residentsleeper):sleep(node)
end,
duration = 400,
onEnd = function() light:die() end
}:run()
return true
end
@ -140,8 +156,9 @@ function attack:cast(caster, target)
},
AnimationNode {
function(node)
targetCharacter:has(Tree.behaviors.residentsleeper):sleep(200, node)
targetCharacter:has(Tree.behaviors.residentsleeper):sleep(node)
end,
duration = 200,
children = {
AnimationNode {
function(node)

View File

@ -39,12 +39,6 @@ function love.load()
Tree.level.turnOrder:add(id)
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()
print("Now playing:", Tree.level.turnOrder.current)
@ -61,13 +55,6 @@ function love.update(dt)
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()
lt = string.format("%.3f", (t2 - t1) * 1000)
end