From 14c36420a37678b75b30f3b4d1dec7eddb053eef Mon Sep 17 00:00:00 2001 From: Tom Barrett Date: Sun, 26 Mar 2017 06:46:12 -0500 Subject: -all organisms now in one list -plants do not reproduce yet, this is needed --- inc/constants.hpp | 7 +++--- inc/list.hpp | 4 +--- src/list.cpp | 66 +++++++++++++++++++++---------------------------------- src/main.cpp | 5 +---- 4 files changed, 30 insertions(+), 52 deletions(-) diff --git a/inc/constants.hpp b/inc/constants.hpp index 76a40c1..a9039bf 100644 --- a/inc/constants.hpp +++ b/inc/constants.hpp @@ -3,9 +3,8 @@ // General const int HERBAVORES = 100; -const int CARNIVORES = 50;; -const int MINIMUM_PLANTS = 4000; -const int PLANTS = 5000; +const int CARNIVORES = 5; +const int PLANTS = 3000; const int WINDOW_X = 1000; const int WINDOW_Y = 1000; const float BOUNDS = 30; @@ -43,7 +42,7 @@ const int NUM_UNIFORMS = 3; const float SIDES = 5; // Quadtree -const int MAX_OBJECTS = 5; +const int MAX_OBJECTS = 10; const int MAX_LEVELS = 20; // Camera diff --git a/inc/list.hpp b/inc/list.hpp index f43ba07..e2b94e5 100644 --- a/inc/list.hpp +++ b/inc/list.hpp @@ -19,11 +19,9 @@ class List std::vector getNear(Organism o); - std::list resources; - std::list creatures; + std::list organisms; Quadtree tree; - std::vector drawQuadTree(); }; #endif diff --git a/src/list.cpp b/src/list.cpp index 5904079..d93b38e 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -7,19 +7,19 @@ List::List() Rectangle tmp; for(i=0;i::iterator it = creatures.begin(); it!= creatures.end(); it++) + for(std::list::iterator it = organisms.begin(); it!= organisms.end(); it++) if(it->getHealth()<=0){ - DNA d = DNA(CORPSE_TYPE); - Organism X(it->getRectangle(), d); - resources.push_back(X); - creatures.erase(it--); + if(it->getType() == PLANT_TYPE or it->getType() == CORPSE_TYPE) + organisms.erase(it--); + else{ + DNA d = DNA(CORPSE_TYPE); + Organism X(it->getRectangle(), d); + organisms.push_back(X); + organisms.erase(it--); + } } - - for(std::list::iterator it = resources.begin(); it!= resources.end(); it++) - if(it->getHealth()<=0) - resources.erase(it--); } void List::Behavior() { - for(std::list::iterator it = creatures.begin(); it!= creatures.end(); it++){ - std::vector near = getNear(*it); - it->giveNearMe(near); - it->Behavior(); + for(std::list::iterator it = organisms.begin(); it!= organisms.end(); it++){ + if(it->getType() == PLANT_TYPE or it->getType() == CORPSE_TYPE) + it->grow(); + else{ + std::vector near = getNear(*it); + it->giveNearMe(near); + it->Behavior(); - if(it->getPregnancyReady()){ - Organism X(it->getRectangle(),it->getChildsDNA()); - creatures.push_back(X); - it->hadPregnancy(); + if(it->getPregnancyReady()){ + Organism X(it->getRectangle(),it->getChildsDNA()); + organisms.push_back(X); + it->hadPregnancy(); + } } } - - for(std::list::iterator it = resources.begin(); it!= resources.end(); it++) - it->grow(); } void List::Place() { tree.clear(); - Rectangle tmp; - DNA d = DNA(PLANT_TYPE); - while(resources.size() < MINIMUM_PLANTS){ - Organism X(tmp, d); - resources.push_back(X); - } - - for(std::list::iterator it = creatures.begin(); it!= creatures.end(); it++) + for(std::list::iterator it = organisms.begin(); it!= organisms.end(); it++) tree.insert(&(*it));; - - for(std::list::iterator it = resources.begin(); it!=resources.end(); it++) - tree.insert(&(*it));; - } std::vector List::getNear(Organism c) @@ -89,9 +79,3 @@ std::vector List::getNear(Organism c) return near; } - -std::vector List::drawQuadTree() -{ - return tree.Draw(); -} - diff --git a/src/main.cpp b/src/main.cpp index cacd612..d42ca9d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -46,11 +46,8 @@ int main() shader.Bind(); _spriteBatch.begin(); - - for(std::list::iterator it = L.creatures.begin(); it != L.creatures.end(); it++) - _spriteBatch.draw(it->getRectangle(),it->getVisuals()); - for(std::list::iterator it = L.resources.begin(); it != L.resources.end(); it++) + for(std::list::iterator it = L.organisms.begin(); it != L.organisms.end(); it++) _spriteBatch.draw(it->getRectangle(),it->getVisuals()); _spriteBatch.end(); -- cgit v1.2.3