diff --git a/lib/audio.lua b/lib/audio.lua index d3647b0..f2f1f0a 100644 --- a/lib/audio.lua +++ b/lib/audio.lua @@ -4,6 +4,7 @@ local AnimationNode = require "lib.animation_node" --- @class Audio --- @field musicVolume number --- @field soundVolume number +--- @field animationNode AnimationNode? audio = {} audio.__index = audio @@ -15,6 +16,13 @@ local function new(musicVolume, soundVolume) }, audio) end +function audio:update(dt) + if self.animationNode then + self.animationNode:update(dt) + print(self.animationNode.t) + print(self.animationNode:getValue()) + end +end --- if from is nil, than we have fade in to; --- if to is nil, than we have fade out from @@ -22,7 +30,7 @@ end --- also we should guarantee, that from and to have the same volume --- @param from love.Source --- @param to love.Source ---- @param ms? number in milliseconds +--- @param ms number? in milliseconds function audio:crossfade(from, to, ms) to:setVolume(0) to:play() @@ -46,13 +54,13 @@ end --- also we should guarantee, that from and to have the same volume --- @param from love.Source --- @param to love.Source ---- @param ms? number in milliseconds +--- @param ms number? in milliseconds function audio:crossfadeAnim(from, to, ms) to:setVolume(0) to:play() print(from:getVolume(), to:getVolume()) local t = 0 - local anim = AnimationNode { + self.animationNode = AnimationNode { function(node) from:setVolume(self.musicVolume - node:getValue() * self.musicVolume) to:setVolume(node:getValue() * self.musicVolume) @@ -79,8 +87,8 @@ function audio:crossfadeAnim(from, to, ms) -- } -- } } - anim:run() - anim:finish() + self.animationNode:run() + -- anim:finish() print(from:getVolume(), to:getVolume(), t, t, t) end diff --git a/lib/spellbook.lua b/lib/spellbook.lua index 6283e14..8502f07 100644 --- a/lib/spellbook.lua +++ b/lib/spellbook.lua @@ -51,7 +51,9 @@ function walk:cast(caster, target) local sprite = caster:has(Tree.behaviors.sprite) if not sprite then return true end AnimationNode { - function(node) caster:has(Tree.behaviors.map):followPath(path, node) end, + function(node) + caster:has(Tree.behaviors.map):followPath(path, node) + end, onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end, }:run() @@ -91,7 +93,7 @@ function regenerateMana:cast(caster, target) local audioPath = Tree.assets.files.audio sprite:animate("hurt", node) Tree.audio:crossfadeAnim(audioPath.music.level1.battle, - audioPath.music.level1.choral, 3000) + audioPath.music.level1.choral, 2000) end, onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end }:run() diff --git a/main.lua b/main.lua index 256ba45..2e03e89 100644 --- a/main.lua +++ b/main.lua @@ -32,6 +32,7 @@ function love.update(dt) testLayout:update(dt) -- потом UI, потому что нужно перехватить жесты и не пустить их дальше Tree.panning:update(dt) Tree.level:update(dt) + Tree.audio:update(dt) Tree.controls:cache()