]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
fixed layer jump
authorClyne Sullivan <tullivan99@gmail.com>
Sun, 13 Sep 2015 01:41:07 +0000 (21:41 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Sun, 13 Sep 2015 01:41:07 +0000 (21:41 -0400)
src/UIClass.cpp
src/main.cpp

index 18e273e8f544b312b6c5e6b675a00ae4193b45dc..00456f59d74a5da4c7115f7e58b7fdea99e6a2a3 100644 (file)
@@ -4,6 +4,7 @@ extern Player player;
 extern World *currentWorld;
 
 void UIClass::handleEvents(){
+       float thing;
        SDL_Event e;
        while(SDL_PollEvent(&e)){
                switch(e.type){
@@ -21,20 +22,22 @@ void UIClass::handleEvents(){
                                player.loc.y += HLINE*1.2;
                                player.vel.y += .004;
                        }
-                       if(e.key.keysym.sym == SDLK_i)
+                       if(e.key.keysym.sym == SDLK_i){
                                if(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;
+                                       thing=(currentWorld->getWidth()-currentWorld->behind->getWidth())/2;
+                                       if(player.loc.x>thing-1&&
+                                          player.loc.x<thing-1+currentWorld->behind->getWidth()){
+                                               player.loc.x-=thing;
+                                               currentWorld=currentWorld->behind;
+                                       }
                                }
-                       if(e.key.keysym.sym == SDLK_k)
+                       }
+                       if(e.key.keysym.sym == SDLK_k){
                                if(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;
+                                       player.loc.x+=(currentWorld->infront->getWidth()-currentWorld->getWidth())/2;
+                                       currentWorld=currentWorld->infront;
                                }
+                       }
                        break;
                case SDL_KEYUP:
                        if(e.key.keysym.sym == SDLK_d) player.right = false;
index 93f7da171cc9dd7b37f1f6ce412129d8036682bd..593e125be271dc95a50eeaae5d79384b14d21527 100644 (file)
@@ -76,7 +76,7 @@ int main(int argc,char **argv){
        // Generate the world
        World *w=NULL,*w2=NULL;
        w2=new World(4,w,NULL);
-       w=new World(2,NULL,w2);
+       w=new World(10,NULL,w2);
        
        currentWorld=w;
        currentWorld->addLayer(3);