X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=rocks.c;h=114e22fac7abcae4c844cd95ea4e81a95db4abb3;hp=428c697ada20a87cb86a5a6aaad16ac7b100fa86;hb=cd7fb220b16a73c15ff9dff7a5627bf78478875f;hpb=ecb22d95c5c67e92873ba1f518711dcf3e86f181 diff --git a/rocks.c b/rocks.c index 428c697..114e22f 100644 --- 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; - if(l && hit_in_bucket(*(bucket-1), x, y, shape)) return true; - if(r && hit_in_bucket(*(bucket-bw), x, y, shape)) return true; - if(l && r && 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(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-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; } @@ -345,12 +345,18 @@ pixel_hit_in_bucket(struct rock_struct *r, float x, float y) int pixel_hit_rocks(float x, float y) { - struct rock_struct **b = bucket(x, y, p); - 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; + int ix, iy; + int l, t; + struct rock_struct **bucket; + + ix = x + grid_size; iy = y + grid_size; + 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 > 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; } void