suck my ass stupid animations, im done
This commit is contained in:
parent
d36b67855a
commit
ac03a014f6
BIN
assets/audio/music/level1/battle.ogg
Normal file
BIN
assets/audio/music/level1/battle.ogg
Normal file
Binary file not shown.
BIN
assets/audio/music/level1/choral.ogg
Normal file
BIN
assets/audio/music/level1/choral.ogg
Normal file
Binary file not shown.
@ -1,18 +1,87 @@
|
||||
local ease = require "lib.utils.easing"
|
||||
local AnimationNode = require "lib.animation_node"
|
||||
|
||||
--- @class Audio
|
||||
--- @field musicVolume number
|
||||
--- @field soundVolume number
|
||||
audio = {}
|
||||
audio.__index = audio
|
||||
|
||||
local function new(musicVolume, soundVolume) -- здесь мы должны выгружать значения из файлика с сохранением настроек
|
||||
--- здесь мы должны выгружать значения из файлика с сохранением настроек
|
||||
local function new(musicVolume, soundVolume)
|
||||
return setmetatable({
|
||||
musicVolume = musicVolume,
|
||||
soundVolume = soundVolume
|
||||
}, audio)
|
||||
end
|
||||
|
||||
function audio:crossfade()
|
||||
|
||||
--- if from is nil, than we have fade in to;
|
||||
--- if to is nil, than we have fade out from
|
||||
---
|
||||
--- 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
|
||||
function audio:crossfade(from, to, ms)
|
||||
to:setVolume(0)
|
||||
to:play()
|
||||
local fromVol = from:getVolume() or self.musicVolume
|
||||
local toVol = to:getVolume() or self.musicVolume
|
||||
local dt = love.timer.getDelta() * (ms or 1000)
|
||||
|
||||
while fromVol > 0 and toVol < self.musicVolume do
|
||||
print(fromVol, toVol)
|
||||
fromVol = self.musicVolume - fromVol + dt / self.musicVolume
|
||||
from:setVolume(ease.easeOutQuad(fromVol))
|
||||
toVol = toVol + dt / self.musicVolume
|
||||
to:setVolume(ease.easeInQuad(toVol))
|
||||
print(fromVol, toVol)
|
||||
end
|
||||
end
|
||||
|
||||
--- if from is nil, than we have fade in to;
|
||||
--- if to is nil, than we have fade out from
|
||||
---
|
||||
--- 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
|
||||
function audio:crossfadeAnim(from, to, ms)
|
||||
to:setVolume(0)
|
||||
to:play()
|
||||
print(from:getVolume(), to:getVolume())
|
||||
local t = 0
|
||||
local anim = AnimationNode {
|
||||
function(node)
|
||||
from:setVolume(self.musicVolume - node:getValue() * self.musicVolume)
|
||||
to:setVolume(node:getValue() * self.musicVolume)
|
||||
t = node.t
|
||||
print(node.finished, node.duration, node.t)
|
||||
end,
|
||||
onEnd = function()
|
||||
from:setVolume(0)
|
||||
to:setVolume(self.musicVolume)
|
||||
end,
|
||||
duration = ms or 1000,
|
||||
easing = ease.linear,
|
||||
-- children = {
|
||||
-- AnimationNode {
|
||||
-- function(node)
|
||||
-- from:setVolume(self.musicVolume - node:getValue() * self.musicVolume)
|
||||
-- end
|
||||
-- },
|
||||
-- AnimationNode {
|
||||
-- function(node)
|
||||
-- to:setVolume(node:getValue() * self.musicVolume)
|
||||
-- print(node.count)
|
||||
-- end
|
||||
-- }
|
||||
-- }
|
||||
}
|
||||
anim:run()
|
||||
anim:finish()
|
||||
print(from:getVolume(), to:getVolume(), t, t, t)
|
||||
end
|
||||
|
||||
--- @param source love.Source
|
||||
|
||||
@ -18,6 +18,9 @@ local path = nil
|
||||
local function new(type, template)
|
||||
local size = Vec3 { 30, 30 } -- magic numbers for testing purposes only
|
||||
print(type, template, size)
|
||||
|
||||
Tree.audio:play(Tree.assets.files.audio.music.level1.battle)
|
||||
|
||||
return setmetatable({
|
||||
size = size,
|
||||
characters = {},
|
||||
|
||||
@ -88,7 +88,10 @@ function regenerateMana:cast(caster, target)
|
||||
if not sprite then return true end
|
||||
AnimationNode {
|
||||
function(node)
|
||||
local audioPath = Tree.assets.files.audio
|
||||
sprite:animate("hurt", node)
|
||||
Tree.audio:crossfadeAnim(audioPath.music.level1.battle,
|
||||
audioPath.music.level1.choral, 3000)
|
||||
end,
|
||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
||||
}:run()
|
||||
@ -143,9 +146,10 @@ function attack:cast(caster, target)
|
||||
children = {
|
||||
AnimationNode {
|
||||
function(node)
|
||||
local audioPath = Tree.assets.files.audio
|
||||
targetSprite:animate("hurt", node)
|
||||
-- Tree.assets.files.audio.sounds.hurt:play()
|
||||
Tree.audio:play(Tree.assets.files.audio.sounds.hurt)
|
||||
Tree.audio:play(audioPath.sounds.hurt)
|
||||
end
|
||||
}
|
||||
}
|
||||
|
||||
@ -8,6 +8,7 @@ Tree = {
|
||||
}
|
||||
Tree.panning = require "lib/panning"
|
||||
Tree.controls = require "lib.controls"
|
||||
Tree.audio = (require "lib.audio").new(1, 1)
|
||||
Tree.level = (require "lib.level.level").new("procedural", "flower_plains") -- для теста у нас только один уровень, который сразу же загружен
|
||||
|
||||
Tree.behaviors = (require "lib.utils.behavior_loader")("lib/character/behaviors") --- @todo написать нормальную загрузку поведений
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user