summaryrefslogtreecommitdiff
path: root/src/creature.cpp
blob: aeff472423cb0d54d2686c37be61dce069bdc9c1 (plain)
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
#include "creature.hpp"

Creature::Creature(Window m, std::string s)
{
	texture = loadTexture(s, m);
	renderer = m.getRenderer();
	x=y=500;

	//For the test resource
	xT=yT=300;
}

void Creature::Behavior()
{
  //Detection

  //Priorities

	//Action
	this->Action();
}

void Creature::Action()
{
	//std::cout << (sqrt(((x-xT)^2)+((y-yT)^2));
	if((sqrt(((x-xT)^2)+((y-yT)^2)))<2)
		return; //eat//reproduce//etc;

	if(x==xT)
		if(y<yT)
			y++;
		else
			y--;
	else if(y==yT)
		if(x<xT)
			x++;
		else
			x--;
	else
	{
		int z = rand()%2;
		if(z)
		{
			if(x<xT)
				x++;
			else
				x--;
		}
		else
		{
			if(y<xT)
				y++;
			else
				y--;
		}
	}
}