JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
fixed 2 more dot collision bugs (last ones?)
authorJoshua Grams <josh@qualdan.com>
Mon, 11 Jul 2005 18:21:34 +0000 (18:21 +0000)
committerJoshua Grams <josh@qualdan.com>
Mon, 11 Jul 2005 18:21:34 +0000 (18:21 +0000)
main.c
rocks.c
shape.c

diff --git a/main.c b/main.c
index 8d131be..b4972a2 100644 (file)
--- a/main.c
+++ b/main.c
@@ -193,20 +193,24 @@ draw_bang_dots(SDL_Surface *s)
        for(i=0; i<MAXBANGDOTS; i++) {
                if(!bdot[i].active) continue;
 
        for(i=0; i<MAXBANGDOTS; i++) {
                if(!bdot[i].active) continue;
 
-               // If the dot has drifted outside the screen, kill it
+               // decrement life and maybe kill
+               bdot[i].life -= bdot[i].decay;
+               if(bdot[i].life<0) { bdot[i].active = 0; continue; }
+
+               // move and clip
+               bdot[i].x += bdot[i].dx*t_frame - xscroll;
+               bdot[i].y += bdot[i].dy*t_frame - yscroll;
                if(bdot[i].x < 0 || bdot[i].x >= XSIZE || bdot[i].y < 0 || bdot[i].y >= YSIZE) {
                        bdot[i].active = 0;
                        continue;
                }
                if(bdot[i].x < 0 || bdot[i].x >= 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; }
                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;
                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 (file)
--- a/rocks.c
+++ b/rocks.c
@@ -308,12 +308,9 @@ hit_rocks(float x, float y, struct shape *shape)
 }
 
 int
 }
 
 int
-pixel_hit_rocks(float x, float y)
+pixel_hit_in_bucket(int b, float x, float y)
 {
 {
-       int b;
        struct rock_struct *r;
        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;
        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;
 }
 
        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)
 {
 void
 blast_rocks(float x, float y, float radius, int onlyslow)
 {
diff --git a/shape.c b/shape.c
index 5aa7fb7..92729e9 100644 (file)
--- 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;
 
        
        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;
 }
 }