diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-12 19:52:48 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-12 19:52:48 -0400 |
commit | ce7a96683ee94f8764e7811a5d6167b248accb7c (patch) | |
tree | 940f36c62610faa273a3b2ecf15968f0828930ad /src | |
parent | a744d3312dd2f0253f7965253b3eff683cca3453 (diff) |
entity-world binding
Diffstat (limited to 'src')
-rw-r--r-- | src/World.cpp | 9 | ||||
-rw-r--r-- | src/entities.cpp | 6 | ||||
-rw-r--r-- | src/main.cpp | 13 |
3 files changed, 20 insertions, 8 deletions
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 /************************** |