X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.h;h=e1216cf03cb5d452846b8c83d4233bf4e1641bfa;hp=939de0855470e2a7b41161e3be626bf8d18f8073;hb=bb819ae60e78c875e66fe2de3ac7fa2b9824a1e5;hpb=f8a464d8eed8cf611c0c3f80166d2a650efb1485 diff --git a/sprite.h b/sprite.h index 939de08..e1216cf 100644 --- a/sprite.h +++ b/sprite.h @@ -1,77 +1,103 @@ -#ifndef VOR_SHAPE_H -#define VOR_SHAPE_H +#ifndef VOR_SPRITE_H +#define VOR_SPRITE_H #include #include -typedef union sprite Sprite; +typedef struct sprite Sprite; +#define SPRITE(x) ((Sprite *) (x)) -// Shape stuff +#define BASE_SPRITE 0 +#define SHIP_SPRITE 1 +#define ROCK_SPRITE 2 +#define N_TYPES 3 -struct shape { +struct sprite { + int8_t type; + Sprite *next; + float x, y; + float dx, dy; + SDL_Surface *image; int w, h; - int mw; // mask width (number of uint32's) + int mask_w; uint32_t *mask; uint32_t area; }; -void get_shape(SDL_Surface *img, struct shape *s); -int collide(Sprite *r, Sprite *s); -int pixel_collide(unsigned int xdiff, unsigned int ydiff, struct shape *r); +Sprite *free_sprites[N_TYPES]; // lists of free sprites, by type. +void init_sprites(void); +void add_sprite(Sprite *s); +void move_sprite(Sprite *s); +void move_sprites(void); +Sprite *collides(Sprite *s); +int pixel_collides(float x, float y); +void load_sprite(Sprite *sprite, char *filename); -// Sprite stuff +void bounce(Sprite *a, Sprite *b); -#define SPRITE(x) ((Sprite *) (x)) -struct base_sprite { - uint8_t type; - Sprite *next; +// extended sprites + +struct ship { + // core sprite fields + int8_t sprite_type; + struct ship *next; float x, y; float dx, dy; SDL_Surface *image; - struct shape *shape; + int w, h; + int mask_w; + uint32_t *mask; + uint32_t area; + // SHIP extras + int lives; + int jets; }; struct rock { // core sprite fields - uint8_t sprite_type; - Sprite *next; + int8_t sprite_type; + struct rock *next; float x, y; float dx, dy; SDL_Surface *image; - struct shape *shape; + int w, h; + int mask_w; + uint32_t *mask; + uint32_t area; // ROCK extras int type; }; -struct ship { - // core sprite fields - uint8_t sprite_type; - Sprite *next; - float x, y; - float dx, dy; - SDL_Surface *image; - struct shape *shape; - // SHIP extras - int lives; - int jets; -}; -union sprite { - uint8_t type; - struct base_sprite sprite; - struct rock rock; - struct ship ship; -}; -#define BASE_SPRITE 0 -#define SHIP_SPRITE 1 -#define ROCK_SPRITE 2 +static inline void +insert_sprite(Sprite **head, Sprite *s) +{ + s->next = *head; + *head = s; +} -SDL_Surface *load_image(char *filename); -void load_sprite(Sprite *sprite, char *filename); -#endif // VOR_SHAPE_H +static inline Sprite * +remove_sprite(Sprite **head) +{ + Sprite *s = *head; + *head = s->next; + return s; +} + + +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); +} + +#endif // VOR_SPRITE_H