From ce7a96683ee94f8764e7811a5d6167b248accb7c Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 12 Sep 2015 19:52:48 -0400 Subject: entity-world binding --- src/World.cpp | 9 ++++++++- src/entities.cpp | 6 +++++- src/main.cpp | 13 +++++++------ 3 files changed, 20 insertions(+), 8 deletions(-) (limited to 'src') 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!"<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 -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 /************************** -- cgit v1.2.3