]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
ortho stuff
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 13 Sep 2015 00:35:06 +0000 (20:35 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 13 Sep 2015 00:35:06 +0000 (20:35 -0400)
src/UIClass.cpp
src/World.cpp
src/main.cpp

index c1c118052ceddd33b933468e95473a9c0e1988cc..e416bc1f257b7760f1bafd158fc2832372747cbe 100644 (file)
@@ -16,16 +16,20 @@ void UIClass::handleEvents(){
                case SDL_KEYDOWN:
                        if(e.key.keysym.sym == SDLK_d) player.right = true;
                        if(e.key.keysym.sym == SDLK_a) player.left = true;
-                       if(e.key.keysym.sym == SDLK_SPACE) player.loc.y += 10;
+                       if(e.key.keysym.sym == SDLK_SPACE) player.loc.y += .5;
                        if(e.key.keysym.sym == SDLK_i)
                                if(currentWorld->behind){
-                                       player.loc.x-=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2;
-                                       currentWorld=currentWorld->behind;
+                                       player.loc.x-=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2; // Match player's location to new area
+                                       currentWorld=currentWorld->behind;                                                                                       // Go to new area
+                                       if(player.loc.x>-1+currentWorld->getWidth())                                                             // Don't let player fall out of world if previous area was bigger
+                                               player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
                                }
                        if(e.key.keysym.sym == SDLK_k)
                                if(currentWorld->infront){
-                                       player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2;
-                                       currentWorld=currentWorld->infront;
+                                       player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2; // Match player's location to new area
+                                       currentWorld=currentWorld->infront;                                                                                       // Go to new area
+                                       if(player.loc.x>-1+currentWorld->getWidth())                                                              // Don't let player fall out of world if previous area was bigger
+                                               player.loc.x=-1+currentWorld->getWidth()-player.width-HLINE;
                                }
                        break;
                case SDL_KEYUP:
index 0ee865888df12aff6314cbd0a67ec8f3bc0d536c..ca19ba17283361821d03600eb2cedbfa279b02a9 100644 (file)
@@ -1,6 +1,9 @@
 #include <World.h>\r
 #include <cstdio>\r
 \r
+static float drawOffsetX=0,\r
+                        drawOffsetY=0;\r
+\r
 World::World(void){\r
        line=NULL;\r
        lineCount=entCount=0;\r
@@ -48,12 +51,17 @@ World::World(const float width,World *l,World *r){
                }\r
        }\r
 }\r
-static float drawOffsetX=0,\r
-                        drawOffsetY=0;\r
+void safeSetColor(int r,int g,int b){\r
+       if(r>255)r=255;else if(r<0)r=0;\r
+       if(g>255)g=255;else if(g<0)g=0;\r
+       if(b>255)b=255;else if(b<0)b=0;\r
+       glColor3ub(r,g,b);\r
+}\r
 void World::draw(void){\r
        unsigned int i;\r
        float x,y,hline=HLINE;\r
        static World *root,*cur;\r
+       int shade;\r
        root=cur=this;\r
 LOOP:\r
        if(cur->behind){\r
@@ -65,17 +73,18 @@ LOOP:
                //behind->draw();\r
        }\r
 LOOP2:\r
+       shade=30*(drawOffsetY/.3);\r
        glBegin(GL_QUADS);\r
                for(i=0;i<cur->lineCount-10;i++){\r
                        x=(hline*i)-1+drawOffsetX;\r
                        y=cur->line[i].start+drawOffsetY;\r
-                       glColor3ub(0,200,0);\r
+                       safeSetColor(0,200+shade,0);\r
                        glVertex2f(x      ,y);\r
                        glVertex2f(x+hline,y);\r
                        y-=hline*2;\r
                        glVertex2f(x+hline,y);\r
                        glVertex2f(x      ,y);\r
-                       glColor3ub(150,100,50);\r
+                       safeSetColor(150+shade,100+shade,50+shade);\r
                        glVertex2f(x      ,y);\r
                        glVertex2f(x+hline,y);\r
                        glVertex2f(x+hline,-1);\r
@@ -109,7 +118,7 @@ void World::detect(vec2 *v,const float width){
                                return;\r
                        }\r
                }else if(v->y>line[i].start+HLINE/4){\r
-                       v->y-=HLINE/8;\r
+                       v->y-=HLINE/32;\r
                }\r
        }\r
 }\r
index 25d76b5d3dece5cfda3f937a8521fbef0a42a412..50eab25d245defa13b86bc69471b79104e7116c1 100644 (file)
@@ -142,7 +142,14 @@ void render(){
                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
-               glOrtho(-1 + player.loc.x, 1 + player.loc.x , -1, 1, -1,1); //set the the size of the screen
+               //set the the size of the screen
+               if(player.loc.x-1<-1){
+                       glOrtho(-1,1,-1,1,-1,1);
+               }else if(player.loc.x+1>-1+currentWorld->getWidth()){
+                       glOrtho(-3+currentWorld->getWidth(),-1+currentWorld->getWidth(),-1,1,-1,1);
+               }else{
+                       glOrtho(-1 + player.loc.x, 1 + player.loc.x , -1, 1, -1,1);
+               }
                glMatrixMode(GL_MODELVIEW);                                     //set the matrix to modelview so we can draw objects
                glPushMatrix();                                                                 //push the  matrix to the top of the matrix stack
                glLoadIdentity();                                                               //replace the entire matrix stack with the updated GL_MODELVIEW mode