From 1da46794f74ebd8f445fcd70cbe0420eadb648e4 Mon Sep 17 00:00:00 2001 From: tom Date: Sun, 12 Feb 2017 07:57:21 -0600 Subject: -removed grouping --- README.md | 3 ++- inc/creature.hpp | 7 ++++--- inc/list.hpp | 3 ++- src/creature.cpp | 9 ++++++--- src/list.cpp | 6 +++--- 5 files changed, 17 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 520df5d..a27a79d 100644 --- a/README.md +++ b/README.md @@ -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 -#include +#include +#include #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 n){N = n;}; + void giveN(std::vector 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 N; + std::vectorN; 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 #include +#include #include "functions.hpp" #include "creature.hpp" @@ -17,7 +18,7 @@ class List void Behavior(); void Place(); void Remove(); - std::list getNear(Creature C); + std::vector 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 ::iterator it = N.begin(); it!=N.end(); it++){ + std::random_shuffle(N.begin(),N.end()); + for(std::vector ::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 ::iterator it = N.begin(); it!=N.end(); it++) + for(std::vector ::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::iterator it = C.begin(); it!=C.end(); it++){ - std::list N = getNear(*it); + std::vector N = getNear(*it); it->giveN(N); it->Behavior(); @@ -71,9 +71,9 @@ void List::Place() it->Place(); } -std::list List::getNear(Creature nC) +std::vector List::getNear(Creature nC) { - std::list N; + std::vector N; for(std::list::iterator it = R.begin(); it!=R.end(); it++) if( nC.getBestSense() > Distance(nC.getRect(),it->getRect()) ) -- cgit v1.2.3