JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
* rocks.c (hit_rock, pixel_hit_rock): fix more possible bugs.
authorJoshua Grams <josh@qualdan.com>
Thu, 5 Jan 2006 04:12:20 +0000 (04:12 +0000)
committerJoshua Grams <josh@qualdan.com>
Thu, 5 Jan 2006 04:12:20 +0000 (04:12 +0000)
rocks.c

diff --git a/rocks.c b/rocks.c
index d395d5d..114e22f 100644 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -316,19 +316,19 @@ hit_rocks(float x, float y, struct shape *shape)
        bucket = &rock_buckets[p][l + t*bw];
 
        if(hit_in_bucket(*bucket, x, y, shape)) return true;
        bucket = &rock_buckets[p][l + t*bw];
 
        if(hit_in_bucket(*bucket, x, y, shape)) return true;
-       if(l && hit_in_bucket(*(bucket-1), x, y, shape)) return true;
-       if(t && hit_in_bucket(*(bucket-bw), x, y, shape)) return true;
-       if(l && t && hit_in_bucket(*(bucket-(1+bw)), x, y, shape)) return true;
+       if(l > 0 && hit_in_bucket(*(bucket-1), x, y, shape)) return true;
+       if(t > 0 && hit_in_bucket(*(bucket-bw), x, y, shape)) return true;
+       if(l > 0 && t > 0 && hit_in_bucket(*(bucket-1-bw), x, y, shape)) return true;
 
        if(r > l) {
                if(hit_in_bucket(*(bucket+1), x, y, shape)) return true;
 
        if(r > l) {
                if(hit_in_bucket(*(bucket+1), x, y, shape)) return true;
-               if(hit_in_bucket(*(bucket+1-bw), x, y, shape)) return true;
+               if(t > 0 && hit_in_bucket(*(bucket+1-bw), x, y, shape)) return true;
        }
        }
-       if(t > b) {
+       if(b > t) {
                if(hit_in_bucket(*(bucket+bw), x, y, shape)) return true;
                if(hit_in_bucket(*(bucket+bw), x, y, shape)) return true;
-               if(hit_in_bucket(*(bucket+bw-1), x, y, shape)) return true;
+               if(l > 0 && hit_in_bucket(*(bucket-1+bw), x, y, shape)) return true;
        }
        }
-       if(r > l && t > b && hit_in_bucket(*(bucket+bw+1), x, y, shape)) return true;
+       if(r > l && b > t && hit_in_bucket(*(bucket+1+bw), x, y, shape)) return true;
        return false;
 }
 
        return false;
 }
 
@@ -353,9 +353,9 @@ pixel_hit_rocks(float x, float y)
        l = ix / grid_size; t = iy / grid_size;
        bucket = &rock_buckets[p][l + t*bw];
        if(pixel_hit_in_bucket(*bucket, x, y)) return true;
        l = ix / grid_size; t = iy / grid_size;
        bucket = &rock_buckets[p][l + t*bw];
        if(pixel_hit_in_bucket(*bucket, x, y)) return true;
-       if(l && pixel_hit_in_bucket(*(bucket-1), x, y)) return true;
-       if(t && pixel_hit_in_bucket(*(bucket-bw), x, y)) return true;
-       if(l && t && pixel_hit_in_bucket(*(bucket-(bw+1)), x, y)) return true;
+       if(l > 0 && pixel_hit_in_bucket(*(bucket-1), x, y)) return true;
+       if(t > 0 && pixel_hit_in_bucket(*(bucket-bw), x, y)) return true;
+       if(l > 0 && t > 0 && pixel_hit_in_bucket(*(bucket-1-bw), x, y)) return true;
        return false;
 }
 
        return false;
 }