X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.h;h=75d7730b1f67cb2f8848f10e93746c4414f50fae;hp=e1216cf03cb5d452846b8c83d4233bf4e1641bfa;hb=110f0b2d1118b17f7ba1a0c7eeb2b01190ccec99;hpb=bb819ae60e78c875e66fe2de3ac7fa2b9824a1e5 diff --git a/sprite.h b/sprite.h index e1216cf..75d7730 100644 --- a/sprite.h +++ b/sprite.h @@ -8,13 +8,14 @@ typedef struct sprite Sprite; #define SPRITE(x) ((Sprite *) (x)) -#define BASE_SPRITE 0 -#define SHIP_SPRITE 1 -#define ROCK_SPRITE 2 +#define BASE 0 +#define SHIP 1 +#define ROCK 2 #define N_TYPES 3 struct sprite { int8_t type; + int8_t flags; Sprite *next; float x, y; float dx, dy; @@ -25,9 +26,19 @@ struct sprite { uint32_t area; }; +#define MOVE 1 +#define DRAW 2 +#define COLLIDE 4 + +#define COLLIDES(sprite) ((sprite)->flags & COLLIDE) + Sprite *free_sprites[N_TYPES]; // lists of free sprites, by type. +void do_collision(Sprite *a, Sprite *b); +void collisions(void); + void init_sprites(void); +void reset_sprites(void); void add_sprite(Sprite *s); void move_sprite(Sprite *s); void move_sprites(void); @@ -44,6 +55,7 @@ void bounce(Sprite *a, Sprite *b); struct ship { // core sprite fields int8_t sprite_type; + int8_t flags; struct ship *next; float x, y; float dx, dy; @@ -60,6 +72,7 @@ struct ship { struct rock { // core sprite fields int8_t sprite_type; + int8_t flags; struct rock *next; float x, y; float dx, dy; @@ -95,9 +108,10 @@ static inline void draw_sprite(Sprite *s) { SDL_Rect dest; - if(s->type == NONE) return; - dest.x = s->x; dest.y = s->y; - SDL_BlitSurface(s->image, NULL, surf_screen, &dest); + if(s->flags & DRAW) { + dest.x = s->x; dest.y = s->y; + SDL_BlitSurface(s->image, NULL, surf_screen, &dest); + } } #endif // VOR_SPRITE_H