we can move under another (closest!!!!!!!!!) character
cool!!!!
This commit is contained in:
parent
8ad68f914d
commit
9489cd0488
@ -8,3 +8,4 @@ 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"
|
||||||
|
|||||||
77
lib/character/behaviors/ai.lua
Normal file
77
lib/character/behaviors/ai.lua
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
local AnimationNode = require "lib.animation_node"
|
||||||
|
|
||||||
|
--- @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 caster = Vec3 {}
|
||||||
|
self.owner:try(Tree.behaviors.positioned, function(b)
|
||||||
|
caster = b.position
|
||||||
|
end)
|
||||||
|
local target = Vec3 {}
|
||||||
|
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
|
||||||
|
target = b.position
|
||||||
|
charTarget = v
|
||||||
|
end
|
||||||
|
-- print(k, b.position)
|
||||||
|
end)
|
||||||
|
break
|
||||||
|
end
|
||||||
|
-- print(target)
|
||||||
|
charTarget:try(Tree.behaviors.positioned, function(b)
|
||||||
|
target = Vec3 { target.x, target.y + 1 } --- @todo тут захардкожено + 1, но мы должны как-то хитро определять с какой стороны обойти
|
||||||
|
end)
|
||||||
|
spellB.spellbook[1]:cast(self.owner, target)
|
||||||
|
-- print(minDist, target)
|
||||||
|
end
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
self.animationNode:run()
|
||||||
|
end)
|
||||||
|
end
|
||||||
|
|
||||||
|
return behavior
|
||||||
@ -106,6 +106,9 @@ 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()
|
||||||
@ -176,7 +179,7 @@ function attack:cast(caster, target)
|
|||||||
volume = 1,
|
volume = 1,
|
||||||
lowgain = 0.1
|
lowgain = 0.1
|
||||||
}
|
}
|
||||||
Tree.audio:play(audioPath.sounds.hurt, settings)
|
Tree.audio:play(audioPath.sounds.hurt)
|
||||||
end
|
end
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -199,6 +202,7 @@ 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
|
||||||
|
|||||||
5
main.lua
5
main.lua
@ -26,12 +26,13 @@ function love.load()
|
|||||||
character.spawn("Baris")
|
character.spawn("Baris")
|
||||||
:addBehavior {
|
:addBehavior {
|
||||||
Tree.behaviors.residentsleeper.new(),
|
Tree.behaviors.residentsleeper.new(),
|
||||||
Tree.behaviors.stats.new(nil, nil, 1),
|
Tree.behaviors.stats.new(nil, nil, 2),
|
||||||
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