diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-28 07:33:05 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-10-28 07:33:05 -0400 |
commit | c0d484d71cdc8b0c22981d1c763d025fedbe1bb4 (patch) | |
tree | ec21114f6203de8cd47beaf0ac22a43a65131106 | |
parent | 23b58dcc63cbadbf8d2a614c903652477cdc00c9 (diff) |
locked backgroun to layer
-rw-r--r-- | include/world.h | 5 | ||||
-rw-r--r-- | main.cpp | 10 | ||||
-rw-r--r-- | src/world.cpp | 10 |
3 files changed, 20 insertions, 5 deletions
diff --git a/include/world.h b/include/world.h index 29c7822..18e1878 100644 --- a/include/world.h +++ b/include/world.h @@ -32,12 +32,13 @@ protected: std::vector<Platform> platform; // An array (vector thing) of platforms int x_start; // Worlds are centered on the x axis (0,n), this contains // where to start drawing the world to have it centered properly. - World *behind,*infront; // Pointers to other areas of land that are behind or in front of this one, respectively. + World *behind; // Pointers to other areas of land that are behind or in front of this one, respectively. void singleDetect(Entity *e); // Handles an individual entity (gravity n' stuff) public: unsigned int lineCount; // Size of the array 'line' (aka the width of the world) 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 *infront; World(void); ~World(void); // Frees the 'line' array. @@ -71,6 +72,8 @@ public: void addHole(unsigned int start,unsigned int end); // Create a hole in the world }; +float worldGetYBase(World *w); + /* * IndoorWorld - Indoor settings stored in a World class ;) */ @@ -558,13 +558,15 @@ void render(){ glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2,SCREEN_HEIGHT); glEnd(); + int base = 50 - (int)worldGetYBase(currentWorld); + glBindTexture(GL_TEXTURE_2D, bgTreesFirst); glColor4ub(255,255,255,255); glBegin(GL_QUADS); - glTexCoord2i(0,1);glVertex2i(-960 +player->loc.x*.25, 50); - glTexCoord2i(1,1);glVertex2i(960 +player->loc.x*.25, 50); - glTexCoord2i(1,0);glVertex2i(960 +player->loc.x*.25, 1130); - glTexCoord2i(0,0);glVertex2i(-960 +player->loc.x*.25, 1130); + glTexCoord2i(0,1);glVertex2i(-960+player->loc.x*.25,base); + glTexCoord2i(1,1);glVertex2i( 960+player->loc.x*.25,base); + glTexCoord2i(1,0);glVertex2i( 960+player->loc.x*.25,base+1080); + glTexCoord2i(0,0);glVertex2i(-960+player->loc.x*.25,base+1080); glEnd(); glDisable(GL_TEXTURE_2D); diff --git a/src/world.cpp b/src/world.cpp index 9f18180..e1d05ab 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -27,6 +27,16 @@ void safeSetColor(int r,int g,int b){ // safeSetColor() is an alternative to dir glColor3ub(r,g,b); } +float worldGetYBase(World *w){ + float base = 0; + World *ptr = w; + while(ptr->infront){ + base+=DRAW_Y_OFFSET; + ptr=ptr->infront; + } + return base; +} + World::World(void){ } |