]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
Made background painting dynamic, and made new tree backdrops
authordrumsetmonkey <abelleisle@roadrunner.com>
Thu, 29 Oct 2015 13:17:43 +0000 (09:17 -0400)
committerdrumsetmonkey <abelleisle@roadrunner.com>
Thu, 29 Oct 2015 13:17:43 +0000 (09:17 -0400)
assets/antree.png [deleted file]
include/ui.h
include/world.h
main.cpp
src/gameplay.cpp
src/ui.cpp
src/world.cpp

diff --git a/assets/antree.png b/assets/antree.png
deleted file mode 100644 (file)
index 2cb54ad..0000000
Binary files a/assets/antree.png and /dev/null differ
index 739aba092080d20a0a4bb425771e006c448c4a62..79ca9a7a7f1e2be6596b351880b88954a947cf28 100644 (file)
@@ -16,6 +16,7 @@ namespace ui {        // Functions are kept in a namespace simply
        extern vec2 mouse;
 
        extern bool debug;
+       extern bool posFlag;
        extern bool dialogBoxExists;
        extern unsigned int fontSize;
 
index ab161c05df54aed8e2bacbed524b54d1036fe0eb..30df9cc74de653529d70848e7fcc4414b7c66238 100644 (file)
@@ -71,7 +71,7 @@ public:
                                                                                                                // drawn and handled by the world.
        void addHole(unsigned int start,unsigned int end);      // Create a hole in the world
        
-       int getStart(void);
+       int getTheWidth(void);
 };
 
 float worldGetYBase(World *w);
index faa2be4fa5a564c464619cd7c576825282ad4b9c..c52528abcdd09423f6fc4a1755601031eff18f33 100644 (file)
--- a/main.cpp
+++ b/main.cpp
@@ -49,7 +49,7 @@ SDL_GLContext  mainGLContext = NULL;
  * 
 */
 
-static GLuint  bgImage, bgMtn, bgTreesFirst;
+static GLuint  bgImage, bgMtn, bgTreesFront, bgTreesMid, bgTreesFar;
 
 /*
  *     gameRunning
@@ -336,7 +336,7 @@ int main(int argc, char *argv[]){
                
                glGetShaderiv(fragShader, GL_COMPILE_STATUS, &bufferln);
                
-               if(bufferln == GL_TRUE){
+               if(bufferln == GL_FALSE){
                        std::cout << "Error compiling shader" << std::endl;
                }
                
@@ -382,7 +382,9 @@ int main(int argc, char *argv[]){
        
        bgImage=                Texture::loadTexture("assets/bg.png");
        bgMtn=                  Texture::loadTexture("assets/bgFarMountain.png");
-       bgTreesFirst =  Texture::loadTexture("assets/antree.png");
+       bgTreesFront =  Texture::loadTexture("assets/bgFrontTree.png");
+       bgTreesMid =    Texture::loadTexture("assets/bgMidTree.png");
+       bgTreesFar =    Texture::loadTexture("assets/bgFarTree.png");
        
        /*
         *      Load sprites used in the inventory menu. See src/inventory.cpp
@@ -541,8 +543,8 @@ void render(){
         *      If the camera will go off of the left  or right of the screen we want to lock it so we can't
         *  see past the world render
        */
-       if(player->loc.x - SCREEN_WIDTH/2 < SCREEN_WIDTH*-1.5)offset.x = ((SCREEN_WIDTH*-1.5) + SCREEN_WIDTH/2) + player->width/2;
-       if(player->loc.x + SCREEN_WIDTH/2 > SCREEN_WIDTH*1.5)offset.x = ((SCREEN_WIDTH*1.5) - SCREEN_WIDTH/2) + player->width/2;
+       if(player->loc.x - SCREEN_WIDTH/2 < currentWorld->getTheWidth()*-0.5f)offset.x = ((currentWorld->getTheWidth()*-0.5f) + SCREEN_WIDTH/2) + player->width/2;
+       if(player->loc.x + SCREEN_WIDTH/2 > currentWorld->getTheWidth()*0.5f)offset.x = ((currentWorld->getTheWidth()*0.5f) - SCREEN_WIDTH/2) + player->width/2;
        glMatrixMode(GL_PROJECTION);                                    //set the matrix mode as projection so we can set the ortho size and the camera settings later on
        glPushMatrix();                                                                 //push the  matrix to the top of the matrix stack
        glLoadIdentity();                                                               //replace the entire matrix stack with the updated GL_PROJECTION mode
