JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
oops, have to check all 9 buckets.
[vor.git] / rocks.c
diff --git a/rocks.c b/rocks.c
index a2aa31e..f68a57a 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -301,19 +301,26 @@ hit_rocks(float x, float y, struct shape *shape)
        int bdx = ((int)x+shape->w)/grid_size - (int)x/grid_size;
        int bdy = ((int)y+shape->h)/grid_size - (int)y/grid_size;
        if(hit_in_bucket(b, x, y, shape)) return 1;
-       if(bdx && hit_in_bucket(b+1, x, y, shape)) return 1;
-       if(bdy && hit_in_bucket(b+bw, x, y, shape)) return 1;
+       if(hit_in_bucket(b-1, x, y, shape)) return 1;
+       if(hit_in_bucket(b-bw, x, y, shape)) return 1;
+       if(hit_in_bucket(b-bw-1, x, y, shape)) return 1;
+
+       if(bdx) {
+               if(hit_in_bucket(b+1, x, y, shape)) return 1;
+               if(hit_in_bucket(b+1-bw, x, y, shape)) return 1;
+       }
+       if(bdy) {
+               if(hit_in_bucket(b+bw, x, y, shape)) return 1;
+               if(hit_in_bucket(b+bw-1, x, y, shape)) return 1;
+       }
        if(bdx && bdy && hit_in_bucket(b+bw+1, x, y, shape)) return 1;
        return 0;
 }
 
 int
-pixel_hit_rocks(float x, float y)
+pixel_hit_in_bucket(int b, float x, float y)
 {
-       int b;
        struct rock_struct *r;
-
-       b = bucket(x, y);
        for(r=rock_buckets[p][b]; r; r=r->next) {
                if(x < r->x || y < r->y) continue;
                if(pixel_collide(x - r->x, y - r->y, r->shape)) return 1;
@@ -321,6 +328,17 @@ pixel_hit_rocks(float x, float y)
        return 0;
 }
 
+int
+pixel_hit_rocks(float x, float y)
+{
+       int b = bucket(x, y);
+       if(pixel_hit_in_bucket(b, x, y)) return 1;
+       if(pixel_hit_in_bucket(b-1, x, y)) return 1;
+       if(pixel_hit_in_bucket(b-bw, x, y)) return 1;
+       if(pixel_hit_in_bucket(b-bw-1, x, y)) return 1;
+       return 0;
+}
+
 void
 blast_rocks(float x, float y, float radius, int onlyslow)
 {