1.1 --- a/include/image.h Sat Nov 10 17:58:49 2018 +0100
1.2 +++ b/include/image.h Sat Nov 10 18:53:06 2018 +0100
1.3 @@ -69,15 +69,39 @@
1.4
1.5
1.6
1.7 -/* Initialise stored regions, allocating memory and a structure to access it. */
1.8 +/* A simple sprite abstraction. */
1.9 +
1.10 +typedef struct
1.11 +{
1.12 + /* The sprite image. */
1.13 +
1.14 + image_t *image;
1.15 +
1.16 + /* The stored regions to be used to unplot the sprite. */
1.17 +
1.18 + stored_regions_t *regions;
1.19 +
1.20 + /* The vertical scaling factor translating display rows to image
1.21 + coordinates. */
1.22 +
1.23 + int yscale;
1.24
1.25 -#define Stored_Regions(NAME, FRAMES, SIZE) \
1.26 - uint8_t __##NAME##_image[FRAMES * SIZE]; \
1.27 - position_t __##NAME##_pos[FRAMES]; \
1.28 - stored_regions_t NAME = { \
1.29 - .image=__##NAME##_image, \
1.30 - .size=SIZE, \
1.31 - .stored=0, \
1.32 +} sprite_t;
1.33 +
1.34 +
1.35 +
1.36 +/* Initialise stored regions, allocating memory and a structure to access it.
1.37 +
1.38 + Stored_Regions(<name>, int, int)
1.39 +*/
1.40 +
1.41 +#define Stored_Regions(NAME, FRAMES, SIZE) \
1.42 + uint8_t __##NAME##_image[(FRAMES) * (SIZE)]; \
1.43 + position_t __##NAME##_pos[FRAMES]; \
1.44 + stored_regions_t NAME = { \
1.45 + .image=__##NAME##_image, \
1.46 + .size=SIZE, \
1.47 + .stored=0, \
1.48 .pos=__##NAME##_pos};
1.49
1.50 /* Access functions. */
1.51 @@ -86,4 +110,20 @@
1.52
1.53 uint8_t *image_get_stored_region(stored_regions_t *r, int frame);
1.54
1.55 +
1.56 +
1.57 +/* Initialise a sprite object using an existing image, creating stored regions
1.58 + for the animation of the sprite.
1.59 +
1.60 + Sprite(<name>, image_t *, int, int)
1.61 +*/
1.62 +
1.63 +#define Sprite(NAME, IMAGE, FRAMES, YSCALE) \
1.64 + Stored_Regions(__##NAME##_regions, FRAMES, \
1.65 + (IMAGE)->width * (IMAGE)->height * (YSCALE)); \
1.66 + sprite_t NAME = { \
1.67 + .image=IMAGE, \
1.68 + .regions=&(__##NAME##_regions), \
1.69 + .yscale=YSCALE};
1.70 +
1.71 #endif /* __IMAGE_H__ */