From ffcee12acf3fe3f972f322c18b3203212682205d Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 7 May 2015 12:35:15 -0500 Subject: woo! detection is implemented albeit shitty --- src/creature.cpp | 38 ++++++++++++++++++++++++++------------ src/list.cpp | 21 +++++++++++++++++++-- src/main.cpp | 2 +- 3 files changed, 46 insertions(+), 15 deletions(-) (limited to 'src') 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 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(); -- cgit v1.2.3