JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
bouncy ship :)
[vor.git] / sprite.h
1 #ifndef VOR_SPRITE_H
2 #define VOR_SPRITE_H
3
4 #include <SDL.h>
5 #include <inttypes.h>
6
7 typedef struct sprite Sprite;
8
9 #define SPRITE(x) ((Sprite *) (x))
10
11 #define BASE_SPRITE 0
12 #define SHIP_SPRITE 1
13 #define ROCK_SPRITE 2
14 #define N_TYPES 3
15
16 struct sprite {
17         int8_t type;
18         Sprite *next;
19         float x, y;
20         float dx, dy;
21         SDL_Surface *image;
22         int w, h;
23         int mask_w;
24         uint32_t *mask;
25 };
26
27 Sprite *free_sprites[N_TYPES];  // lists of free sprites, by type.
28
29 void init_sprites(void);
30 void add_sprite(Sprite *s);
31 void move_sprite(Sprite *s);
32 void move_sprites(void);
33
34 Sprite *collides(Sprite *s);
35 int pixel_collides(float x, float y);
36 void load_sprite(Sprite *sprite, char *filename);
37
38 void bounce(Sprite *a, Sprite *b);
39
40
41 // extended sprites
42
43 struct ship {
44         // core sprite fields
45         int8_t sprite_type;
46         struct ship *next;
47         float x, y;
48         float dx, dy;
49         SDL_Surface *image;
50         int w, h;
51         int mask_w;
52         uint32_t *mask;
53         // SHIP extras
54         int lives;
55         int jets;
56 };
57
58 struct rock {
59         // core sprite fields
60         int8_t sprite_type;
61         struct rock *next;
62         float x, y;
63         float dx, dy;
64         SDL_Surface *image;
65         int w, h;
66         int mask_w;
67         uint32_t *mask;
68         // ROCK extras
69         int type;
70 };
71
72
73
74 static inline void
75 insert_sprite(Sprite **head, Sprite *s)
76 {
77         s->next = *head;
78         *head = s;
79 }
80
81
82 static inline Sprite *
83 remove_sprite(Sprite **head)
84 {
85         Sprite *s = *head;
86         *head = s->next;
87         return s;
88 }
89
90
91 static inline void
92 draw_sprite(Sprite *s)
93 {
94         SDL_Rect dest;
95         if(s->type == NONE) return;
96         dest.x = s->x; dest.y = s->y;
97         SDL_BlitSurface(s->image, NULL, surf_screen, &dest);
98 }
99
100 #endif // VOR_SPRITE_H