1 #ifndef __SPRITE_H__ 2 #define __SPRITE_H__ 3 #include <SDL/SDL.h> 4 #include "datafun.h" 5 6 /*! \brief Simple sprite struct 7 */ 8 struct sprite { 9 Uint32 start_tick; 10 SDL_Surface **surface_ptr; 11 Uint16 surface_count; 12 Uint16 speed_divisor; 13 }; 14 15 /*! \brief Draw a sprite 16 * 17 * It will draw a sprite while animating it. 18 * 19 * \param sprite pointer to a sprite struct 20 * \param x x-position 21 * \param y y-position 22 * \param target target surface 23 * \param now return from SDL_GetTicks, used for selecting the frame 24 * \return return value of SDL_BlitSurface 25 */ 26 int draw_sprite(struct sprite *sprite, Sint16 x, Sint16 y, 27 SDL_Surface * target, Uint32 now); 28 29 /*! \brief get current image 30 * \param sprite sprite pointer 31 * \param now return from SDL_GetTicks 32 * \return the current surface 33 */ 34 SDL_Surface *get_current_sprite_surface(struct sprite *sprite, Uint32 now); 35 36 /*! \brief Initialise a sprite struct 37 * 38 * \param sprite pointer to a sprite 39 * \param surfaces pointer to an array of surfaces 40 * \param surface_count number of surfaces in this array 41 * \param delay delay in ms for each frame 42 * \param now return from SDL_GetTicks 43 */ 44 void init_sprite(struct sprite *sprite, SDL_Surface ** surfaces, 45 Uint16 surface_count, Uint16 delay, Uint32 now); 46 47 48 /*! \brief Initialise a sprite struct 49 * 50 * This function uses the surfaces as given by an sdl_surfaces_t 51 * struct. This function was introduced as loading the surfaces and 52 * using them for a sprite happen quite often. 53 * 54 * \param sprite pointer to a sprite 55 * \param surfaces pointer to an array of surfaces 56 * \param surface_count number of surfaces in this array 57 * \param delay delay in ms for each frame 58 * \param now return from SDL_GetTicks 59 */ 60 void init_sprite2(struct sprite *sprite, sdl_surfaces_t *surfaces, Uint16 delay, Uint32 now); 61 62 #endif 63