diff options
-rw-r--r-- | include/World.h | 5 | ||||
-rw-r--r-- | include/entities.h | 7 | ||||
-rw-r--r-- | src/World.cpp | 9 | ||||
-rw-r--r-- | src/entities.cpp | 6 | ||||
-rw-r--r-- | src/main.cpp | 13 |
5 files changed, 29 insertions, 11 deletions
diff --git a/include/World.h b/include/World.h index 09e06d9..216be98 100644 --- a/include/World.h +++ b/include/World.h @@ -3,6 +3,8 @@ #include <common.h>
+#define MAX_ENTITIES 8
+
#define goWorldLeft(w) if(w->toLeft){w=w->toLeft;}
#define goWorldRight(w) if(w->toRight){w=w->toRight;}
@@ -13,6 +15,8 @@ private: double start; // Where to change to dirt, going down (y)
} __attribute__ ((packed)) *line;
unsigned int lineCount;
+ unsigned int entCount;
+ void *entity[MAX_ENTITIES];
public:
World *behind,*infront;
World *toLeft,*toRight;
@@ -24,6 +28,7 @@ public: void saveToFile(FILE *f,World *parent);
void loadFromFile(FILE *f,World *parent);
void addLayer(const float width);
+ void addEntity(void *e);
};
#endif // WORLD_H diff --git a/include/entities.h b/include/entities.h index e50c77a..7cd657a 100644 --- a/include/entities.h +++ b/include/entities.h @@ -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(); }; diff --git a/src/World.cpp b/src/World.cpp index 82735bd..8f9308e 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -3,7 +3,7 @@ World::World(void){
line=NULL;
- lineCount=0;
+ lineCount=entCount=0;
toLeft=toRight=behind=infront=NULL;
}
World::World(const float width,World *l,World *r){
@@ -17,6 +17,7 @@ World::World(const float width,World *l,World *r){ toLeft=l;
toRight=r;
behind=infront=NULL;
+ entCount=0;
if(toLeft){
if(toLeft->toRight){
std::cout<<"There's already a world to the left!"<<std::endl;
@@ -87,6 +88,9 @@ LOOP2: goto LOOP2;
}else{
drawOffsetX=drawOffsetY=0;
+ for(i=0;i<entCount;i++){
+ ((Entity **)entity)[i]->draw();
+ }
}
}
void World::detect(vec2 *v,const float width){
@@ -141,3 +145,6 @@ void World::addLayer(const float width){ behind->infront=this;
}
}
+void World::addEntity(void *e){
+ entity[entCount++]=e;
+}
diff --git a/src/entities.cpp b/src/entities.cpp index 754c777..19ac536 100644 --- a/src/entities.cpp +++ b/src/entities.cpp @@ -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; diff --git a/src/main.cpp b/src/main.cpp index 60564c4..ed82e5e 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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 /************************** |