X-Git-Url: https://jasonwoof.com/gitweb/?p=vor.git;a=blobdiff_plain;f=sprite.h;h=7df8631ac846214f232a898cfce06bd0bcbe34ff;hp=c2d0a8e1757859c3ff1ab53a38766686f448fe18;hb=0d415d88f7ecd55273b09b619170078f7d35a910;hpb=f33f1a05297ce0156030f0f78ecf5b84e00d424c diff --git a/sprite.h b/sprite.h index c2d0a8e..7df8631 100644 --- a/sprite.h +++ b/sprite.h @@ -1,74 +1,66 @@ #ifndef VOR_SHAPE_H #define VOR_SHAPE_H -#include +#include #include +typedef struct sprite Sprite; -// Shape stuff +#define SPRITE(x) ((Sprite *) (x)) + +#define BASE_SPRITE 0 +#define SHIP_SPRITE 1 +#define ROCK_SPRITE 2 -struct shape { +struct sprite { + uint8_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(int xdiff, int ydiff, struct shape *r, struct shape *s); -int pixel_collide(unsigned int xoff, unsigned int yoff, struct shape *r); - +void get_shape(Sprite *s); +int collide(Sprite *r, Sprite *s); +int pixel_collide(Sprite *s, int x, int y); -// Sprite stuff -typedef union sprite Sprite; +// extended sprites -#define SPRITE(x) ((Sprite *) (x)) - -struct base_sprite { - uint8_t type; - Sprite *next; +struct ship { + // core sprite fields + uint8_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; + // SHIP extras + int lives; + int jets; }; struct rock { // core sprite fields uint8_t sprite_type; - Sprite *next; + struct rock *next; float x, y; float dx, dy; SDL_Surface *image; - struct shape *shape; + int w, h; + int mask_w; + uint32_t *mask; // 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 +SDL_Surface *load_image(char *filename); +void load_sprite(Sprite *sprite, char *filename); #endif // VOR_SHAPE_H