diff options
author | Tom Barrett <tombarrett@cornell.engr.siu.edu> | 2015-05-08 10:14:42 -0500 |
---|---|---|
committer | Tom Barrett <tombarrett@cornell.engr.siu.edu> | 2015-05-08 10:14:42 -0500 |
commit | 39d7fe95633baafe4539f604186b151f30401a39 (patch) | |
tree | 242d91eafe56a15db046a1068d8e970624c6abfd /src/list.cpp | |
parent | 76e10e651906b756c4482274cdf1d8ccb686b915 (diff) | |
parent | 8c5121486a0e5d94ae5e5ee67370a31530cf8b6f (diff) |
Merge branch 'master' of http://github.com/majortom6/natures
Diffstat (limited to 'src/list.cpp')
-rw-r--r-- | src/list.cpp | 48 |
1 files changed, 35 insertions, 13 deletions
diff --git a/src/list.cpp b/src/list.cpp index c3246c9..2140a75 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -1,14 +1,16 @@ #include "list.hpp" -List::List(Window m) +List::List(Window m) //Constructor { int i; - for(i=0;i<5;i++) + + for(i=0;i<10;i++) { - Creature X = Creature(m,"img/Cbasic.png"); + Creature X(m,"img/Cbasic.png"); C.push_back(X); } + //Creates 5 resources, inserts them into vector R; inserts locations of resources into vector L for(i=0;i<5;i++) { Resource Y(m,"img/Rbasic.png"); @@ -17,31 +19,51 @@ List::List(Window m) } } -void List::Behavior() -{ - int i; - for(i = 0; i < C.size(); i++) - { - C[i].Behavior(); - } -} - void List::Place() { int i; + //if any locations are creatures, erases them from vector L for(i = 0;i < L.size(); i++) - if(L.getType()==1) + if(L[i].type==1) L.erase(L.begin()+i); + //places each creature on window, inserts their locations into vector L for(i = 0; i < C.size(); i++) { C[i].Place(); L.push_back(C[i].getLocation()); } + //places all resources for(i = 0; i < R.size(); i++) { R[i].Place(); } } + +void List::Behavior() +{ + int i, j; + std::vector<Location> Z; + + // + for(i = 0; i < C.size(); i++) + { + C[i].Behavior(); //executes the behavior of the creature at i + for(j = 0; j < L.size(); j++) + if(200>(Distance(C[i].getLocation(),L[j]))) //if the distance between the creature and L[j] is less than 200, insert L[j] into vector Z. + { + Z.push_back(L[j]); + } + + C[i].giveKnown(Z); //sets creature's target location? + Z.clear(); //clear vector Z for next creature + } +} + +double List::Distance(Location A, Location B) +{ + //computes distance between two points + return sqrt(pow(A.x - B.x, 2) + pow(A.y - B.y, 2)); +} |