summaryrefslogtreecommitdiff
path: root/src/creature.cpp
blob: ae3122b5085733316398efe35f5b8b02ef71aef1 (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
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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#include "creature.hpp"

Creature::Creature(Window m, std::string s)
{
	texture = loadTexture(s, m);
	renderer = m.getRenderer();
	hp = 100;
	hu = 0;

	int zy = rand()%800;
	int zx = rand()%1200;
	y=yT=zy;
	x=xT=zx;
	//std::cout << x << ' ' <<  y << std::endl;

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

void Creature::Behavior()
{
	hp--;
  //Detection

  //Priorities
	this->Priority();
  //Action
  this->Action();
}

void Creature::Action()
{
	//std::cout << (sqrt(((x-xT)^2)+((y-yT)^2));
	if(sqrt(pow(x-xT,2)+pow(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 if(x<xT)
	{
		if(y<yT)
		{
			x++;
			y++;
		}
		else
		{
			x++;
			y--;
		}
	}
	else if (x>xT)
	{
		if(y<yT)
		{
			x--;
			y++;
		}
		else
		{
			x--;
			y--;
		}
	}

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

void Creature::Priority()
{
	int i;
	for(i=0;i<K.size();i++)
	{
		std::cout << K[i].t;
		if(K[i].t==2)
		{
			xT = K[i].x;
			yT = K[i].y;
			std::cout << xT << "IN\n";
		}
	}
}

Location Creature::getLocation()
{
	Location L(x,y,1);
	return L;
}