-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGoHomeAI.cs
48 lines (42 loc) · 1.03 KB
/
GoHomeAI.cs
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
using System;
namespace room
{
class GoHomeAI : AI
{
public int TargetX { get; set; }
public int TargetY { get; set; }
public GoHomeAI(int targetX, int targetY)
{
TargetX = targetX;
TargetY = targetY;
}
public void Think(World w, Mob m)
{
int x = m.X;
int y = m.Y;
// Get Player direction and walk one step toward.
if (m.X > TargetX)
x--;
if (m.X < TargetX)
x++;
if (m.Y > TargetY)
y--;
if (m.Y < TargetY)
y++;
if (w.CanWalk(x, y))
{
m.X = x;
m.Y = y;
}
if (x == TargetX && y == TargetY)
{
m.CurrentAI = new Wander();
m.Color = ConsoleColor.Green;
}
else if (w.DistanceToPlayer(x, y) < 3)
{
m.Aggro();
}
}
}
}