diff options
author | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-18 17:30:48 -0400 |
---|---|---|
committer | Clyne Sullivan <tullivan99@gmail.com> | 2015-09-18 17:30:48 -0400 |
commit | 1f3fee78514fb097834a2cb4235aaad3bdf639e7 (patch) | |
tree | 0846c1acbbbf62d01d6741d5394da128342ed017 /src | |
parent | 6c2fa9e1b372f71d311b376e689961dad6aaa036 (diff) |
world bound checks
Diffstat (limited to 'src')
-rw-r--r-- | src/world.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/src/world.cpp b/src/world.cpp index d2a15f7..12d9591 100644 --- a/src/world.cpp +++ b/src/world.cpp @@ -61,13 +61,20 @@ void World::draw(vec2 *vec){ void World::detect(vec2 *v,vec2 *vel,const float width){ unsigned int i; + // Vertical checks i=(v->x+width/2-x_start)/HLINE; if(v->y<=line[i].y){ vel->y=0; v->y=line[i].y+HLINE/2; - return; }else{ vel->y-=.05; - return; + } + // Horizontal checks + if(v->x<x_start){ + vel->x=0; + v->x=x_start+HLINE/2; + }else if(v->x>x_start+getWidth()){ + vel->x=0; + v->x=x_start+getWidth()-width-HLINE/2; } } |