]> code.bitgloo.com Git - clyne/gamedev.git/commitdiff
world bound checks
authorClyne Sullivan <tullivan99@gmail.com>
Fri, 18 Sep 2015 21:30:48 +0000 (17:30 -0400)
committerClyne Sullivan <tullivan99@gmail.com>
Fri, 18 Sep 2015 21:30:48 +0000 (17:30 -0400)
src/world.cpp

index d2a15f7034cc5512bd062eb2ee01c190d7136137..12d9591280767ec42bbc61c054e076f5795b2639 100644 (file)
@@ -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;
        }
 }