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

index 216be98a0643f53da518605b4d0c696f7d8b2e5b..658adb0e98a7aaca6f662bac83910a7f93e07eec 100644 (file)
@@ -23,7 +23,7 @@ public:
        World(void);\r
        World(const float width,World *l,World *r);\r
        void draw(void);\r
-       void detect(vec2 *v,const float width);\r
+       void detect(vec2 *v,vec2 *vel,const float width);\r
        float getWidth(void);\r
        void saveToFile(FILE *f,World *parent);\r
        void loadFromFile(FILE *f,World *parent);\r
index e416bc1f257b7760f1bafd158fc2832372747cbe..3f3a91a645267909d3c8946a00c4ba8c29261c66 100644 (file)
@@ -16,7 +16,10 @@ 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 += .5;
+                       if(e.key.keysym.sym == SDLK_SPACE){
+                               player.loc.y += HLINE*1.2;
+                               player.vel.y += .004;
+                       }
                        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
index ca19ba17283361821d03600eb2cedbfa279b02a9..e36160891cea46d316b54567556f810a7d608201 100644 (file)
@@ -104,21 +104,21 @@ LOOP2:
                }\r
        }\r
 }\r
-void World::detect(vec2 *v,const float width){\r
+void World::detect(vec2 *v,vec2 *vel,const float width){\r
        unsigned int i;\r
        // hey\r
        // oh hai\r
        for(i=0;i<lineCount-10;i++){\r
                if(v->y<line[i].start){\r
                        if(v->x>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){\r
-                               v->y=line[i].start;\r
+                               if(v->y<line[i].start){vel->y=0;v->y=line[i].start+HLINE;}\r
                                return;\r
                        }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){\r
-                               v->y=line[i].start;\r
+                               if(v->y<line[i].start){vel->y=0;v->y=line[i].start+HLINE;}\r
                                return;\r
                        }\r
-               }else if(v->y>line[i].start+HLINE/4){\r
-                       v->y-=HLINE/32;\r
+               }else if(v->y>line[i].start+HLINE){\r
+                       vel->y-=.00000001;\r
                }\r
        }\r
 }\r
index 50eab25d245defa13b86bc69471b79104e7116c1..a9e5179b2fd39c1c0835a692bce0fcc9fb76736d 100644 (file)
@@ -103,6 +103,9 @@ int main(int argc,char **argv){
                }
 
                player.loc.x += player.vel.x*deltaTime;                                         //update the player's x based on 
+               player.loc.y += player.vel.y*deltaTime;
+               
+               npc.loc.y += npc.vel.y*deltaTime;
 
                gw=currentWorld->getWidth();
                if(player.loc.x+player.width>-1+gw){
@@ -192,8 +195,8 @@ void logic(){
 
        std::cout<<"\r("<<player.loc.x<<","<<player.loc.y<<")";
 
-       currentWorld->detect(&player.loc,player.width);
-       currentWorld->detect(&npc.loc,npc.height);
+       currentWorld->detect(&player.loc,&player.vel,player.width);
+       currentWorld->detect(&npc.loc,&player.vel,npc.height);
 
        tickCount++;
 }