X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.c;h=923e967eff1f6cf2d17a8df6829fc5ec10ae4ed5;hp=6a20442a4080d993ca30e2aa52112f044f1461e0;hb=HEAD;hpb=100372ba9cc83542b9d9894001d70f40e28f8f4b diff --git a/sprite.c b/sprite.c index 6a20442..923e967 100644 --- a/sprite.c +++ b/sprite.c @@ -1,7 +1,7 @@ #include #include #include -#include "config.h" +#include "vorconfig.h" #include "common.h" #include "globals.h" #include "sprite.h" @@ -88,8 +88,8 @@ init_sprites(void) load_sprites(); grid_size = grid_size * 3 / 2; - gw = (XSIZE-1 + 2*grid_size) / grid_size; - gh = (YSIZE-1 + 2*grid_size) / grid_size; + gw = (XSIZE + 2*grid_size) / grid_size; // -grid-size to XSIZE inclusive (so sprites can be just off either edge) + gh = (YSIZE + 2*grid_size) / grid_size; sprites[0] = malloc(2 * gw * gh * sizeof(Sprite *)); sprites[1] = (void *)sprites[0] + gw * gh * sizeof(Sprite *); @@ -105,6 +105,10 @@ static inline Sprite ** square(int x, int y, int set) { int b = (x+grid_size)/grid_size + gw*((y+grid_size)/grid_size); + if(b >= gw*gh || b < 0) { + fprintf(stderr, "square(%i, %i, %i) = %i\n", x, y, set, b); + ((int*)0)[0] = 0; + } return &sprites[set][b]; } @@ -128,11 +132,11 @@ reset_sprites(void) } void -move_sprite(Sprite *s, float ticks) +move_sprite(Sprite *s) { if(s->flags & MOVE) { - s->x += (s->dx - screendx)*ticks; - s->y += (s->dy - screendy)*ticks; + s->x += (s->dx - screendx)*t_frame; + s->y += (s->dy - screendy)*t_frame; } } @@ -148,7 +152,7 @@ sort_sprite(Sprite *s) } void -move_sprites(float ticks) +move_sprites(void) { int sq; Sprite **head; @@ -158,13 +162,15 @@ move_sprites(float ticks) head=&sprites[set][sq]; while(*head) { Sprite *s = remove_sprite(head); - move_sprite(s, ticks); sort_sprite(s); + move_sprite(s); sort_sprite(s); } } set = 1-set; // switch to other set of sprites. } +// xov: number of bits of overlap +// bit: number of bits in from the left edge of amask where bmask is static int line_collide(int xov, unsigned bit, uint32_t *amask, uint32_t *bmask) { @@ -182,6 +188,8 @@ line_collide(int xov, unsigned bit, uint32_t *amask, uint32_t *bmask) return false; } +// xov: number of bits/pixels of horizontal overlap +// yov: number of bits/pixels of vertical overlap static int mask_collide(int xov, int yov, Sprite *a, Sprite *b) { @@ -195,8 +203,8 @@ mask_collide(int xov, int yov, Sprite *a, Sprite *b) bmask = b->mask; } else { yov = -yov; - amask = a->mask; - bmask = b->mask + ((b->h - yov) * b->mask_w) + word; + amask = a->mask + word; + bmask = b->mask + ((b->h - yov) * b->mask_w); } for(y=0; ynext) - if(collide(r, s)) break; - return r; -} - -Sprite * -collides(Sprite *s) -{ - int l, r, t, b; - Sprite **sq; - Sprite *c; - - 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; - sq = &sprites[set][l + t*gw]; - - if((c = hit_in_square(*sq, s))) return c; - if(l > 0 && (c = hit_in_square(*(sq-1), s))) return c; - if(t > 0 && (c = hit_in_square(*(sq-gw), s))) return c; - if(l > 0 && t > 0 && (c = hit_in_square(*(sq-1-gw), s))) return c; - - if(r > l) { - if((c = hit_in_square(*(sq+1), s))) return c; - if(t > 0 && hit_in_square(*(sq+1-gw), s)) return c; - } - if(b > t) { - if((c = hit_in_square(*(sq+gw), s))) return c; - if(l > 0 && (c = hit_in_square(*(sq-1+gw), s))) return c; - } - if(r > l && b > t && (c = hit_in_square(*(sq+1+gw), s))) return c; - return NULL; -} - int pixel_collide(Sprite *s, int x, int y) {