X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.h;h=3cb2c0e4f5f619aae8f79e9c6748c740a48a85fa;hp=4c0cefdc107ccec500d6f145fb863beb26d381d3;hb=1d9107a3d43b3f57087edee14f1eaf7c1f3db54e;hpb=5c8f059629c2127848ce4051296d2f5897bf5c0f diff --git a/sprite.h b/sprite.h index 4c0cefd..3cb2c0e 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; @@ -22,25 +23,40 @@ struct sprite { int w, h; int mask_w; uint32_t *mask; + 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); -int collides(Sprite *s); -int pixel_collides(float x, float y); +Sprite *collides(Sprite *s); +Sprite * pixel_collides(float x, float y); void load_sprite(Sprite *sprite, char *filename); +float sprite_mass(Sprite *s); +void bounce(Sprite *a, Sprite *b); + // extended sprites struct ship { // core sprite fields int8_t sprite_type; + int8_t flags; struct ship *next; float x, y; float dx, dy; @@ -48,6 +64,7 @@ struct ship { int w, h; int mask_w; uint32_t *mask; + uint32_t area; // SHIP extras int lives; int jets; @@ -56,6 +73,7 @@ struct ship { struct rock { // core sprite fields int8_t sprite_type; + int8_t flags; struct rock *next; float x, y; float dx, dy; @@ -63,6 +81,7 @@ struct rock { int w, h; int mask_w; uint32_t *mask; + uint32_t area; // ROCK extras int type; }; @@ -90,9 +109,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