From a77978e0c9bc91ea3d7b192ce136621e78d4ec5b Mon Sep 17 00:00:00 2001 From: Joshua Grams Date: Mon, 11 Jul 2005 18:21:34 +0000 Subject: [PATCH] fixed 2 more dot collision bugs (last ones?) --- main.c | 16 ++++++++++------ rocks.c | 16 ++++++++++++---- shape.c | 4 ++-- 3 files changed, 24 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index 8d131be..b4972a2 100644 --- a/main.c +++ b/main.c @@ -193,20 +193,24 @@ draw_bang_dots(SDL_Surface *s) for(i=0; i= XSIZE || bdot[i].y < 0 || bdot[i].y >= YSIZE) { bdot[i].active = 0; continue; } + + // check collisions if(pixel_hit_rocks(bdot[i].x, bdot[i].y)) { bdot[i].active = 0; continue; } + pixel = pixels + row_inc*(int)(bdot[i].y) + (int)(bdot[i].x); if(bdot[i].c) c = bdot[i].c; else c = heatcolor[(int)(bdot[i].life)*3]; *pixel = c; - bdot[i].life -= bdot[i].decay; - bdot[i].x += bdot[i].dx*t_frame - xscroll; - bdot[i].y += bdot[i].dy*t_frame - yscroll; - - if(bdot[i].life<0) bdot[i].active = 0; } } diff --git a/rocks.c b/rocks.c index a2aa31e..e098fa0 100644 --- a/rocks.c +++ b/rocks.c @@ -308,12 +308,9 @@ hit_rocks(float x, float y, struct shape *shape) } 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 +318,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) { diff --git a/shape.c b/shape.c index 5aa7fb7..92729e9 100644 --- a/shape.c +++ b/shape.c @@ -116,6 +116,6 @@ pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r) if(xoff >= r->w || yoff >= r->h) return 0; - pmask = 1 << (xoff & 31); xoff >>= 5; - return r->mask[yoff*r->mw + xoff] & pmask; + pmask = 1 << (32 - (xoff&0x1f)); + return r->mask[(yoff*r->mw) + (xoff>>5)] & pmask; } -- 1.7.10.4