From 6b967f3bd7a3e7203b57bd9e4edb0db82bc9ed1c Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 26 May 2015 14:04:04 -0500 Subject: revamped the list and creatures two bugs i can see right now -somehow when a resource has less than 0 amount it still sticks around (somewhat rare) -some creatures just bounce back and forth until they die not getting to their target --- src/list.cpp | 79 +++++++++++++++--------------------------------------------- 1 file changed, 19 insertions(+), 60 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index cd69f8f..93d2312 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -4,18 +4,16 @@ List::List(Window m) //Constructor { int i; - for(i=0;i<10;i++) + for(i=0;i<25;i++) { 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++) + for(i=0;i<100;i++) { Resource Y(m,"img/Rbasic.png"); R.push_back(Y); - L.push_back(Y.getLocation()); } main = m; @@ -23,73 +21,34 @@ List::List(Window m) //Constructor void List::Place() { - int i; - - //if any locations are creatures, erases them from vector L - for(i = 0;i < L.size(); i++) - 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 each creature on window + for(vector::iterator it = C.begin(); it!=C.end(); it++) + it->Place(); //places all resources - for(i = 0; i < R.size(); i++) + for(int j = 0; j Z; - - for(i = 0; i < C.size(); i++) + for(int i = 0; i(Distance(C[i].getLocation(),L[j]))) - Z.push_back(L[j]); + vector N; - C[i].giveKnown(Z); //sets creature's target location? - Z.clear(); //clear vector Z for next creature + for(int j = 0; j < R.size(); j++) + if(250>Distance(C[i].getLocation(),R[j].getLocation())) + N.push_back(&R[j]); + + C[i].give(N); + N.clear(); // This kills the creature if(C[i].getHealth()<=0) -- cgit v1.2.3