diff --git a/lib/character/behaviors/light.lua b/lib/character/behaviors/light.lua index 8d6b93c..1c629c6 100644 --- a/lib/character/behaviors/light.lua +++ b/lib/character/behaviors/light.lua @@ -2,6 +2,9 @@ --- @field intensity number --- @field color Vec3 --- @field seed integer +--- @field colorAnimationNode? AnimationNode +--- @field targetColor? Vec3 +--- @field sourceColor? Vec3 local behavior = {} behavior.__index = behavior behavior.id = "light" @@ -16,7 +19,18 @@ function behavior.new(values) }, behavior) end -function behavior:update() +function behavior:update(dt) + if not self.colorAnimationNode then return end + local delta = self.targetColor - self.sourceColor + self.color = self.sourceColor + delta * self.colorAnimationNode:getValue() + self.colorAnimationNode:update(dt) +end + +function behavior:animateColor(targetColor, animationNode) + if self.colorAnimationNode then self.colorAnimationNode:finish() end + self.colorAnimationNode = animationNode + self.sourceColor = self.color + self.targetColor = targetColor end function behavior:draw() diff --git a/lib/spellbook.lua b/lib/spellbook.lua index e50fc82..51b0fa6 100644 --- a/lib/spellbook.lua +++ b/lib/spellbook.lua @@ -107,9 +107,10 @@ function regenerateMana:cast(caster, target) AnimationNode { function(node) - light:has(Tree.behaviors.residentsleeper):sleep(node) + light:has(Tree.behaviors.light):animateColor(Vec3 {}, node) end, - duration = 400, + easing = easing.easeInQuad, + duration = 800, onEnd = function() light:die() end }:run()