@@ -576,75 +578,58 @@ void render(){
 
        glEnable(GL_TEXTURE_2D);
        glBindTexture(GL_TEXTURE_2D,bgImage);
-       
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2,0);
-               glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2,0);
-               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2,SCREEN_HEIGHT);
-               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2,SCREEN_HEIGHT);
+               glTexCoord2i(0,1);glVertex2i(-SCREEN_WIDTH*2+offset.x,0);
+               glTexCoord2i(1,1);glVertex2i( SCREEN_WIDTH*2+offset.x,0);
+               glTexCoord2i(1,0);glVertex2i( SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
+               glTexCoord2i(0,0);glVertex2i(-SCREEN_WIDTH*2+offset.x,SCREEN_HEIGHT);
        glEnd();
 
        int base = 40 - (int)worldGetYBase(currentWorld);
 
        glBindTexture(GL_TEXTURE_2D, bgMtn);
-
-       glColor4ub(150,150,150,220);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.85,base);
-               glTexCoord2i(1,1);glVertex2i(      offset.x*.85,base);
-               glTexCoord2i(1,0);glVertex2i(      offset.x*.85,base+1080);
-               glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.85,base+1080);
-       glEnd();
        glColor4ub(150,150,150,220);
-       glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(     offset.x*.85,base);
-               glTexCoord2i(1,1);glVertex2i(1920+offset.x*.85,base);
-               glTexCoord2i(1,0);glVertex2i(1920+offset.x*.85,base+1080);
-               glTexCoord2i(0,0);glVertex2i(     offset.x*.85,base+1080);
+               for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){
+               glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.85,base);
+               glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.85,base);
+               glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.85,base+1080);
+               glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.85,base+1080);
+       }
        glEnd();
 
-       glBindTexture(GL_TEXTURE_2D, bgTreesFirst);
 
-       glPushMatrix();
-       glColor4ub(100,100,100,240);
+       glBindTexture(GL_TEXTURE_2D, bgTreesFar);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.6,base);
-               glTexCoord2i(1,1);glVertex2i(      offset.x*.6,base);
-               glTexCoord2i(1,0);glVertex2i(      offset.x*.6,base+1080);
-               glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.6,base+1080);
-       glEnd();
-
        glColor4ub(100,100,100,240);
-       glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(     offset.x*.6,base);
-               glTexCoord2i(1,1);glVertex2i(1920+offset.x*.6,base);
-               glTexCoord2i(1,0);glVertex2i(1920+offset.x*.6,base+1080);
-               glTexCoord2i(0,0);glVertex2i(     offset.x*.6,base+1080);
+       for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){
+               glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.6,base);
+               glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.6,base);
+               glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.6,base+1080);
+               glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.6,base+1080);
+       }
        glEnd();
-       glPopMatrix();
 
-       glColor4ub(150,150,150,250);
+       glBindTexture(GL_TEXTURE_2D, bgTreesMid);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(-1920+offset.x*.4,base);
-               glTexCoord2i(1,1);glVertex2i(      offset.x*.4,base);
-               glTexCoord2i(1,0);glVertex2i(      offset.x*.4,base+1080);
-               glTexCoord2i(0,0);glVertex2i(-1920+offset.x*.4,base+1080);
-       glEnd();
-
        glColor4ub(150,150,150,250);
