]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
locked backgroun to layer
authorClyne Sullivan <tullivan99@gmail.com>
Wed, 28 Oct 2015 11:33:05 +0000 (07:33 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Wed, 28 Oct 2015 11:33:05 +0000 (07:33 -0400)
include/world.h
main.cpp
src/world.cpp

index 29c7822c85185587feeee3008a16c0c4822497e2..18e1878c071ac5431147a23e29cef880ebe5ce3e 100644 (file)
@@ -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 ;)
  */
index 13ad28949a2bc1d503fd233730dab1e976fca6d9..dd221489fda72aefa7118dfe4f93081b199d9739 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -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);
        
index 9f18180c6fcef30dd954367b736096df1a5ae7bb..e1d05ab63b2025c2db822307b5f9b59229d9976d 100644 (file)
@@ -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){
 }