From 75b782c83954e77554d2ad30f9e45e723e91765e Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 26 Sep 2015 16:07:07 -0400 Subject: created base for indoor areas --- include/world.h | 20 +++++++++++++++++--- src/main.cpp | 16 ++++++++-------- src/world.cpp | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 80 insertions(+), 13 deletions(-) diff --git a/include/world.h b/include/world.h index ff1a3ef..444b2c4 100644 --- a/include/world.h +++ b/include/world.h @@ -7,7 +7,7 @@ * World - creates and handles an area of land */ class World { -private: +protected: /* * struct line_t * @@ -32,13 +32,15 @@ public: World *toLeft,*toRight; // Pointers to areas to the left and right of this world. These are made public // so that they can easily be set without a function. - World(unsigned int width); // Generates a world of width 'width'. + World(void); ~World(void); // Frees the 'line' array. + virtual void generate(unsigned int width); // Generate the world + void addLayer(unsigned int width); // Generates a new world and makes 'behind' point to it. If 'behind' // already points to a world, the new world will be set to be behind 'behind'. - void draw(vec2 *vec); // Draws the world around the coordinates 'vec' + virtual void draw(vec2 *vec); // Draws the world around the coordinates 'vec' void detect(Player *p); // Insures objects/entities stored in an Entity class stay outside of the @@ -58,4 +60,16 @@ public: }; +/* + * IndoorWorld - Indoor settings stored in a World class ;) + */ +class IndoorWorld : public World { +public: + IndoorWorld(void); + ~IndoorWorld(void); + + void generate(unsigned int width); + void draw(vec2 *vec); +}; + #endif // WORLD_H diff --git a/src/main.cpp b/src/main.cpp index 6049d2c..1747915 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -86,11 +86,18 @@ int main(int argc, char *argv[]){ //************************************************************************// // Make a world - World *test =new World(SCREEN_WIDTH/2); + World *test=new World(); + test->generate(SCREEN_WIDTH/2); test->addLayer(400); test->addLayer(100); currentWorld=test; + IndoorWorld *iw=new IndoorWorld(); + iw->generate(200); + + test->toRight=iw; + iw->toLeft=test; + // Make the player player=new Player(); player->spawn(0,100); @@ -105,13 +112,6 @@ int main(int argc, char *argv[]){ for(i=0;iinWorld=test; } - for(i=0;ientity; void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to directly using glColor3ub() to set @@ -24,7 +26,10 @@ void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to dir glColor3ub(r,g,b); } -World::World(unsigned int width){ // Generates the world and sets all variables contained in the World class. +World::World(void){ +} + +void World::generate(unsigned int width){ // Generates the world and sets all variables contained in the World class. unsigned int i; // Used for 'for' loops float inc; // See line 40 lineCount=width+GEN_INC; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. @@ -149,7 +154,8 @@ void World::addLayer(unsigned int width){ behind->addLayer(width); return; } - behind=new World(width); + behind=new World(); + behind->generate(width); behind->infront=this; } @@ -184,3 +190,50 @@ World *World::goWorldFront(Player *p){ } return this; } + + + + +IndoorWorld::IndoorWorld(void){ +} + +IndoorWorld::~IndoorWorld(void){ + free(line); +} + +void IndoorWorld::generate(unsigned int width){ // Generates a flat area of width 'width' + unsigned int i; // Used for 'for' loops + lineCount=width+GEN_INC; // Sets line count to the desired width plus GEN_INC to remove incorrect line calculations. + + line=(struct line_t *)calloc(lineCount,sizeof(struct line_t)); // Allocate memory for the array 'line' + + for(i=0;ix-x_start)/HLINE; // Calculate the player's offset in the array 'line' using the player's location 'vec' + i=v_offset-SCREEN_WIDTH/2; // um + if(i<0)i=0; // If the player is past the start of that world 'i' should start at the beginning + // of the world + ie=v_offset+SCREEN_WIDTH/2; // Set how many lines should be drawn (the drawing for loop loops from 'i' to 'ie') + if(ie>lineCount)ie=lineCount; // If the player is past the end of that world 'ie' should contain the end of that world + glBegin(GL_QUADS); + for(i=i;iinWorld==this) + entity[i]->draw(); + } +} -- cgit v1.2.3