- SDL_Rect dest;
-
- for(i=0; i<MAXROCKS; i++) {
- if(!rocks[i].image) continue;
- dest.x = rocks[i].x; dest.y = rocks[i].y;
- SDL_BlitSurface(rocks[i].image,NULL,surf_screen,&dest);
- }
-}
-
-int
-hit_in_bucket(struct rock *r, float x, float y, struct shape *shape)
-{
- for(; r; r=&r->next->rock) {
- if(collide(x - r->x, y - r->y, r->shape, shape)) return 1;
- }
- return 0;
-}
-
-int
-hit_rocks(float x, float y, struct shape *shape)
-{
- int ix, iy;
- int l, r, t, b;
- struct rock **bucket;
-
- ix = x + grid_size; iy = y + grid_size;
- l = ix / grid_size; r = (ix+shape->w)/grid_size;
- t = iy / grid_size; b = (iy+shape->h)/grid_size;
- bucket = &rock_buckets[p][l + t*bw];
-
- if(hit_in_bucket(*bucket, 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(t > 0 && hit_in_bucket(*(bucket+1-bw), x, y, shape)) return true;
- }
- if(b > t) {
- if(hit_in_bucket(*(bucket+bw), x, y, shape)) return true;
- if(l > 0 && hit_in_bucket(*(bucket-1+bw), x, y, shape)) return true;
- }
- if(r > l && b > t && hit_in_bucket(*(bucket+1+bw), x, y, shape)) return true;
- return false;
-}
-
-int
-pixel_hit_in_bucket(struct rock *r, float x, float y)
-{
- for(; r; r=&r->next->rock) {
- if(x < r->x || y < r->y) continue;
- if(pixel_collide(x - r->x, y - r->y, r->shape)) return 1;
- }
- return 0;
-}
-
-int
-pixel_hit_rocks(float x, float y)
-{
- int ix, iy;
- int l, t;
- struct rock **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
-blast_rocks(float x, float y, float radius, int onlyslow)
-{
- int b;
- struct rock *r;
- float dx, dy, n;
-
- if(onlyslow) return;
-
- for(b=0; b<n_buckets; b++) {
- for(r=rock_buckets[p][b]; r; r=&r->next->rock) {
- if(r->x <= 0) continue;
-
- // This makes it so your explosion from dying magically doesn't leave
- // any rocks that aren't moving much on the x axis. If onlyslow is set,
- // only rocks that are barely moving will be pushed.
- if(onlyslow && (r->dx - screendx < -4 || r->dx - screendx > 3)) continue;
-
- dx = r->x - x;
- dy = r->y - y;
-
- n = sqrt(dx*dx + dy*dy);
- if(n < radius) {
- n *= 15;
- r->dx += 54.0*dx/n;
- r->dy += 54.0*dy/n;
- }
- }
- }