- int b = bucket(x, y);
- 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(bdx && bdy && hit_in_bucket(b+bw+1, x, y, shape)) return 1;
- return 0;
+ int l, r, t, b;
+ Sprite **bucket;
+
+ l = (s->x + grid_size) / grid_size;
+ r = (s->x + s->w + grid_size) / grid_size;
+ t = (s->y + grid_size) / grid_size;
+ b = (s->y + s->h + grid_size) / grid_size;
+ bucket = &rock_buckets[p][l + t*bw];
+
+ if(hit_in_bucket(*bucket, s)) return true;
+ if(l > 0 && hit_in_bucket(*(bucket-1), s)) return true;
+ if(t > 0 && hit_in_bucket(*(bucket-bw), s)) return true;
+ if(l > 0 && t > 0 && hit_in_bucket(*(bucket-1-bw), s)) return true;
+
+ if(r > l) {
+ if(hit_in_bucket(*(bucket+1), s)) return true;
+ if(t > 0 && hit_in_bucket(*(bucket+1-bw), s)) return true;
+ }
+ if(b > t) {
+ if(hit_in_bucket(*(bucket+bw), s)) return true;
+ if(l > 0 && hit_in_bucket(*(bucket-1+bw), s)) return true;
+ }
+ if(r > l && b > t && hit_in_bucket(*(bucket+1+bw), s)) return true;
+ return false;