Compare commits
No commits in common. "d48f1af1afd3b1032ae13dbe3c002588eb5d4e2c" and "8ad68f914df42815d470f78e259d05eccc0dcc0f" have entirely different histories.
d48f1af1af
...
8ad68f914d
@ -8,4 +8,3 @@ Tree.behaviors.light = require "character.behaviors.light"
|
|||||||
Tree.behaviors.positioned = require "character.behaviors.positioned"
|
Tree.behaviors.positioned = require "character.behaviors.positioned"
|
||||||
Tree.behaviors.tiled = require "character.behaviors.tiled"
|
Tree.behaviors.tiled = require "character.behaviors.tiled"
|
||||||
Tree.behaviors.cursor = require "character.behaviors.cursor"
|
Tree.behaviors.cursor = require "character.behaviors.cursor"
|
||||||
Tree.behaviors.ai = require "lib.character.behaviors.ai"
|
|
||||||
|
|||||||
@ -1,78 +0,0 @@
|
|||||||
local AnimationNode = require "lib.animation_node"
|
|
||||||
|
|
||||||
local function closestCharacter(char)
|
|
||||||
local caster = Vec3 {}
|
|
||||||
char:try(Tree.behaviors.positioned, function(b)
|
|
||||||
caster = b.position
|
|
||||||
end)
|
|
||||||
local charTarget
|
|
||||||
local minDist = 88005553535 -- spooky magic number
|
|
||||||
for k, v in pairs(Tree.level.characters) do
|
|
||||||
v:try(Tree.behaviors.positioned, function(b)
|
|
||||||
local dist = ((caster.x - b.position.x) ^ 2 + (caster.y - b.position.y) ^ 2) ^ 0.5
|
|
||||||
if dist < minDist and dist ~= 0 then
|
|
||||||
minDist = dist
|
|
||||||
charTarget = v
|
|
||||||
end
|
|
||||||
-- print(k, b.position)
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
return charTarget
|
|
||||||
end
|
|
||||||
|
|
||||||
--- @class AIBehavior : Behavior
|
|
||||||
--- @field animationNode AnimationNode?
|
|
||||||
local behavior = {}
|
|
||||||
behavior.__index = behavior
|
|
||||||
behavior.id = "ai"
|
|
||||||
|
|
||||||
function behavior.new()
|
|
||||||
return setmetatable({}, behavior)
|
|
||||||
end
|
|
||||||
|
|
||||||
function behavior:update(dt)
|
|
||||||
self.owner:try(Tree.behaviors.spellcaster, function(b)
|
|
||||||
if b.state == "casting" then
|
|
||||||
b.cast:update(self.owner, dt)
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
if self.animationNode and self.animationNode.state == "running" then
|
|
||||||
self.animationNode:update(dt)
|
|
||||||
-- print(self.animationNode.t)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
function behavior:draw()
|
|
||||||
self.owner:try(Tree.behaviors.spellcaster, function(b)
|
|
||||||
if b.state == "casting" then
|
|
||||||
b.cast:draw()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
function behavior:makeMove()
|
|
||||||
self.owner:try(Tree.behaviors.spellcaster, function(spellB)
|
|
||||||
-- print('какещке')
|
|
||||||
self.animationNode = AnimationNode {
|
|
||||||
function(node) end,
|
|
||||||
onEnd = function()
|
|
||||||
-- print('kakeshke')
|
|
||||||
end,
|
|
||||||
children = {
|
|
||||||
AnimationNode {
|
|
||||||
function(node)
|
|
||||||
local charTarget = closestCharacter(self.owner)
|
|
||||||
local target
|
|
||||||
charTarget:try(Tree.behaviors.positioned, function(b)
|
|
||||||
target = Vec3 { b.position.x, b.position.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
|
|
||||||
end)
|
|
||||||
spellB.spellbook[1]:cast(self.owner, target)
|
|
||||||
end
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
self.animationNode:run()
|
|
||||||
end)
|
|
||||||
end
|
|
||||||
|
|
||||||
return behavior
|
|
||||||
@ -106,9 +106,6 @@ function regenerateMana:cast(caster, target)
|
|||||||
sprite:animate("hurt", node)
|
sprite:animate("hurt", node)
|
||||||
Tree.audio:crossfade(audioPath.music.level1.battle,
|
Tree.audio:crossfade(audioPath.music.level1.battle,
|
||||||
audioPath.music.level1.choral, 5000)
|
audioPath.music.level1.choral, 5000)
|
||||||
caster:try(Tree.behaviors.ai, function(b)
|
|
||||||
b:makeMove()
|
|
||||||
end)
|
|
||||||
end,
|
end,
|
||||||
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
onEnd = function() caster:has(Tree.behaviors.spellcaster):endCast() end
|
||||||
}:run()
|
}:run()
|
||||||
@ -179,7 +176,7 @@ function attack:cast(caster, target)
|
|||||||
volume = 1,
|
volume = 1,
|
||||||
lowgain = 0.1
|
lowgain = 0.1
|
||||||
}
|
}
|
||||||
Tree.audio:play(audioPath.sounds.hurt)
|
Tree.audio:play(audioPath.sounds.hurt, settings)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -202,7 +199,6 @@ local spellbook = {
|
|||||||
function spellbook.of(list)
|
function spellbook.of(list)
|
||||||
local spb = {}
|
local spb = {}
|
||||||
for i, sp in ipairs(list) do
|
for i, sp in ipairs(list) do
|
||||||
print(i)
|
|
||||||
spb[i] = setmetatable({}, { __index = sp })
|
spb[i] = setmetatable({}, { __index = sp })
|
||||||
end
|
end
|
||||||
return spb
|
return spb
|
||||||
|
|||||||
25
main.lua
25
main.lua
@ -23,36 +23,15 @@ function love.load()
|
|||||||
Tree.behaviors.shadowcaster.new(),
|
Tree.behaviors.shadowcaster.new(),
|
||||||
Tree.behaviors.spellcaster.new()
|
Tree.behaviors.spellcaster.new()
|
||||||
},
|
},
|
||||||
character.spawn("Foodor")
|
|
||||||
:addBehavior {
|
|
||||||
Tree.behaviors.residentsleeper.new(),
|
|
||||||
Tree.behaviors.stats.new(nil, nil, 1),
|
|
||||||
Tree.behaviors.positioned.new(Vec3 { 4, 3 }),
|
|
||||||
Tree.behaviors.tiled.new(),
|
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
|
||||||
Tree.behaviors.shadowcaster.new(),
|
|
||||||
Tree.behaviors.spellcaster.new()
|
|
||||||
},
|
|
||||||
character.spawn("Foodor")
|
|
||||||
:addBehavior {
|
|
||||||
Tree.behaviors.residentsleeper.new(),
|
|
||||||
Tree.behaviors.stats.new(nil, nil, 1),
|
|
||||||
Tree.behaviors.positioned.new(Vec3 { 5, 3 }),
|
|
||||||
Tree.behaviors.tiled.new(),
|
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
|
||||||
Tree.behaviors.shadowcaster.new(),
|
|
||||||
Tree.behaviors.spellcaster.new()
|
|
||||||
},
|
|
||||||
character.spawn("Baris")
|
character.spawn("Baris")
|
||||||
:addBehavior {
|
:addBehavior {
|
||||||
Tree.behaviors.residentsleeper.new(),
|
Tree.behaviors.residentsleeper.new(),
|
||||||
Tree.behaviors.stats.new(nil, nil, 2),
|
Tree.behaviors.stats.new(nil, nil, 1),
|
||||||
Tree.behaviors.positioned.new(Vec3 { 5, 5 }),
|
Tree.behaviors.positioned.new(Vec3 { 5, 5 }),
|
||||||
Tree.behaviors.tiled.new(),
|
Tree.behaviors.tiled.new(),
|
||||||
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
Tree.behaviors.sprite.new(Tree.assets.files.sprites.character),
|
||||||
Tree.behaviors.shadowcaster.new(),
|
Tree.behaviors.shadowcaster.new(),
|
||||||
Tree.behaviors.spellcaster.new(),
|
Tree.behaviors.spellcaster.new()
|
||||||
Tree.behaviors.ai.new()
|
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user