diff options
| author | tom <tombarrett@siu.edu> | 2017-02-12 07:57:21 -0600 | 
|---|---|---|
| committer | tom <tombarrett@siu.edu> | 2017-02-12 07:57:21 -0600 | 
| commit | 1da46794f74ebd8f445fcd70cbe0420eadb648e4 (patch) | |
| tree | fee655a50188e50b7c63d6b855bc671e0a1b0128 | |
| parent | 358ea01c03d787377ef88945706f350befd5b7a9 (diff) | |
-removed grouping
| -rw-r--r-- | README.md | 3 | ||||
| -rw-r--r-- | inc/creature.hpp | 7 | ||||
| -rw-r--r-- | inc/list.hpp | 3 | ||||
| -rw-r--r-- | src/creature.cpp | 9 | ||||
| -rw-r--r-- | src/list.cpp | 6 | 
5 files changed, 17 insertions, 11 deletions
| @@ -11,5 +11,6 @@ ideas  - click to add entities  - randomly generate new types of creatures  - gui speed up / down -- all traits (speed, reach, size, etc) contained in DNA structure which is mixed with mate and passed to child +- DNA which is mixed with mate and passed to child  - pick a c naming/coding standard and stick with it +- show framerate in gui diff --git a/inc/creature.hpp b/inc/creature.hpp index 95b1329..c3ed2d8 100644 --- a/inc/creature.hpp +++ b/inc/creature.hpp @@ -2,7 +2,8 @@  #define creature_h  #include <SDL2/SDL.h> -#include <list> +#include <vector> +#include <algorithm>  #include "entity.hpp"  #include "constants.hpp" @@ -20,7 +21,7 @@ class Creature: public Entity      void    checkTarget();      void    Move(SDL_Rect R);      void    impregnate(); -    void    giveN(std::list<Entity*> n){N = n;}; +    void    giveN(std::vector<Entity*> n){N = n;};      Dna     getDNA(){return mine;};      int     getHealth(){return health;}; @@ -32,7 +33,7 @@ class Creature: public Entity    private:      SDL_Rect            wTarget;      Entity              *target; -    std::list<Entity*>  N; +    std::vector<Entity*>N;      Dna                 mine;      int     health;  diff --git a/inc/list.hpp b/inc/list.hpp index 7d3d8a2..64b3ec5 100644 --- a/inc/list.hpp +++ b/inc/list.hpp @@ -3,6 +3,7 @@  #include <SDL2/SDL.h>  #include <list> +#include <vector>  #include "functions.hpp"  #include "creature.hpp" @@ -17,7 +18,7 @@ class List  		void Behavior();  		void Place();          void Remove(); -        std::list<Entity*> getNear(Creature C); +        std::vector<Entity*> getNear(Creature C);  	private:  		Window main = Window("do not create new window."); diff --git a/src/creature.cpp b/src/creature.cpp index 7a86af9..0b7a438 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -14,8 +14,11 @@ Creature::Creature(Window M, SDL_Rect R, Dna D)      type            = CREATURE_TYPE;      health          = mine.maxHealth/2;      gender          = rand() % 2; +    age             = 0; +    pregnancyTime   = 0;      able            = true;      pregnancyReady  = false; +    pregnate        = false;  }  void Creature::Behavior() @@ -56,7 +59,8 @@ void Creature::Priority()  void Creature::setTarget()  { -    for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++){ +    std::random_shuffle(N.begin(),N.end()); +    for(std::vector <Entity*>::iterator it = N.begin(); it!=N.end(); it++){          if( (*it)->getType() == RESOURCE_TYPE && hungry){               target = *it;              hasTarget = true; @@ -80,12 +84,11 @@ void Creature::setTarget()  void Creature::checkTarget()  { -    for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++) +    for(std::vector <Entity*>::iterator it = N.begin(); it!=N.end(); it++)          if( target == *it )              return;      hasTarget = false; -    return;  } diff --git a/src/list.cpp b/src/list.cpp index edf3063..0439278 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -38,7 +38,7 @@ void List::Remove()  void List::Behavior()  {      for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++){ -        std::list<Entity*> N = getNear(*it);  +        std::vector<Entity*> N = getNear(*it);           it->giveN(N);           it->Behavior(); @@ -71,9 +71,9 @@ void List::Place()          it->Place();  } -std::list<Entity*> List::getNear(Creature nC) +std::vector<Entity*> List::getNear(Creature nC)  { -    std::list<Entity*> N; +    std::vector<Entity*> N;      for(std::list<Resource>::iterator it = R.begin(); it!=R.end(); it++)          if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) ) | 