-       glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(     offset.x*.4,base);
-               glTexCoord2i(1,1);glVertex2i(1920+offset.x*.4,base);
-               glTexCoord2i(1,0);glVertex2i(1920+offset.x*.4,base+1080);
-               glTexCoord2i(0,0);glVertex2i(     offset.x*.4,base+1080);
+       for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){
+               glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.4,base);
+               glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.4,base);
+               glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.4,base+1080);
+               glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.4,base+1080);
+       }
        glEnd();
 
-       glColor4ub(255,255,255,255);
+       glBindTexture(GL_TEXTURE_2D, bgTreesFront);
        glBegin(GL_QUADS);
-               glTexCoord2i(0,1);glVertex2i(-960+offset.x*.25,base);
-               glTexCoord2i(1,1);glVertex2i( 960+offset.x*.25,base);
-               glTexCoord2i(1,0);glVertex2i( 960+offset.x*.25,base+1080);
-               glTexCoord2i(0,0);glVertex2i(-960+offset.x*.25,base+1080);
+       glColor4ub(255,255,255,255);
+       for(int i = 0; i <= currentWorld->getTheWidth()/1920; i++){
+               glTexCoord2i(0,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.25,base);
+               glTexCoord2i(1,1);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.25,base);
+               glTexCoord2i(1,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * (i+1))+offset.x*.25,base+1080);
+               glTexCoord2i(0,0);glVertex2i((currentWorld->getTheWidth()*-0.5f)+(1920 * i)+offset.x*.25,base+1080);
+       }
        glEnd();
        glDisable(GL_TEXTURE_2D);
        
@@ -685,6 +670,20 @@ void render(){
                                        debugY,                                         // The player's y coordinate
                                        player->qh.current.size()       // Active quest count
                                        );
+               if(ui::posFlag){
+                       glBegin(GL_LINES);
+                               glColor3ub(255,0,0);
+                               glVertex2i(0,0);
+                               glVertex2i(0,SCREEN_HEIGHT);
+
+                               glColor3ub(255,255,255);
+                               glVertex2i(player->loc.x + player->width/2,0);
+                               glVertex2i(player->loc.x + player->width/2,SCREEN_HEIGHT);
+
+                               glVertex2i(-SCREEN_WIDTH/2+offset.x,player->loc.y);
+                               glVertex2i(SCREEN_WIDTH/2+offset.x, player->loc.y);
+                       glEnd();
+               }
                                        
        }
        
index 9e0cc99d3360ea4d6133ed07544f014f34b2c890..964794fc4ca8281e77982deedee9fe716db1a3ee 100644 (file)
@@ -35,12 +35,7 @@ void initEverything(void){
        */
        
        World *test=new World();
-       test->generate(SCREEN_WIDTH);
-       
-       /*
-        *      Add two layers, a platform, and a hole to the world. 
-       */
-       
+       test->generate(SCREEN_WIDTH * 2);
        test->addLayer(400);
        
        test->addPlatform(150,100,100,10);
index e6d18d2d3125678b850ee432b80397830c5130d8..e0ebc506bfd5aaf417b21c9f38d7af0f27b79d94 100644 (file)
@@ -19,6 +19,7 @@ static char *dialogBoxText;
 namespace ui {
        vec2 mouse;
        bool debug=false;
+       bool posFlag=false;
        bool dialogBoxExists=false;
        unsigned int fontSize;
 
@@ -247,6 +248,7 @@ namespace ui {
                                if(SDL_KEY==SDLK_LCTRL)player->speed = .5;
                        }
                                if(SDL_KEY==SDLK_F3)debug^=true;
+                               if(SDL_KEY==SDLK_b & SDL_KEY==SDLK_F3)posFlag^=true;
                                break;
                        /*
                                KEYUP
index 97ec5accf2f06573deab8fdb1dc3273ebd7803b4..c04c88a972a07412e57e8cf6acab5919933234b1 100644 (file)
@@ -581,8 +581,8 @@ void World::addHole(unsigned int start,unsigned int end){
        }
 }
 
-int World::getStart(void){
-       return -x_start;
+int World::getTheWidth(void){
+       return x_start*-2;
 }
 
 IndoorWorld::IndoorWorld(void){