X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.c;h=abe9fb37f9762804ed923d69d679c51f4e4eba4c;hp=809547b29431a96c861b3d343d95dcc7ab68d11e;hb=f1cd2ff38dd9f3c5c4925d8a5f9588129b3bf343;hpb=cffdedca2aba899f3e0f8b98f67b9125edf6b5a5 diff --git a/sprite.c b/sprite.c index 809547b..abe9fb3 100644 --- a/sprite.c +++ b/sprite.c @@ -302,36 +302,37 @@ pixel_collide(Sprite *s, int x, int y) return s->mask[(y*s->mask_w) + (x>>5)] & pmask; } -int +Sprite * pixel_hit_in_square(Sprite *r, float x, float y) { for(; r; r=r->next) { - if(COLLIDES(r) && pixel_collide(r, x, y)) return 1; + if(COLLIDES(r) && pixel_collide(r, x, y)) return r; } return 0; } -int +Sprite * pixel_collides(float x, float y) { int l, t; Sprite **sq; + Sprite *ret; l = (x + grid_size) / grid_size; t = (y + grid_size) / grid_size; sq = &sprites[set][l + t*gw]; - if(pixel_hit_in_square(*sq, x, y)) return true; - if(l > 0 && pixel_hit_in_square(*(sq-1), x, y)) return true; - if(t > 0 && pixel_hit_in_square(*(sq-gw), x, y)) return true; - if(l > 0 && t > 0 && pixel_hit_in_square(*(sq-1-gw), x, y)) return true; - return false; + if((ret = pixel_hit_in_square(*sq, x, y))) return ret; + if(l > 0 && (ret = pixel_hit_in_square(*(sq-1), x, y))) return ret; + if(t > 0 && (ret = pixel_hit_in_square(*(sq-gw), x, y))) return ret; + if(l > 0 && t > 0 && (ret = pixel_hit_in_square(*(sq-1-gw), x, y))) return ret; + return 0; } -static float +float sprite_mass(Sprite *s) { if(s->type == SHIP) return s->area; - else if(s->type == ROCK) return 3*s->area; + else if(s->type == ROCK) return 3 * s->area; else return 0; }