From 11c5d147b845d4323f2e94c1ac47b6001420d8e6 Mon Sep 17 00:00:00 2001 From: tom Date: Thu, 19 Jan 2017 13:33:46 -0600 Subject: -added entity growing -added bite functionality for creature/resource -added gender (next largest feature is reproduction) -refractored creature setTarget function to make more sense -added constants for starting size of entity and max size of entity -refractored list to make make much more sense -added constants for types --- src/list.cpp | 61 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 32 insertions(+), 29 deletions(-) (limited to 'src/list.cpp') diff --git a/src/list.cpp b/src/list.cpp index 3127d76..5309109 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -5,13 +5,13 @@ List::List(Window m) main = m; int i; - SDL_Rect Rect = {0,0,CREATURE_SIZE,CREATURE_SIZE}; + SDL_Rect Rect = {0,0,CREATURE_SIZE_START,CREATURE_SIZE_START}; for(i=0;i::iterator it = C.begin(); it!=C.end(); it++) - it->Place(); - - for(list::iterator it = R.begin(); it!=R.end(); it++){ - if(it->getAmount()<=0) - R.erase(it--); - else - it->Place(); - } +void List::Remove() +{ + for(list::iterator it = C.begin(); it!=C.end(); it++) + if(it->getHealth()<=0){ + SDL_Rect Rect = it->getRect(); + Resource r = Resource(main,Rect); + R.push_back(r); + C.erase(it--); + } + + for(list::iterator it = R.begin(); it!=R.end(); it++) + if(it->getAmount()<=0) + R.erase(it--); } void List::Behavior() { for(list::iterator it = C.begin(); it!=C.end(); it++){ - list N = getNear(*it); it->giveN(N); - it->Behavior(); - - if(it->getHealth()<=0){ - SDL_Rect Rect = it->getRect(); - Resource r = Resource(main,Rect); - R.push_back(r); - C.erase(it--); - } } + + for(list::iterator it = R.begin(); it!=R.end(); it++) + it->grow(); +} - SDL_Rect Rect = {0,0,RESOURCE_SIZE,RESOURCE_SIZE}; +void List::Place() +{ + SDL_Rect Rect = {0,0,RESOURCE_SIZE_START,RESOURCE_SIZE_START}; while(R.size() < MINIMUM_RESOURCES){ Resource Y(main,Rect); R.push_back(Y); } + + for(list::iterator it = C.begin(); it!=C.end(); it++) + it->Place(); + + for(list::iterator it = R.begin(); it!=R.end(); it++) + it->Place(); } list List::getNear(Creature nC) { list N; - for(list ::iterator it = R.begin(); it!=R.end(); it++){ + for(list ::iterator it = R.begin(); it!=R.end(); it++) if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) ) N.push_back(&(*it)); - } - - for(list ::iterator it = C.begin(); it!=C.end(); it++){ + + for(list ::iterator it = C.begin(); it!=C.end(); it++) if( &nC == &(*it)) continue; else if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) ) N.push_back(&(*it)); - } - + return N; } -- cgit v1.2.3