Got questions, comments, patches, etc.?
Contact Jason Woofenden
gitweb
/
vor.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
moved grid stuff from rocks.c to sprite.c
[vor.git]
/
sprite.h
diff --git
a/sprite.h
b/sprite.h
index
7df8631
..
4c0cefd
100644
(file)
--- a/
sprite.h
+++ b/
sprite.h
@@
-1,5
+1,5
@@
-#ifndef VOR_SHAPE_H
-#define VOR_SHAPE_H
+#ifndef VOR_SPRITE_H
+#define VOR_SPRITE_H
#include <SDL.h>
#include <inttypes.h>
#include <SDL.h>
#include <inttypes.h>
@@
-11,9
+11,10
@@
typedef struct sprite Sprite;
#define BASE_SPRITE 0
#define SHIP_SPRITE 1
#define ROCK_SPRITE 2
#define BASE_SPRITE 0
#define SHIP_SPRITE 1
#define ROCK_SPRITE 2
+#define N_TYPES 3
struct sprite {
struct sprite {
- uint8_t type;
+ int8_t type;
Sprite *next;
float x, y;
float dx, dy;
Sprite *next;
float x, y;
float dx, dy;
@@
-23,17
+24,23
@@
struct sprite {
uint32_t *mask;
};
uint32_t *mask;
};
-void get_shape(Sprite *s);
-int collide(Sprite *r, Sprite *s);
-int pixel_collide(Sprite *s, int x, int y);
+Sprite *free_sprites[N_TYPES]; // lists of free sprites, by type.
+void init_sprites(void);
+void add_sprite(Sprite *s);
+void move_sprite(Sprite *s);
+void move_sprites(void);
+
+int collides(Sprite *s);
+int pixel_collides(float x, float y);
+void load_sprite(Sprite *sprite, char *filename);
// extended sprites
struct ship {
// core sprite fields
// extended sprites
struct ship {
// core sprite fields
- uint8_t sprite_type;
+ int8_t sprite_type;
struct ship *next;
float x, y;
float dx, dy;
struct ship *next;
float x, y;
float dx, dy;
@@
-48,7
+55,7
@@
struct ship {
struct rock {
// core sprite fields
struct rock {
// core sprite fields
- uint8_t sprite_type;
+ int8_t sprite_type;
struct rock *next;
float x, y;
float dx, dy;
struct rock *next;
float x, y;
float dx, dy;
@@
-60,7
+67,32
@@
struct rock {
int type;
};
int type;
};
-SDL_Surface *load_image(char *filename);
-void load_sprite(Sprite *sprite, char *filename);
-#endif // VOR_SHAPE_H
+
+static inline void
+insert_sprite(Sprite **head, Sprite *s)
+{
+ s->next = *head;
+ *head = s;
+}
+
+
+static inline Sprite *
+remove_sprite(Sprite **head)
+{
+ Sprite *s = *head;
+ *head = s->next;
+ return s;
+}
+
+
+static inline void
+draw_sprite(Sprite *s)
+{
+ SDL_Rect dest;
+ if(s->type == NONE) return;
+ dest.x = s->x; dest.y = s->y;
+ SDL_BlitSurface(s->image, NULL, surf_screen, &dest);
+}
+
+#endif // VOR_SPRITE_H