JasonWoof Got questions, comments, patches, etc.? Contact Jason Woofenden
we now return you to your regularly scheduled exploding 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 0
12 #define SHIP 1
13 #define ROCK 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         uint32_t area;
26 };
27
28 Sprite *free_sprites[N_TYPES];  // lists of free sprites, by type.
29
30 void do_collision(Sprite *a, Sprite *b);
31 void collisions(void);
32
33 void init_sprites(void);
34 void reset_sprites(void);
35 void add_sprite(Sprite *s);
36 void move_sprite(Sprite *s);
37 void move_sprites(void);
38
39 Sprite *collides(Sprite *s);
40 int pixel_collides(float x, float y);
41 void load_sprite(Sprite *sprite, char *filename);
42
43 void bounce(Sprite *a, Sprite *b);
44
45
46 // extended sprites
47
48 struct ship {
49         // core sprite fields
50         int8_t sprite_type;
51         struct ship *next;
52         float x, y;
53         float dx, dy;
54         SDL_Surface *image;
55         int w, h;
56         int mask_w;
57         uint32_t *mask;
58         uint32_t area;
59         // SHIP extras
60         int lives;
61         int jets;
62 };
63
64 struct rock {
65         // core sprite fields
66         int8_t sprite_type;
67         struct rock *next;
68         float x, y;
69         float dx, dy;
70         SDL_Surface *image;
71         int w, h;
72         int mask_w;
73         uint32_t *mask;
74         uint32_t area;
75         // ROCK extras
76         int type;
77 };
78
79
80
81 static inline void
82 insert_sprite(Sprite **head, Sprite *s)
83 {
84         s->next = *head;
85         *head = s;
86 }
87
88
89 static inline Sprite *
90 remove_sprite(Sprite **head)
91 {
92         Sprite *s = *head;
93         *head = s->next;
94         return s;
95 }
96
97
98 static inline void
99 draw_sprite(Sprite *s)
100 {
101         SDL_Rect dest;
102         if(s->type < 0) return;
103         dest.x = s->x; dest.y = s->y;
104         SDL_BlitSurface(s->image, NULL, surf_screen, &dest);
105 }
106
107 #endif // VOR_SPRITE_H