diff options
-rw-r--r-- | inc/camera.hpp | 57 | ||||
-rw-r--r-- | inc/constants.hpp | 27 | ||||
-rw-r--r-- | inc/creature.hpp | 76 | ||||
-rw-r--r-- | inc/dna.hpp | 29 | ||||
-rw-r--r-- | inc/entity.hpp | 36 | ||||
-rw-r--r-- | inc/event.hpp | 15 | ||||
-rw-r--r-- | inc/functions.hpp | 8 | ||||
-rw-r--r-- | inc/geoshader.hpp | 30 | ||||
-rw-r--r-- | inc/graphicsobjects.hpp | 149 | ||||
-rw-r--r-- | inc/list.hpp | 1 | ||||
-rw-r--r-- | inc/quadtree.hpp | 1 | ||||
-rw-r--r-- | inc/rectangle.hpp | 15 | ||||
-rw-r--r-- | inc/resource.hpp | 2 | ||||
-rw-r--r-- | src/creature.cpp | 64 | ||||
-rw-r--r-- | src/dna.cpp | 6 | ||||
-rw-r--r-- | src/list.cpp | 15 | ||||
-rw-r--r-- | src/main.cpp | 4 | ||||
-rw-r--r-- | src/quadtree.cpp | 18 | ||||
-rw-r--r-- | src/resource.cpp | 2 |
19 files changed, 245 insertions, 310 deletions
diff --git a/inc/camera.hpp b/inc/camera.hpp new file mode 100644 index 0000000..62ae837 --- /dev/null +++ b/inc/camera.hpp @@ -0,0 +1,57 @@ +#ifndef camera_h +#define camera_h + +struct Camera +{ + public: + Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar){ + this->pos = pos; + this->forward = glm::vec3(0.0f, 0.0f, -1.0f); + this->up = glm::vec3(0.0f, 1.0f, 0.0f); + this->projection = glm::perspective(fov, aspect, zNear, zFar); + } + + inline glm::mat4 GetViewProjection() const { + return projection * glm::lookAt(pos, pos + forward, up); + } + + void MoveForward(){ + pos += forward * amt; + } + + void MoveBackward(){ + pos += forward * -amt; + } + + void MoveRight(){ + pos += -glm::cross(up, forward) * amt; + } + + void MoveLeft(){ + pos += glm::cross(up, forward) * amt; + } + + void MoveUp(){ + pos += glm::vec3(0,.2,0); + } + + void MoveDown(){ + pos -= glm::vec3(0,.2,0); + } + + void Pitch(float angle){ + glm::vec3 right = glm::normalize(glm::cross(up, forward)); + + forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0))); + up = glm::normalize(glm::cross(forward, right)); + } + + private: + float amt = .2; + glm::mat4 projection; + glm::vec3 pos; + glm::vec3 forward; + glm::vec3 up; +}; + +#endif diff --git a/inc/constants.hpp b/inc/constants.hpp index 646d987..7d53134 100644 --- a/inc/constants.hpp +++ b/inc/constants.hpp @@ -1,14 +1,14 @@ #ifndef constants_h #define constants_h -const int CREATURES = 10; -const int RESOURCES = 100; -const int MINIMUM_RESOURCES = 800; -const int WINDOW_X = 1000; -const int WINDOW_Y = 1000; +const int CREATURES = 10; +const int RESOURCES = 100; +const int MINIMUM_RESOURCES = 800; +const int WINDOW_X = 1000; +const int WINDOW_Y = 1000; -const int CREATURE_TYPE = 1; -const int RESOURCE_TYPE = 2; +const int CREATURE_TYPE = 1; +const int RESOURCE_TYPE = 2; const int CREATURE_MAX_HEALTH = 1000; const int CREATURE_REACH = 1; @@ -20,10 +20,13 @@ const int CREATURE_EXP_AGE = 1000000; const int CREATURE_SIZE_MAX = 10; const float CREATURE_SPEED = .1; -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_SIZE_STAR = 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 NUM_SHADERS = 3; +const int NUM_UNIFORMS = 3; #endif diff --git a/inc/creature.hpp b/inc/creature.hpp index 1bc6f49..99226b3 100644 --- a/inc/creature.hpp +++ b/inc/creature.hpp @@ -2,53 +2,51 @@ #define creature_h #include <SDL2/SDL.h> -#include <vector> #include <list> -#include <algorithm> #include "entity.hpp" -#include "constants.hpp" #include "functions.hpp" #include "dna.hpp" class Creature: public Entity { - public: - Creature(Location t, Dna D); - void Behavior(); - void Action(); - void Priority(); - void setTarget(); - void checkTarget(); - void moveTowards(Location t); - void impregnate(Dna D); - void giveN(std::list<Entity*> n){N = n;}; - - Dna getDNA(){return mine;}; - Dna getChildDNA(){return childs;}; - int getHealth(){return health;}; - int getBestSense(){return mine.bestSense;}; - bool getGender(){return gender;}; - bool getPregnancyReady(){return pregnancyReady;}; - void hadPregnancy(){pregnate = pregnancyReady = false;}; - - private: - Location wTarget; - Entity *target; - std::list<Entity*> N; - Dna mine; - Dna childs; - - int health; - int amountAte; - int pregnancyTime; - int age; - - bool hungry; - bool pregnancyReady; - bool able; - bool hasTarget; - bool wander; + public: + Creature(Rectangle t, DNA D); + + void Behavior(); + void Action(); + void Priority(); + void setTarget(); + void checkTarget(); + void moveTowards(Rectangle t); + void impregnate(DNA D); + void giveNearMe(std::list<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::list<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 dc46b64..d7312f6 100644 --- a/inc/dna.hpp +++ b/inc/dna.hpp @@ -3,20 +3,23 @@ #include "constants.hpp" -class Dna +class DNA { - public: - Dna(); - Dna combine(Dna D); - int maxHealth; - float speed; - int reach; - int bestSense; - int bite; - int amountToGrow; - int expectedPregnancyTime; - int expectedAge; - int sizeMax; + public: + DNA(); + + DNA combine(DNA D); + + int maxHealth; + int reach; + int bestSense; + int bite; + int amountToGrow; + int expectedPregnancyTime; + int expectedAge; + int sizeMax; + + float speed; }; #endif diff --git a/inc/entity.hpp b/inc/entity.hpp index 50f9b06..259849f 100644 --- a/inc/entity.hpp +++ b/inc/entity.hpp @@ -5,27 +5,29 @@ #include "dna.hpp" #include "graphicsobjects.hpp" +#include "rectangle.hpp" class Entity { - public: - void Place(); - - int getType(){return type;}; - virtual bool getGender(void){}; - virtual int getAmount(void){}; - Location getLocation(){return L;}; - - virtual void eat(int bite){}; - virtual void impregnate(Dna D){}; - GraphicsData getGFXD(){return gfxData;}; - GraphicsData gfxData; + public: + void Place(); + + virtual void eat(int bite){}; + virtual void impregnate(DNA D){}; - protected: - int type; - int gender; - bool pregnate; - Location L; + int getType(){return type;}; + virtual bool getGender(void){}; + virtual int getAmount(void){}; + Rectangle getRectangle(){return L;}; + GraphicsData getGFXD(){return gfxData;}; + + + protected: + int type; + int gender; + bool pregnate; + Rectangle L; + GraphicsData gfxData; }; #endif diff --git a/inc/event.hpp b/inc/event.hpp index c1d528e..3a0a868 100644 --- a/inc/event.hpp +++ b/inc/event.hpp @@ -5,13 +5,14 @@ class Event { - public: - Event(); - int Poll(); - void off(); - bool gRun(); - SDL_Event& gEvent(); - int gEventType(); + public: + Event(); + + int Poll(); + void off(); + bool gRun(); + SDL_Event& gEvent(); + int gEventType(); private: bool run; diff --git a/inc/functions.hpp b/inc/functions.hpp index ce072e2..15cb94a 100644 --- a/inc/functions.hpp +++ b/inc/functions.hpp @@ -1,14 +1,14 @@ #ifndef functions_h #define functions_h -#include "graphicsobjects.hpp" +#include "rectangle.hpp" -static double Distance(Location A, Location B){ - return sqrt( pow(A.x-B.x,2) + pow(A.y-B.y,2)); +static double Distance(Rectangle A, Rectangle B){ + return sqrt(pow(A.x-B.x,2) + pow(A.y-B.y,2)); } static int map(int x, int inMin, int inMax, int outMin, int outMax){ - return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin; + return (x-inMin) * (outMax - outMin) / (inMax - inMin) + outMin; } #endif diff --git a/inc/geoshader.hpp b/inc/geoshader.hpp index f8be43b..65e2fc3 100644 --- a/inc/geoshader.hpp +++ b/inc/geoshader.hpp @@ -3,29 +3,27 @@ #include <string>
#include <GL/glew.h>
-#include "graphicsobjects.hpp"
-//#define GLSL(src) "#version 150 core\n" #src
+#include "constants.hpp"
+#include "graphicsobjects.hpp"
class GeoShader
{
- public:
- GeoShader(const std::string& fileName);
+ public:
+ GeoShader(const std::string& fileName);
- void Bind();
- void Update(const Transform& transform, const Camera& camera);
- virtual ~GeoShader();
- GLuint m_program;
+ void Bind();
+ void Update(const Transform& transform, const Camera& camera);
+ virtual ~GeoShader();
+ GLuint m_program;
- private:
- static const unsigned int NUM_SHADERS = 3;
- static const unsigned int NUM_UNIFORMS = 3;
- std::string LoadShader(const std::string& fileName);
- void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
- GLuint CreateShader(const std::string& text, GLenum shaderType);
+ private:
+ std::string LoadShader(const std::string& fileName);
+ void CheckShaderError(GLuint shader, GLuint flag, bool isProgram, const std::string& errorMessage);
+ GLuint CreateShader(const std::string& text, GLenum shaderType);
- GLuint m_shaders[NUM_SHADERS];
- GLuint m_uniforms[NUM_UNIFORMS];
+ GLuint m_shaders[NUM_SHADERS];
+ GLuint m_uniforms[NUM_UNIFORMS];
};
#endif
diff --git a/inc/graphicsobjects.hpp b/inc/graphicsobjects.hpp index 66e3fc3..de85467 100644 --- a/inc/graphicsobjects.hpp +++ b/inc/graphicsobjects.hpp @@ -4,82 +4,7 @@ #include <glm/glm.hpp>
#include <glm/gtx/transform.hpp>
-
-struct Camera
-{
-public:
- Camera(const glm::vec3& pos, float fov, float aspect, float zNear, float zFar)
- {
- this->pos = pos;
- this->forward = glm::vec3(0.0f, 0.0f, -1.0f);
- this->up = glm::vec3(0.0f, 1.0f, 0.0f);
- this->projection = glm::perspective(fov, aspect, zNear, zFar);
- }
-
- inline glm::mat4 GetViewProjection() const
- {
- return projection * glm::lookAt(pos, pos + forward, up);
- }
-
- void MoveForward()
- {
- pos += forward * amt;
- }
-
- void MoveBackward()
- {
- pos += forward * -amt;
- }
-
- void MoveRight()
- {
- pos += -glm::cross(up, forward) * amt;
- }
-
- void MoveLeft()
- {
- pos += glm::cross(up, forward) * amt;
- }
-
- void MoveUp()
- {
- //pos += glm::cross(up, forward) * amt;
- pos += glm::vec3(0,.2,0);
- }
-
- void MoveDown()
- {
- //pos += glm::cross(up, forward) * amt;
- pos -= glm::vec3(0,.2,0);
- }
-
- void Pitch(float angle)
- {
- glm::vec3 right = glm::normalize(glm::cross(up, forward));
-
- forward = glm::vec3(glm::normalize(glm::rotate(angle, right) * glm::vec4(forward, 0.0)));
- up = glm::normalize(glm::cross(forward, right));
- }
-
- /*void RotateY(float angle)
- {
- static const glm::vec3 UP(0.0f, 1.0f, 0.0f);
-
- glm::mat4 rotation = glm::rotate(angle, UP);
-
- forward = glm::vec3(glm::normalize(rotation * glm::vec4(forward, 0.0)));
- up = glm::vec3(glm::normalize(rotation * glm::vec4(up, 0.0)));
- }*/
-
-private:
- float amt = .2;
- //glm::vec3 speed = glm::vec3(0,0,0.2);
- glm::mat4 projection;
- glm::vec3 pos;
- glm::vec3 forward;
- glm::vec3 up;
-};
-
+#include "camera.hpp"
struct Transform
@@ -109,7 +34,7 @@ public: glm::mat4 VP = camera.GetViewProjection();
glm::mat4 M = GetModel();
- return VP * M;//camera.GetViewProjection() * GetModel();
+ return VP * M;
}
inline glm::vec3* GetPos() { return &pos; }
@@ -126,32 +51,6 @@ private: glm::vec3 scale;
};
-
-
-
-
-
-class Location
-{
- public:
- Location(float x1, float y1){x=x1;y=y1; w=5; h=5;};
- Location(){x=y=0; w=5; h=5;};
-
- float getX(){
- return x;
- }
-
- float getY(){
- return y;
- }
-
- float x;
- float y;
- float w;
- float h;
-};
-
-
class GraphicsData
{
public:
@@ -162,8 +61,6 @@ class GraphicsData float g;
float b;
float sides;
- //float theret[6];
- //float* ret[6];
GraphicsData(){
this->x = 0;
@@ -194,44 +91,4 @@ class GraphicsData };
-
-class Rectangle
-{
- public:
- Rectangle(float x1, float y1, float wid, float heit){x=x1;y=y1;width=wid; height=heit;};
- Rectangle(){x=y=width=height=0;};
-
-
- void setX(float x1){
- x=x1;
- }
-
- void setY(float y1){
- y=y1;
- }
-
-
-
- float getX(){
- return x;
- }
-
- float getY(){
- return y;
- }
-
- float getWidth(){
- return width;
- }
-
- float getHeight(){
- return height;
- }
-
- float x;
- float y;
- float width;
- float height;
-};
-
-#endif
\ No newline at end of file +#endif
diff --git a/inc/list.hpp b/inc/list.hpp index 7758fac..14a824c 100644 --- a/inc/list.hpp +++ b/inc/list.hpp @@ -10,6 +10,7 @@ #include "resource.hpp" #include "window.hpp" #include "constants.hpp" +#include "rectangle.hpp" #include "quadtree.hpp" class List diff --git a/inc/quadtree.hpp b/inc/quadtree.hpp index 2c23c67..fab20da 100644 --- a/inc/quadtree.hpp +++ b/inc/quadtree.hpp @@ -8,6 +8,7 @@ #include "creature.hpp"
#include "resource.hpp"
#include "entity.hpp"
+#include "rectangle.hpp"
#include "graphicsobjects.hpp"
class Quadtree {
diff --git a/inc/rectangle.hpp b/inc/rectangle.hpp new file mode 100644 index 0000000..9e5ef9b --- /dev/null +++ b/inc/rectangle.hpp @@ -0,0 +1,15 @@ +#ifndef rectangle_h +#define rectangle_h + +class Rectangle +{ + public: + Rectangle(){x=y=w=h=0;}; + Rectangle(float x1, float y1, float w1, float h1){x=x1;y=y1;w=w1;h1=h;}; + float x; + float y; + float w; + float h; +}; + +#endif diff --git a/inc/resource.hpp b/inc/resource.hpp index ce8ef5b..252b086 100644 --- a/inc/resource.hpp +++ b/inc/resource.hpp @@ -7,7 +7,7 @@ class Resource: public Entity { public: - Resource(Location L); + Resource(Rectangle t); int getAmount(){return amount;}; void grow(); void eat(int bite); diff --git a/src/creature.cpp b/src/creature.cpp index 0484fd1..7e5d0f3 100644 --- a/src/creature.cpp +++ b/src/creature.cpp @@ -1,9 +1,9 @@ #include "creature.hpp" -Creature::Creature(Location t, Dna D) +Creature::Creature(Rectangle t, DNA D) { L = t; - mine = D; + myDNA = D; if(L.x == 0 && L.y == 0){ L.x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); @@ -15,7 +15,7 @@ Creature::Creature(Location t, Dna D) gfxData.y = L.y; type = CREATURE_TYPE; - health = mine.maxHealth/2; + health = myDNA.maxHealth/2; gender = rand() % 2; age = 0; pregnancyTime = 0; @@ -55,18 +55,18 @@ void Creature::Behavior() if(pregnate){ pregnancyTime++; - if(pregnancyTime > mine.expectedPregnancyTime) + if(pregnancyTime > myDNA.expectedPregnancyTime) pregnancyReady = true; } age++; - if(age > mine.expectedAge) + if(age > myDNA.expectedAge) health = 0; } void Creature::Priority() { - if(health < mine.maxHealth / 2){ + if(health < myDNA.maxHealth / 2){ hungry = true; able = false; } @@ -79,7 +79,7 @@ void Creature::Priority() void Creature::setTarget() { //std::random_shuffle(N.begin(),N.end()); - for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++){ + for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++){ if( (*it)->getType() == RESOURCE_TYPE && hungry){ target = *it; hasTarget = true; @@ -98,7 +98,7 @@ void Creature::setTarget() wander = true; float x = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); float y = -30.0 + static_cast <float> (rand()) / (static_cast <float> (RAND_MAX/(30-(-30)))); - Location tmp; + Rectangle tmp; tmp.x = x; tmp.y = y; wTarget = tmp; @@ -107,7 +107,7 @@ void Creature::setTarget() void Creature::checkTarget() { - for(std::list <Entity*>::iterator it = N.begin(); it!=N.end(); it++) + for(std::list <Entity*>::iterator it = nearMe.begin(); it!=nearMe.end(); it++) if( target == *it ) return; @@ -118,73 +118,73 @@ void Creature::checkTarget() void Creature::Action() { if(hasTarget){ - if( Distance(L,target->getLocation()) < mine.reach && target->getType() == RESOURCE_TYPE){ - target->eat(mine.bite); - health+=mine.bite; + if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == RESOURCE_TYPE){ + target->eat(myDNA.bite); + health+=myDNA.bite; amountAte++; - //if(L.w <= mine.sizeMax && mine.amountToGrow <= amountAte){ + //if(L.w <= myDNA.sizeMax && myDNA.amountToGrow <= amountAte){ // amountAte = 0; // L.w = L.h = L.w + 1; //} if(target->getAmount()<=0) hasTarget = false; } - else if( Distance(L,target->getLocation()) < mine.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){ - target->impregnate(mine); + else if( Distance(L,target->getRectangle()) < myDNA.reach && target->getType() == CREATURE_TYPE && target->getGender() != gender ){ + target->impregnate(myDNA); hasTarget = false; } else - moveTowards(target->getLocation()); + moveTowards(target->getRectangle()); } else if(wander){ - if(Distance(L,wTarget) < mine.reach) + if(Distance(L,wTarget) < myDNA.reach) wander = false; else moveTowards(wTarget); } } -void Creature::moveTowards(Location t) +void Creature::moveTowards(Rectangle t) { if( L.x == t.x ){ if( L.y < t.y ) - L.y+=mine.speed; + L.y+=myDNA.speed; else - L.y-=mine.speed; + L.y-=myDNA.speed; } else if( L.y == t.y ){ if( L.x < t.x ) - L.x+=mine.speed; + L.x+=myDNA.speed; else - L.x-=mine.speed; + L.x-=myDNA.speed; } else if( L.x < t.x ){ if( L.y < t.y ){ - L.x+=mine.speed; - L.y+=mine.speed; + L.x+=myDNA.speed; + L.y+=myDNA.speed; } else{ - L.x+=mine.speed; - L.y-=mine.speed; + L.x+=myDNA.speed; + L.y-=myDNA.speed; } } else if ( L.x > t.x ){ if( L.y < t.y ){ - L.x-=mine.speed; - L.y+=mine.speed; + L.x-=myDNA.speed; + L.y+=myDNA.speed; } else{ - L.x-=mine.speed; - L.y-=mine.speed; + L.x-=myDNA.speed; + L.y-=myDNA.speed; } } } -void Creature::impregnate(Dna D) +void Creature::impregnate(DNA D) { if(!pregnate){ pregnate = true; pregnancyTime = 0; - childs = mine.combine(D); + childsDNA = myDNA.combine(D); } } diff --git a/src/dna.cpp b/src/dna.cpp index 1145276..bc51fd9 100644 --- a/src/dna.cpp +++ b/src/dna.cpp @@ -1,6 +1,6 @@ #include "dna.hpp" -Dna::Dna() +DNA::DNA() { maxHealth = CREATURE_MAX_HEALTH; speed = CREATURE_SPEED; @@ -13,9 +13,9 @@ Dna::Dna() sizeMax = CREATURE_SIZE_MAX; } -Dna Dna::combine(Dna D) +DNA DNA::combine(DNA D) { - Dna N; + DNA N; N.maxHealth = (this->maxHealth + D.maxHealth)/2; N.speed = (this->speed + D.speed)/2; diff --git a/src/list.cpp b/src/list.cpp index fab5813..e83822f 100644 --- a/src/list.cpp +++ b/src/list.cpp @@ -3,9 +3,8 @@ List::List() { int i; - Dna defaultDNA; - //SDL_Rect rect = {0,0,defaultDNA.sizeMax/5,defaultDNA.sizeMax/5}; - Location tmp; + DNA defaultDNA; + Rectangle tmp; tmp.x = tmp.y = 0; for(i=0;i<CREATURES;i++){ Creature X(tmp,defaultDNA); @@ -26,7 +25,7 @@ void List::Remove() { for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++) if(it->getHealth()<=0){ - Location tmp = it->getLocation(); + Rectangle tmp = it->getRectangle(); Resource r = Resource(tmp); R.push_back(r); C.erase(it--); @@ -41,12 +40,12 @@ void List::Behavior() { for(std::list<Creature>::iterator it = C.begin(); it!=C.end(); it++){ std::list<Entity*> N = getNear(*it); - it->giveN(N); + it->giveNearMe(N); it->Behavior(); if(it->getPregnancyReady()){ - Dna D = it->getChildDNA(); - Location tmp = it->getLocation(); + DNA D = it->getChildsDNA(); + Rectangle tmp = it->getRectangle(); Creature X(tmp,D); C.push_back(X); it->hadPregnancy(); @@ -61,7 +60,7 @@ void List::Place() { tree.clear(); - Location tmp; + Rectangle tmp; tmp.x = tmp.y = 0; while(R.size() < MINIMUM_RESOURCES){ Resource Y(tmp); diff --git a/src/main.cpp b/src/main.cpp index e385f9f..eb4438f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -55,10 +55,10 @@ int main() shader.Bind();
_spriteBatch.begin();
for(std::list<Creature>::iterator it = L.C.begin(); it != L.C.end(); it++)
- _spriteBatch.draw(it->gfxData);;
+ _spriteBatch.draw(it->getGFXD());;
for(std::list<Resource>::iterator it = L.R.begin(); it != L.R.end(); it++)
- _spriteBatch.draw(it->gfxData);;
+ _spriteBatch.draw(it->getGFXD());;
_spriteBatch.end();
_spriteBatch.renderBatch();
diff --git a/src/quadtree.cpp b/src/quadtree.cpp index e347e55..9fd4f0c 100644 --- a/src/quadtree.cpp +++ b/src/quadtree.cpp @@ -13,7 +13,7 @@ Quadtree::Quadtree(int pLevel, Rectangle pBounds){ gfxDataRect.r = 255;
gfxDataRect.g = 0;
gfxDataRect.b = 255;
- gfxDataRect.sides = pBounds.height;
+ gfxDataRect.sides = pBounds.h;
}
void Quadtree::clear(){
@@ -31,10 +31,10 @@ void Quadtree::clear(){ }
void Quadtree::split(){
- float subWidth = (bounds.getWidth() / 2);
- float subHeight = (bounds.getHeight() / 2);
- float x = bounds.getX();
- float y = bounds.getY();
+ float subWidth = (bounds.w / 2);
+ float subHeight = (bounds.h / 2);
+ float x = bounds.x;
+ float y = bounds.y;
Rectangle R0(x + subWidth/2, y + subHeight/2, subWidth, subHeight);
@@ -57,16 +57,16 @@ void Quadtree::clear(){ int Quadtree::getIndex(GraphicsData object) {
int index = -1;
- bool topQuadrant = (object.getY() > bounds.getY());
- bool bottomQuadrant = (object.getY() < bounds.getY());
+ bool topQuadrant = (object.y > bounds.y);
+ bool bottomQuadrant = (object.y < bounds.y);
- if (object.getX() < bounds.getX()) {
+ if (object.x < bounds.x) {
if (topQuadrant)
index = 1;
else if (bottomQuadrant)
index = 2;
}
- else if (object.getX() > bounds.getX()) {
+ else if (object.x > bounds.x) {
if (topQuadrant)
index = 0;
else if (bottomQuadrant)
diff --git a/src/resource.cpp b/src/resource.cpp index 31811ca..fdb4bf0 100644 --- a/src/resource.cpp +++ b/src/resource.cpp @@ -1,6 +1,6 @@ #include "resource.hpp" -Resource::Resource(Location t) +Resource::Resource(Rectangle t) { L = t; |