#include <SDL.h>
#include <inttypes.h>
-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
-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);
+void get_shape(Sprite *s);
int collide(Sprite *r, Sprite *s);
-int pixel_collide(unsigned int xdiff, unsigned int ydiff, struct shape *r);
+int pixel_collide(Sprite *s, int x, int y);
-// Sprite stuff
-
-#define SPRITE(x) ((Sprite *) (x))
+// extended sprites
-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);