From 7394b069537ed7a490a343381d62862eb22abdcf Mon Sep 17 00:00:00 2001 From: majortom6 Date: Sun, 26 Feb 2017 11:14:31 -0600 Subject: -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 --- inc/constants.hpp | 17 +++++-------- inc/creature.hpp | 51 ------------------------------------- inc/dna.hpp | 11 +++++--- inc/entity.hpp | 32 ----------------------- inc/list.hpp | 15 ++++++----- inc/opengl/spritebatch.hpp | 6 ++--- inc/organism.hpp | 63 ++++++++++++++++++++++++++++++++++++++++++++++ inc/quadtree.hpp | 10 +++----- inc/resource.hpp | 24 ------------------ 9 files changed, 90 insertions(+), 139 deletions(-) delete mode 100644 inc/creature.hpp delete mode 100644 inc/entity.hpp create mode 100644 inc/organism.hpp delete mode 100644 inc/resource.hpp (limited to 'inc') 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 -#include - -#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 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 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 + #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 #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 getNear(Creature c); + std::vector getNear(Organism o); - std::list resources; - std::list creatures; + std::list resources; + std::list creatures; Quadtree tree; std::vector 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 +#include #include + #include "graphicsdata.hpp" -#include #include "geoshader.hpp" -#include - 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 +#include + +#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 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 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 #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 retrieve(std::vector returnObject, GraphicsData obj); - std::vector objects; + std::vector retrieve(std::vector returnObject, GraphicsData obj); + std::vector 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 - -#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 -- cgit v1.2.3