summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortom <tom@ground-control>2015-05-07 12:35:15 -0500
committertom <tom@ground-control>2015-05-07 12:35:15 -0500
commitffcee12acf3fe3f972f322c18b3203212682205d (patch)
treeac300fa0808b8f6218669e3f14b1d0b784bc7055
parente91f0c208605f27d2ba9e2a9c584c92212ab0088 (diff)
woo! detection is implemented albeit shitty
-rw-r--r--inc/creature.hpp4
-rw-r--r--inc/list.hpp1
-rw-r--r--inc/location.hpp8
-rw-r--r--src/creature.cpp38
-rw-r--r--src/list.cpp21
-rw-r--r--src/main.cpp2
6 files changed, 53 insertions, 21 deletions
diff --git a/inc/creature.hpp b/inc/creature.hpp
index f72dfbc..a0046fb 100644
--- a/inc/creature.hpp
+++ b/inc/creature.hpp
@@ -10,14 +10,16 @@ class Creature: public Entity
Creature(Window m, std::string s);
void Behavior();
void Action();
+ void Priority();
Location getLocation();
+ void giveKnown(std::vector<Location> Z){K=Z;};
private:
int xT;
int yT;
int hp;
int hu;
- Location K[3];
+ std::vector<Location> K;
};
#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index 203ad7f..96509aa 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -12,6 +12,7 @@ class List
List(Window m);
void Behavior();
void Place();
+ double Distance(Location A, Location B);
private:
//Window main;
diff --git a/inc/location.hpp b/inc/location.hpp
index 2042734..6a20b4e 100644
--- a/inc/location.hpp
+++ b/inc/location.hpp
@@ -5,11 +5,9 @@ class Location
{
public:
Location(){x=y=t=0;};
- Location(int x, int y, int z){};
- int getType(){return t;};
-
- private:
- int x;
+ Location(int x1, int y1, int t1){x=x1;y=y1;t=t1;};
+
+ int x;
int y;
int t;
};
diff --git a/src/creature.cpp b/src/creature.cpp
index 9d50291..ae3122b 100644
--- a/src/creature.cpp
+++ b/src/creature.cpp
@@ -9,30 +9,29 @@ Creature::Creature(Window m, std::string s)
int zy = rand()%800;
int zx = rand()%1200;
- y=zy;
- x=zx;
+ y=yT=zy;
+ x=xT=zx;
//std::cout << x << ' ' << y << std::endl;
-
+
//For the test resource
- xT=yT=300;
+ //xT=yT=300;
}
void Creature::Behavior()
{
hp--;
- //Detection
-
-
- //Priorities
+ //Detection
- //Action
- this->Action();
+ //Priorities
+ this->Priority();
+ //Action
+ this->Action();
}
void Creature::Action()
{
//std::cout << (sqrt(((x-xT)^2)+((y-yT)^2));
- if((sqrt(((x-xT)^2)+((y-yT)^2)))<2)
+ if(sqrt(pow(x-xT,2)+pow(y-yT,2))<2)
return; //eat//reproduce//etc;
if(x==xT)
@@ -76,7 +75,7 @@ void Creature::Action()
}
}
- /*
+ /*
else
{
int z = rand()%2;
@@ -98,6 +97,21 @@ void Creature::Action()
*/
}
+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);
diff --git a/src/list.cpp b/src/list.cpp
index c3246c9..2612d3e 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -19,10 +19,20 @@ List::List(Window m)
void List::Behavior()
{
- int i;
+ int i, j;
+ std::vector<Location> Z;
+
for(i = 0; i < C.size(); i++)
{
C[i].Behavior();
+ for(j = 0; j < L.size(); j++)
+ if(200>(Distance(C[i].getLocation(),L[j])))
+ {
+ Z.push_back(L[j]);
+ }
+
+ C[i].giveKnown(Z);
+ Z.clear();
}
}
@@ -31,7 +41,7 @@ void List::Place()
int i;
for(i = 0;i < L.size(); i++)
- if(L.getType()==1)
+ if(L[i].t==1)
L.erase(L.begin()+i);
for(i = 0; i < C.size(); i++)
@@ -45,3 +55,10 @@ void List::Place()
R[i].Place();
}
}
+
+double List::Distance(Location A, Location B)
+{
+ double z = sqrt(pow(A.x-B.x,2)+pow(A.y-B.y,2));
+ //std::cout << z << "\n";
+ return z;
+}
diff --git a/src/main.cpp b/src/main.cpp
index 1dec02c..1e8424a 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -22,7 +22,7 @@ int main()
L.Behavior();
main.Render();
- SDL_Delay(5);
+ SDL_Delay(15);
}
main.Destroy();