summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormajortom6 <tombarrett@siu.edu>2017-02-26 11:14:31 -0600
committerTom Barrett <tombarrett@siu.edu>2017-03-07 13:23:42 -0600
commit7394b069537ed7a490a343381d62862eb22abdcf (patch)
treec8bff4f88cf962ec4148a2e133bf959035feedb7
parente54170cfb8c0fb99ecdc3b1e57e832dec58ee76e (diff)
-REMOVED ENTITY, RESOURCE, AND CREATURE !
-replaced them all with one class, organism (always subject to change) -the dna type now is what differs creatures and resources -removed dead constants -may be a rogue segfault -also weird artifacts start showing if running long
-rw-r--r--inc/constants.hpp17
-rw-r--r--inc/creature.hpp51
-rw-r--r--inc/dna.hpp11
-rw-r--r--inc/entity.hpp32
-rw-r--r--inc/list.hpp15
-rw-r--r--inc/opengl/spritebatch.hpp6
-rw-r--r--inc/organism.hpp63
-rw-r--r--inc/quadtree.hpp10
-rw-r--r--inc/resource.hpp24
-rw-r--r--src/dna.cpp57
-rw-r--r--src/entity.cpp7
-rw-r--r--src/list.cpp50
-rw-r--r--src/main.cpp4
-rw-r--r--src/organism.cpp (renamed from src/creature.cpp)64
-rw-r--r--src/quadtree.cpp8
-rw-r--r--src/resource.cpp30
16 files changed, 198 insertions, 251 deletions
diff --git a/inc/constants.hpp b/inc/constants.hpp
index dc0ddec..ce4c3ff 100644
--- a/inc/constants.hpp
+++ b/inc/constants.hpp
@@ -14,28 +14,23 @@ const int RESOURCE_TYPE = 2;
// Creatures
const int CREATURE_MAX_HEALTH = 1000;
-const int CREATURE_REACH = 1;
-const int CREATURE_BEST_SENSE = 1;
+const int CREATURE_BEST_SENSE = 2;
const int CREATURE_BITE = 10;
-const int CREATURE_AMOUNT_TO_GROW = 50;
const int CREATURE_EXP_PREG_TIME = 100;
-const int CREATURE_EXP_AGE = 1000000;
-const int CREATURE_SIZE_MAX = 10;
+const int CREATURE_EXP_AGE = 1000;
const float CREATURE_SPEED = .1;
const float CREATURE_MUTATION_PERCENT = .25;
const float CREATURE_MUTATION_CHANCE = .05;
+const float CREATURE_REACH = .1;
// Resource
-const int RESOURCE_SIZE_START = 1;
-const int RESOURCE_SIZE_MAX = 4;
-const int RESOURCE_AMOUNT_START = 100;
-const int RESOURCE_AMOUNT_MAX = 200;
-const int RESOURCE_GROW = 1;
+const int RESOURCE_MAX_HEALTH = 200;
+const int RESOURCE_GROW_AMOUNT = 1;
// Opengl
const int NUM_SHADERS = 3;
const int NUM_UNIFORMS = 3;
-const float CREATURE_SIDES = 4.0;
+const float CREATURE_SIDES = 4;
const float RESOURCE_SIDES = 10;
// Quadtree
diff --git a/inc/creature.hpp b/inc/creature.hpp
deleted file mode 100644
index 8174cf6..0000000
--- a/inc/creature.hpp
+++ /dev/null
@@ -1,51 +0,0 @@
-#ifndef creature_h
-#define creature_h
-
-#include <vector>
-#include <algorithm>
-
-#include "entity.hpp"
-#include "functions.hpp"
-
-class Creature: public Entity
-{
- public:
- Creature(Rectangle r, DNA d);
-
- void Behavior();
- void Action();
- void Priority();
- void setTarget();
- void checkTarget();
- void moveTowards(Rectangle r);
- void impregnate(DNA d);
- void giveNearMe(std::vector<Entity*> n){nearMe = n;};
-
- DNA getDNA(){return myDNA;};
- DNA getChildsDNA(){return childsDNA;};
- int getHealth(){return health;};
- int getBestSense(){return myDNA.bestSense;};
- bool getGender(){return gender;};
- bool getPregnancyReady(){return pregnancyReady;};
- void hadPregnancy(){pregnate = pregnancyReady = false;};
-
- private:
- Rectangle wTarget;
- Entity* target;
- std::vector<Entity*> nearMe;
- DNA myDNA;
- DNA childsDNA;
-
- int health;
- int amountAte;
- int pregnancyTime;
- int age;
-
- bool hungry;
- bool pregnancyReady;
- bool able;
- bool hasTarget;
- bool wander;
-};
-
-#endif
diff --git a/inc/dna.hpp b/inc/dna.hpp
index b549c27..8c4effa 100644
--- a/inc/dna.hpp
+++ b/inc/dna.hpp
@@ -1,25 +1,28 @@
#ifndef dna_h
#define dna_h
+#include <string>
+
#include "constants.hpp"
#include "functions.hpp"
class DNA
{
public:
- DNA();
+ DNA(){};
+ DNA(std::string s);
DNA combine(DNA D);
+ int type;
int maxHealth;
- int reach;
int bestSense;
int bite;
- int amountToGrow;
int expectedPregnancyTime;
int expectedAge;
- int sizeMax;
+ int growAmount;
+ float reach;
float speed;
float mutationPercent;
float mutationChance;
diff --git a/inc/entity.hpp b/inc/entity.hpp
deleted file mode 100644
index 20c87aa..0000000
--- a/inc/entity.hpp
+++ /dev/null
@@ -1,32 +0,0 @@
-#ifndef entity_h
-#define entity_h
-
-#include "dna.hpp"
-#include "rectangle.hpp"
-
-#include "opengl/graphicsdata.hpp"
-
-class Entity
-{
- public:
- void Place();
-
- virtual void eat(int bite){};
- virtual void impregnate(DNA D){};
-
- int getType(){return type;};
- virtual bool getGender(void){};
- virtual int getAmount(void){};
- Rectangle getRectangle(){return rect;};
- GraphicsData getGFXD(){return gfxData;};
-
-
- protected:
- int type;
- int gender;
- bool pregnate;
- Rectangle rect;
- GraphicsData gfxData;
-};
-
-#endif
diff --git a/inc/list.hpp b/inc/list.hpp
index f62112c..93a0537 100644
--- a/inc/list.hpp
+++ b/inc/list.hpp
@@ -5,22 +5,21 @@
#include <vector>
#include "constants.hpp"
-#include "creature.hpp"
-#include "resource.hpp"
+#include "organism.hpp"
#include "quadtree.hpp"
class List
{
public:
List();
- void Behavior();
- void Place();
- void Remove();
+ void Behavior();
+ void Place();
+ void Remove();
- std::vector<Entity*> getNear(Creature c);
+ std::vector<Organism*> getNear(Organism o);
- std::list<Resource> resources;
- std::list<Creature> creatures;
+ std::list<Organism> resources;
+ std::list<Organism> creatures;
Quadtree tree;
std::vector<GraphicsData> drawQuadTree();
diff --git a/inc/opengl/spritebatch.hpp b/inc/opengl/spritebatch.hpp
index 2618054..63e45eb 100644
--- a/inc/opengl/spritebatch.hpp
+++ b/inc/opengl/spritebatch.hpp
@@ -1,12 +1,12 @@
#ifndef spritebatch_h
#define spritebatch_h
+#include <iostream>
+#include <vector>
#include <GL/glew.h>
+
#include "graphicsdata.hpp"
-#include <vector>
#include "geoshader.hpp"
-#include <iostream>
-
class RenderBatch {
public:
diff --git a/inc/organism.hpp b/inc/organism.hpp
new file mode 100644
index 0000000..9534fbb
--- /dev/null
+++ b/inc/organism.hpp
@@ -0,0 +1,63 @@
+#ifndef organism_h
+#define organism_h
+
+#include <vector>
+#include <algorithm>
+
+#include "dna.hpp"
+#include "rectangle.hpp"
+#include "functions.hpp"
+
+#include "opengl/graphicsdata.hpp"
+
+class Organism
+{
+ public:
+ Organism(Rectangle r, DNA d);
+
+ void Behavior();
+ void Action();
+ void Priority();
+ void Place();
+ void setTarget();
+ void checkTarget();
+ void moveTowards(Rectangle r);
+ void passDNA(DNA d);
+ void giveNearMe(std::vector<Organism*> n){nearMe = n;};
+ void grow();
+ void takeBite(int bite);
+ void hadPregnancy(){pregnate = pregnancyReady = false;};
+
+ DNA getDNA() {return myDNA;};
+ DNA getChildsDNA() {return childsDNA;};
+ GraphicsData getGFXD() {return gfxData;};
+ Rectangle getRectangle() {return rect;};
+ int getHealth() {return health;};
+ int getBestSense() {return myDNA.bestSense;};
+ int getType() {return myDNA.type;};
+ bool getGender() {return gender;};
+ bool getPregnancyReady() {return pregnancyReady;};
+
+ private:
+ Rectangle wTarget;
+ Organism* target;
+ std::vector<Organism*> nearMe;
+ DNA myDNA;
+ DNA childsDNA;
+ Rectangle rect;
+ GraphicsData gfxData;
+
+ int health;
+ int pregnancyTime;
+ int age;
+
+ bool gender;
+ bool pregnate;
+ bool hungry;
+ bool pregnancyReady;
+ bool able;
+ bool hasTarget;
+ bool wander;
+};
+
+#endif
diff --git a/inc/quadtree.hpp b/inc/quadtree.hpp
index bf308f8..8520584 100644
--- a/inc/quadtree.hpp
+++ b/inc/quadtree.hpp
@@ -4,9 +4,7 @@
#include <vector>
#include "constants.hpp"
-#include "creature.hpp"
-#include "resource.hpp"
-#include "entity.hpp"
+#include "organism.hpp"
#include "rectangle.hpp"
#include "opengl/graphicsdata.hpp"
@@ -18,10 +16,10 @@ class Quadtree {
Quadtree(int pLevel,Rectangle pBounds);
void clear();
- void insert(Entity* iter);
+ void insert(Organism* iter);
- std::vector<Entity*> retrieve(std::vector<Entity*> returnObject, GraphicsData obj);
- std::vector<Entity*> objects;
+ std::vector<Organism*> retrieve(std::vector<Organism*> returnObject, GraphicsData obj);
+ std::vector<Organism*> objects;
Quadtree* nodes;
diff --git a/inc/resource.hpp b/inc/resource.hpp
deleted file mode 100644
index e559463..0000000
--- a/inc/resource.hpp
+++ /dev/null
@@ -1,24 +0,0 @@
-#ifndef resource_h
-#define resource_h
-
-#include <cstdlib>
-
-#include "entity.hpp"
-#include "functions.hpp"
-
-class Resource: public Entity
-{
- public:
- Resource(Rectangle r);
-
- void grow();
- void eat(int bite);
-
- int getAmount(){return amount;};
-
- private:
- int amount;
- int growAmount;
-};
-
-#endif
diff --git a/src/dna.cpp b/src/dna.cpp
index 5d3fc8f..5d727d2 100644
--- a/src/dna.cpp
+++ b/src/dna.cpp
@@ -1,33 +1,46 @@
#include "dna.hpp"
-DNA::DNA()
+DNA::DNA(std::string s)
{
- maxHealth = CREATURE_MAX_HEALTH;
- speed = CREATURE_SPEED;
- reach = CREATURE_REACH;
- bestSense = CREATURE_BEST_SENSE;
- bite = CREATURE_BITE;
- amountToGrow = CREATURE_AMOUNT_TO_GROW;
- expectedPregnancyTime = CREATURE_EXP_PREG_TIME;
- expectedAge = CREATURE_EXP_AGE;
- sizeMax = CREATURE_SIZE_MAX;
- mutationPercent = CREATURE_MUTATION_PERCENT;
- mutationChance = CREATURE_MUTATION_CHANCE;
+ if(s == "creature"){
+ type = CREATURE_TYPE;
+ maxHealth = CREATURE_MAX_HEALTH;
+ bestSense = CREATURE_BEST_SENSE;
+ bite = CREATURE_BITE;
+ expectedPregnancyTime = CREATURE_EXP_PREG_TIME;
+ expectedAge = CREATURE_EXP_AGE;
+ growAmount = 0;
+ reach = CREATURE_REACH;
+ speed = CREATURE_SPEED;
+ mutationPercent = CREATURE_MUTATION_PERCENT;
+ mutationChance = CREATURE_MUTATION_CHANCE;
+ }
+ else if(s == "resource"){
+ type = RESOURCE_TYPE;
+ maxHealth = RESOURCE_MAX_HEALTH;
+ bestSense = 0;
+ bite = 0;
+ expectedPregnancyTime = 0;
+ expectedAge = 0;
+ growAmount = RESOURCE_GROW_AMOUNT;
+ reach = 0;
+ speed = 0;
+ mutationPercent = 0;
+ mutationChance = 0;
+ }
}
DNA DNA::combine(DNA D)
{
- DNA N;
-
+ DNA N("empty");
+ N.type = CREATURE_TYPE;
N.maxHealth = (maxHealth + D.maxHealth)/2;
N.speed = (speed + D.speed)/2;
N.reach = (reach + D.reach)/2;
N.bestSense = (bestSense + D.bestSense)/2;
N.bite = (bite + D.bite)/2;
- N.amountToGrow = (amountToGrow + D.amountToGrow)/2;
N.expectedPregnancyTime = (expectedPregnancyTime + D.expectedPregnancyTime)/2;
N.expectedAge = (expectedAge + D.expectedAge)/2;
- N.sizeMax = (sizeMax + D.sizeMax)/2;
N.mutationPercent = (mutationPercent + D.mutationPercent)/2;
N.mutationChance = (mutationChance + D.mutationChance)/2;
@@ -37,18 +50,16 @@ DNA DNA::combine(DNA D)
pn = 1;
else
pn = -1;
- switch(rand()%11){
+ switch(rand()%9){
case 0: N.maxHealth = abs(N.maxHealth *(N.mutationPercent+pn)); break;
case 1: N.speed = abs(N.speed *(N.mutationPercent+pn)); break;
case 2: N.reach = abs(N.reach *(N.mutationPercent+pn)); break;
case 3: N.bestSense = abs(N.bestSense *(N.mutationPercent+pn)); break;
case 4: N.bite = abs(N.bite *(N.mutationPercent+pn)); break;
- case 5: N.amountToGrow = abs(N.amountToGrow *(N.mutationPercent+pn)); break;
- case 6: N.expectedPregnancyTime = abs(N.expectedPregnancyTime *(N.mutationPercent+pn)); break;
- case 7: N.expectedAge = abs(N.expectedAge *(N.mutationPercent+pn)); break;
- case 8: N.sizeMax = abs(N.sizeMax *(N.mutationPercent+pn)); break;
- case 9: N.mutationPercent = abs(N.expectedAge *(N.mutationPercent+pn)); break;
- case 10:N.mutationChance = abs(N.mutationChance *(N.mutationPercent+pn)); break;
+ case 5: N.expectedPregnancyTime = abs(N.expectedPregnancyTime *(N.mutationPercent+pn)); break;
+ case 6: N.expectedAge = abs(N.expectedAge *(N.mutationPercent+pn)); break;
+ case 7: N.mutationPercent = abs(N.expectedAge *(N.mutationPercent+pn)); break;
+ case 8: N.mutationChance = abs(N.mutationChance *(N.mutationPercent+pn)); break;
}
}
return N;
diff --git a/src/entity.cpp b/src/entity.cpp
deleted file mode 100644
index ab94d23..0000000
--- a/src/entity.cpp
+++ /dev/null
@@ -1,7 +0,0 @@
-#include "entity.hpp"
-
-void Entity::Place()
-{
- gfxData.x = rect.x;
- gfxData.y = rect.y;
-}
diff --git a/src/list.cpp b/src/list.cpp
index 30b0eb1..826208e 100644
--- a/src/list.cpp
+++ b/src/list.cpp
@@ -3,16 +3,17 @@
List::List()
{
int i;
- DNA d;
+ DNA d = DNA("creature");
Rectangle tmp;
for(i=0;i<CREATURES;i++){
- Creature X(tmp,d);
+ Organism X(tmp,d);
creatures.push_back(X);
}
-
+
+ d = DNA("resource");
for(i=0;i<RESOURCES;i++){
- Resource Y(tmp);
- resources.push_back(Y);
+ Organism X(tmp, d);
+ resources.push_back(X);
}
Rectangle R1 = Rectangle(0,0,60,60);
@@ -21,33 +22,34 @@ List::List()
void List::Remove()
{
- for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++)
+ for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++)
if(it->getHealth()<=0){
- Resource Y(it->getRectangle());
- resources.push_back(Y);
+ DNA d = DNA("resource");
+ Organism X(it->getRectangle(), d);
+ resources.push_back(X);
creatures.erase(it--);
}
- for(std::list<Resource>::iterator it = resources.begin(); it!= resources.end(); it++)
- if(it->getAmount()<=0)
+ for(std::list<Organism>::iterator it = resources.begin(); it!= resources.end(); it++)
+ if(it->getHealth()<=0)
resources.erase(it--);
}
void List::Behavior()
{
- for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++){
- std::vector<Entity*> N = getNear(*it);
- it->giveNearMe(N);
+ for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++){
+ std::vector<Organism*> near = getNear(*it);
+ it->giveNearMe(near);
it->Behavior();
if(it->getPregnancyReady()){
- Creature X(it->getRectangle(),it->getChildsDNA());
+ Organism X(it->getRectangle(),it->getChildsDNA());
creatures.push_back(X);
it->hadPregnancy();
}
}
- for(std::list<Resource>::iterator it = resources.begin(); it!= resources.end(); it++)
+ for(std::list<Organism>::iterator it = resources.begin(); it!= resources.end(); it++)
it->grow();
}
@@ -56,35 +58,37 @@ void List::Place()
tree.clear();
Rectangle tmp;
+ DNA d = DNA("resource");
while(resources.size() < MINIMUM_RESOURCES){
- Resource Y(tmp);
- resources.push_back(Y);
+ Organism X(tmp, d);
+ resources.push_back(X);
}
- for(std::list<Creature>::iterator it = creatures.begin(); it!= creatures.end(); it++){
+ for(std::list<Organism>::iterator it = creatures.begin(); it!= creatures.end(); it++){
it->Place();
tree.insert(&(*it));;
}
- for(std::list<Resource>::iterator it = resources.begin(); it!=resources.end(); it++){
+ for(std::list<Organism>::iterator it = resources.begin(); it!=resources.end(); it++){
it->Place();
tree.insert(&(*it));;
}
}
-std::vector<Entity*> List::getNear(Creature c)
+std::vector<Organism*> List::getNear(Organism c)
{
- std::vector<Entity*> near;
+ std::vector<Organism*> near;
near = tree.retrieve(near, c.getGFXD());
- for(std::vector<Entity*>::iterator it = near.begin(); it!= near.end(); it++)
+ for(std::vector<Organism*>::iterator it = near.begin(); it!= near.end(); it++)
if(c.getBestSense() < Distance(c.getRectangle(),(*it)->getRectangle()))
near.erase(it--);
return near;
}
-std::vector<GraphicsData> List::drawQuadTree(){
+std::vector<GraphicsData> List::drawQuadTree()
+{
return tree.Draw();
}
diff --git a/src/main.cpp b/src/main.cpp
index d5a192d..43ec1e4 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -47,10 +47,10 @@ int main()
shader.Bind();
_spriteBatch.begin();
- for(std::list<Creature>::iterator it = L.creatures.begin(); it != L.creatures.end(); it++)
+ for(std::list<Organism>::iterator it = L.creatures.begin(); it != L.creatures.end(); it++)
_spriteBatch.draw(it->getGFXD());
- for(std::list<Resource>::iterator it = L.resources.begin(); it != L.resources.end(); it++)
+ for(std::list<Organism>::iterator it = L.resources.begin(); it != L.resources.end(); it++)
_spriteBatch.draw(it->getGFXD());
_spriteBatch.end();
diff --git a/src/creature.cpp b/src/organism.cpp
index 9cfdacb..27f6f8a 100644
--- a/src/creature.cpp
+++ b/src/organism.cpp
@@ -1,6 +1,6 @@
-#include "creature.hpp"
+#include "organism.hpp"
-Creature::Creature(Rectangle r, DNA d)
+Organism::Organism(Rectangle r, DNA d)
{
rect = r;
myDNA = d;
@@ -10,7 +10,6 @@ Creature::Creature(Rectangle r, DNA d)
rect.y = getRandom(30);
}
- type = CREATURE_TYPE;
health = myDNA.maxHealth/2;
gender = rand() % 2;
age = 0;
@@ -18,14 +17,19 @@ Creature::Creature(Rectangle r, DNA d)
pregnancyReady = false;
pregnate = false;
hasTarget = false;
+ wander = false;
- if(gender)
- gfxData = GraphicsData(rect.x, rect.y, 1, 0, 0, CREATURE_SIDES);
+ if(myDNA.type == CREATURE_TYPE){
+ if(gender)
+ gfxData = GraphicsData(rect.x, rect.y, 1, 0, 0, CREATURE_SIDES);
+ else
+ gfxData = GraphicsData(rect.x, rect.y, 0, 0, 1, CREATURE_SIDES);
+ }
else
- gfxData = GraphicsData(rect.x, rect.y, 0, 0, 1, CREATURE_SIDES);
+ gfxData = GraphicsData(rect.x, rect.y, 0, 1, 0, RESOURCE_SIDES);
}
-void Creature::Behavior()
+void Organism::Behavior()
{
health-=1;
@@ -49,7 +53,7 @@ void Creature::Behavior()
health = 0;
}
-void Creature::Priority()
+void Organism::Priority()
{
if(health < myDNA.maxHealth / 2){
hungry = true;
@@ -61,11 +65,11 @@ void Creature::Priority()
}
}
-void Creature::setTarget()
+void Organism::setTarget()
{
std::random_shuffle(nearMe.begin(),nearMe.end());
- for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){
+ for(std::vector<Organism*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){
if( (*it)->getType() == RESOURCE_TYPE && hungry){
target = *it;
hasTarget = true;
@@ -82,16 +86,14 @@ void Creature::setTarget()
if(!hasTarget&&!wander){
wander = true;
- Rectangle tmp;
- tmp.x = getRandom(30);
- tmp.y = getRandom(30);
+ Rectangle tmp(getRandom(30),getRandom(30),0,0);
wTarget = tmp;
}
}
-void Creature::checkTarget()
+void Organism::checkTarget()
{
- for(std::vector <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++)
+ for(std::vector<Organism*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++)
if( target == *it )
return;
@@ -99,20 +101,19 @@ void Creature::checkTarget()
}
-void Creature::Action()
+void Organism::Action()
{
if(hasTarget){
if(Distance(rect,target->getRectangle()) < myDNA.reach){
if(target->getType() == RESOURCE_TYPE){
- target->eat(myDNA.bite);
+ target->takeBite(myDNA.bite);
health+=myDNA.bite;
- amountAte++;
- if(target->getAmount()<=0)
+ if(target->getHealth()<=0)
hasTarget = false;
}
else if (target->getType() == CREATURE_TYPE){
if(target->getGender() != gender){
- target->impregnate(myDNA);
+ target->passDNA(myDNA);
}
hasTarget = false;
}
@@ -129,7 +130,7 @@ void Creature::Action()
}
}
-void Creature::moveTowards(Rectangle t)
+void Organism::moveTowards(Rectangle t)
{
if( rect.x == t.x ){
if( rect.y < t.y )
@@ -165,11 +166,28 @@ void Creature::moveTowards(Rectangle t)
}
}
-void Creature::impregnate(DNA D)
+void Organism::passDNA(DNA d)
{
if(!pregnate){
pregnate = true;
pregnancyTime = 0;
- childsDNA = myDNA.combine(D);
+ childsDNA = myDNA.combine(d);
}
}
+
+void Organism::grow()
+{
+ if(health < myDNA.maxHealth)
+ health+=myDNA.growAmount;
+}
+
+void Organism::takeBite(int bite)
+{
+ health-=bite;
+}
+
+void Organism::Place()
+{
+ gfxData.x = rect.x;
+ gfxData.y = rect.y;
+}
diff --git a/src/quadtree.cpp b/src/quadtree.cpp
index 909c875..ada839a 100644
--- a/src/quadtree.cpp
+++ b/src/quadtree.cpp
@@ -76,7 +76,7 @@ int Quadtree::getIndex(GraphicsData object) {
return index;
}
-void Quadtree::insert(Entity* iter){
+void Quadtree::insert(Organism* iter){
if (!nodes[0].isNull) {
int index = getIndex((*iter).getGFXD());
if (index != -1) {
@@ -92,7 +92,7 @@ void Quadtree::insert(Entity* iter){
split();
int index;
- for(std::vector<Entity*>::iterator it = objects.begin(); it!=objects.end();it++){
+ for(std::vector<Organism*>::iterator it = objects.begin(); it!=objects.end();it++){
index = getIndex((*it)->getGFXD());
if (index != -1) {
nodes[index].insert(*it);
@@ -126,12 +126,12 @@ std::vector<GraphicsData> Quadtree::Draw(){
return retdat;
}
-std::vector<Entity*> Quadtree::retrieve(std::vector<Entity*> returnObjects, GraphicsData obj) {
+std::vector<Organism*> Quadtree::retrieve(std::vector<Organism*> returnObjects, GraphicsData obj) {
int index = getIndex(obj);
if (index != -1 && !nodes[0].isNull)
returnObjects = nodes[index].retrieve(returnObjects, obj);
- for(std::vector<Entity*>::iterator it = objects.begin(); it!=objects.end(); it++)
+ for(std::vector<Organism*>::iterator it = objects.begin(); it!=objects.end(); it++)
returnObjects.emplace_back(*it);
return returnObjects;
diff --git a/src/resource.cpp b/src/resource.cpp
deleted file mode 100644
index c3e61d6..0000000
--- a/src/resource.cpp
+++ /dev/null
@@ -1,30 +0,0 @@
-#include "resource.hpp"
-
-Resource::Resource(Rectangle r)
-{
- rect = r;
-
- if(rect.x == 0 && rect.y == 0){
- rect.x = getRandom(30);
- rect.y = getRandom(30);
- }
-
- gfxData = GraphicsData(rect.x, rect.y, 0, 1, 0, RESOURCE_SIDES);
-
- type = RESOURCE_TYPE;
- amount = RESOURCE_AMOUNT_START;
- growAmount = RESOURCE_GROW;
-}
-
-void Resource::eat(int bite)
-{
- amount-=bite;
-}
-
-void Resource::grow()
-{
- if(amount < RESOURCE_AMOUNT_MAX){
- amount+=growAmount;
- rect.h = rect.w = map(amount,0,RESOURCE_AMOUNT_MAX,0,RESOURCE_SIZE_MAX);
- }
-}