-
Notifications
You must be signed in to change notification settings - Fork 0
/
yama_ai.lua
85 lines (64 loc) · 1.43 KB
/
yama_ai.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
local ai = {}
function ai.new()
local public = {}
local private = {}
public.direction = 0
public.speed = 0
local behaviours = {attack = false, patrol = true, guard = false}
local behaviour = {}
behaviour.current = nil
local goal = nil
local aim = 0
-- UPDATE
function public.update(x, y)
if behaviour.current then
public[behaviour.current].update(x, y)
goal = public[behaviour.current].goal
public.speed = public[behaviour.current].speed
else
goal = nil
end
--if behaviours.attack then
--public.updateAttack()
--elseif behaviours.patrol then
-- public.patrol.update(x, y)
-- goal = public.patrol.goal
-- public.speed = public.patrol.public.speed
--elseif behaviours.guard then
--public.updateGuard()
--end
if goal then
public.direction = math.atan2(goal[2]-y, goal[1]-x)
public.speed = 1
end
end
-- BEHAVRIOURS
-- BEHAVIOUR: PATROL
--dofile("yama_ai_patrol.lua")
public.patrol = yama.ai.patrols.new()
function public.patrol.getPoint()
return public.patrol.v.x, public.patrol.v.y
end
function public.patrol.isActive()
if public.patrol.v then
return truepatrol
else
return false
end
end
-- INPUT
function public.setBehaviour(aBehaviour)
if public[aBehaviour] then
behaviour.current = aBehaviour
end
end
-- OUTPUT
function public.getDirection()
return public.direction
end
function public.getSpeed()
return public.speed
end
return public
end
return ai