From f3028d986781fb9a5199b6a0394b5a79871af156 Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 12 Sep 2015 20:55:37 -0400 Subject: jump --- src/UIClass.cpp | 5 ++++- src/World.cpp | 10 +++++----- src/main.cpp | 7 +++++-- 3 files changed, 14 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/UIClass.cpp b/src/UIClass.cpp index e416bc1..3f3a91a 100644 --- a/src/UIClass.cpp +++ b/src/UIClass.cpp @@ -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 diff --git a/src/World.cpp b/src/World.cpp index ca19ba1..e361608 100644 --- a/src/World.cpp +++ b/src/World.cpp @@ -104,21 +104,21 @@ LOOP2: } } } -void World::detect(vec2 *v,const float width){ +void World::detect(vec2 *v,vec2 *vel,const float width){ unsigned int i; // hey // oh hai for(i=0;iyx>(HLINE*i)-1&&v->x<(HLINE*i)-1+HLINE){ - v->y=line[i].start; + if(v->yy=0;v->y=line[i].start+HLINE;} return; }else if(v->x+width>(HLINE*i)-1&&v->x+width<(HLINE*i)-1+HLINE){ - v->y=line[i].start; + if(v->yy=0;v->y=line[i].start+HLINE;} return; } - }else if(v->y>line[i].start+HLINE/4){ - v->y-=HLINE/32; + }else if(v->y>line[i].start+HLINE){ + vel->y-=.00000001; } } } diff --git a/src/main.cpp b/src/main.cpp index 50eab25..a9e5179 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -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("<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++; } -- cgit v1.2.3