JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
Updated collide to take two sprites.
[vor.git] / sprite.h
1 #ifndef VOR_SHAPE_H
2 #define VOR_SHAPE_H
3
4 #include <SDL.h>
5 #include <inttypes.h>
6
7 typedef union sprite Sprite;
8
9
10 // Shape stuff
11
12 struct shape {
13         int w, h;
14         int mw; // mask width (number of uint32's)
15         uint32_t *mask;
16         uint32_t area;
17 };
18
19 void get_shape(SDL_Surface *img, struct shape *s);
20 int collide(Sprite *r, Sprite *s);
21 int pixel_collide(unsigned int xdiff, unsigned int ydiff, struct shape *r);
22
23
24
25 // Sprite stuff
26
27 #define SPRITE(x) ((Sprite *) (x))
28
29 struct base_sprite {
30         uint8_t type;
31         Sprite *next;
32         float x, y;
33         float dx, dy;
34         SDL_Surface *image;
35         struct shape *shape;
36 };
37
38 struct rock {
39         // core sprite fields
40         uint8_t sprite_type;
41         Sprite *next;
42         float x, y;
43         float dx, dy;
44         SDL_Surface *image;
45         struct shape *shape;
46         // ROCK extras
47         int type;
48 };
49
50 struct ship {
51         // core sprite fields
52         uint8_t sprite_type;
53         Sprite *next;
54         float x, y;
55         float dx, dy;
56         SDL_Surface *image;
57         struct shape *shape;
58         // SHIP extras
59         int lives;
60         int jets;
61 };
62
63 union sprite {
64         uint8_t type;
65         struct base_sprite sprite;
66         struct rock rock;
67         struct ship ship;
68 };
69
70 #define BASE_SPRITE 0
71 #define SHIP_SPRITE 1
72 #define ROCK_SPRITE 2
73
74 SDL_Surface *load_image(char *filename);
75 void load_sprite(Sprite *sprite, char *filename);
76
77 #endif // VOR_SHAPE_H