]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
entity-world binding
authorClyne Sullivan <tullivan99@gmail.com>
Sat, 12 Sep 2015 23:52:48 +0000 (19:52 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sat, 12 Sep 2015 23:52:48 +0000 (19:52 -0400)
include/World.h
include/entities.h
src/World.cpp
src/entities.cpp
src/main.cpp

index 09e06d9ee69efc70c1a212e34b107267745478c7..216be98a0643f53da518605b4d0c696f7d8b2e5b 100644 (file)
@@ -3,6 +3,8 @@
 \r
 #include <common.h>\r
 \r
+#define MAX_ENTITIES 8\r
+\r
 #define goWorldLeft(w)  if(w->toLeft){w=w->toLeft;}\r
 #define goWorldRight(w) if(w->toRight){w=w->toRight;}\r
 \r
@@ -13,6 +15,8 @@ private:
                double start; // Where to change to dirt, going down (y)\r
        } __attribute__ ((packed)) *line;\r
        unsigned int lineCount;\r
+       unsigned int entCount;\r
+       void *entity[MAX_ENTITIES];\r
 public:\r
        World *behind,*infront;\r
        World *toLeft,*toRight;\r
@@ -24,6 +28,7 @@ public:
        void saveToFile(FILE *f,World *parent);\r
        void loadFromFile(FILE *f,World *parent);\r
        void addLayer(const float width);\r
+       void addEntity(void *e);\r
 };\r
 \r
 #endif // WORLD_H
index e50c77a32579c58e5da3e61e7bfdb8d50dd4b39b..7cd657a11efa1fdcc031aff77cb62544966da272 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <common.h>
 
-class Entities{
+class Entity{
 public:
        float width;
        float height;
@@ -14,15 +14,16 @@ public:
        bool right,left;
 
        void spawn(float, float);
+       void draw(void);
 };
 
-class Player : public Entities{
+class Player : public Entity{
 public:
        Player();
        ~Player();
 };
 
-class NPC : public Entities{
+class NPC : public Entity{
 public:
        NPC();
 };
index 82735bdb53707014ce8bce556a2caf089544f7d5..8f9308e16b6ab1da622282dcdea0f7527157828e 100644 (file)
@@ -3,7 +3,7 @@
 \r
 World::World(void){\r
        line=NULL;\r
-       lineCount=0;\r
+       lineCount=entCount=0;\r
        toLeft=toRight=behind=infront=NULL;\r
 }\r
 World::World(const float width,World *l,World *r){\r
@@ -17,6 +17,7 @@ World::World(const float width,World *l,World *r){
        toLeft=l;\r
        toRight=r;\r
        behind=infront=NULL;\r
+       entCount=0;\r
        if(toLeft){\r
                if(toLeft->toRight){\r
                        std::cout<<"There's already a world to the left!"<<std::endl;\r
@@ -87,6 +88,9 @@ LOOP2:
                goto LOOP2;\r
        }else{\r
                drawOffsetX=drawOffsetY=0;\r
+               for(i=0;i<entCount;i++){\r
+                       ((Entity **)entity)[i]->draw();\r
+               }\r
        }\r
 }\r
 void World::detect(vec2 *v,const float width){\r
@@ -141,3 +145,6 @@ void World::addLayer(const float width){
                behind->infront=this;\r
        }\r
 }\r
+void World::addEntity(void *e){\r
+       entity[entCount++]=e;\r
+}\r
index 754c77756dec23a8b61ead401833d1f8e3bb3608..19ac536f185b0de5baf3d184ead19df0155a5e97 100644 (file)
@@ -1,6 +1,6 @@
 #include <entities.h>
 
-void Entities::spawn(float x, float y){
+void Entity::spawn(float x, float y){
        loc.x = x;
        loc.y = y;
        vel.x = 0;
@@ -8,6 +8,10 @@ void Entities::spawn(float x, float y){
        right = false;
        left = false;
 }
+void Entity::draw(void){
+       glColor3ub(0,0,100);
+       glRectf(loc.x,loc.y,loc.x+width,loc.y+height);
+}
 
 Player::Player(){
        width = HLINE * 8;
index 60564c416e202a89a90db86b4ca4e98c1dc388ac..ed82e5ef76fe1a370dd663e68ea9012234c853fb 100644 (file)
@@ -16,8 +16,8 @@ static unsigned int tickCount   = 0,
                                        currentTime = 0,
                                        deltaTime   = 0;
 
-Entities *entPlay;     //The player base
-Entities *entnpc;      //The NPC base
+Entity *entPlay;       //The player base
+Entity *entnpc;        //The NPC base
 Player player;         //The actual player object
 NPC npc;
 UIClass ui;                    //Yep
@@ -92,7 +92,7 @@ int main(int argc,char **argv){
        entPlay->spawn(0, 0);
        entnpc = &npc;
        npc.type = -1;                                           //this will make the NPC spawn the start of a village
-       entnpc->spawn( (grand()%20)-10 ,0); //this will spawn the start of a village
+       entnpc->spawn(.5,0);// (grand()%20)-10 ,0); //this will spawn the start of a village
 
        // Generate the world
        World *w=NULL,*w2=NULL;
@@ -101,6 +101,7 @@ int main(int argc,char **argv){
        
        currentWorld=w;
        currentWorld->addLayer(3);
+       currentWorld->addEntity((void *)entnpc);
        //currentWorld->addLayer();
        
        // Save the world if necessary
@@ -117,7 +118,7 @@ int main(int argc,char **argv){
                fread(&fSave,sizeof(unsigned int),1,f);
                fclose(f);
        }*/
-       
+
        float gw;
        
        while(gameRunning){
@@ -186,14 +187,14 @@ void render(){
                glRectf(player.loc.x, player.loc.y, player.loc.x + player.width, player.loc.y + player.height);
 
                ///TEMP NPC RENDER!!!!!!
-               glColor3ub(98, 78, 44);                                                 //render the NPC(s)
+               /*glColor3ub(98, 78, 44);                                                       //render the NPC(s)
                glRectf(npc.loc.x, npc.loc.y, npc.loc.x + .25, npc.loc.y + .25);
                glColor3ub(83, 49, 24);
                glBegin(GL_TRIANGLES);
                        glVertex2f(npc.loc.x, npc.loc.y + .25);
                        glVertex2f(npc.loc.x + .25, npc.loc.y + .25);
                        glVertex2f(npc.loc.x + .125, npc.loc.y + .35);
-               glEnd();
+               glEnd();*/
                ///BWAHHHHHHHHHHHH
                
                /**************************