home *** CD-ROM | disk | FTP | other *** search
/ Garbo / Garbo.cdr / pc / progrmng / stk110.lzh / STKSRC.COM / SPR_ANIM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1991-02-25  |  8.9 KB  |  207 lines

  1. /**********************************************************************
  2. * spr_anim.h
  3. * Routines for automatic sprite animation and movement.
  4. **********************************************************************
  5.                     This file is part of
  6.  
  7.           STK -- The sprite toolkit -- version 1.1
  8.  
  9.               Copyright (C) Jari Karjala 1991
  10.  
  11. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  12. resolution sprite graphics with PCompatible hardware. This toolkit 
  13. is provided as is without any warranty or such thing. See the file
  14. COPYING for further information.
  15.  
  16. **********************************************************************
  17. **********************************************************************/
  18.  
  19. #ifndef __SPR_ANIM_H_
  20. #define __SPR_ANIM_H_
  21.  
  22. #include "grtypes.h"
  23.  
  24. /***** Datatypes *****/
  25.  
  26. #ifndef __ANIM_SPRITE_
  27. typedef void *ANIM_SPRITE;
  28. #endif
  29. /**********************************************************************
  30. * The animated sprite type is private. The handle must be void pointer 
  31. * due to the TC which does not allow "struct _anim_sprite *ANIM_SPRITE"  
  32. * without a "struct _anim_sprite" defined in the same file.
  33. **********************************************************************/
  34.  
  35. /**********************************************************************
  36. * The information structure returned by the spr_anim_get_info():
  37. **********************************************************************/
  38. typedef struct _anim_spr_info {
  39.     int     x,y;                            /** location        **/
  40.     int     dx,dy;                          /** movement vector **/
  41.     int     lef, top, rig, bot;             /** limits          **/
  42.     WORD    frame, frame_delay, timeout;    /** time info       **/
  43.     WORD    id;     /** the user spesified id of current sprite **/
  44.     int     w,h;                            /** width&height    **/
  45. } ANIM_SPR_INFO;
  46.  
  47. /***** Literal defines *****/
  48.  
  49. /**********************************************************************
  50. * The values for fx_mode and fx_type: (See spr_anim_set_fx_handler)
  51. **********************************************************************/
  52. #define SPR_ANIM_FX_ALL         (0x0F) /** all fx       **/
  53. #define SPR_ANIM_FX_TIMEOUT     (1<<0) /** timeout      **/
  54. #define SPR_ANIM_FX_HIT_X_LIMIT (1<<1) /** hit x limit  **/
  55. #define SPR_ANIM_FX_HIT_Y_LIMIT (1<<2) /** hit y limit  **/
  56. #define SPR_ANIM_FX_HIT_SPRITE  (1<<3) /** hit other spr**/
  57.  
  58. /**********************************************************************
  59. *
  60. * The FX_RET values for the fx_handler return codes:
  61. **********************************************************************/
  62. #define SPR_ANIM_FX_RET_NOTHING (0)     /** continue normally       **/
  63. #define SPR_ANIM_FX_RET_RE_PUT  (1)     /** put the sprite again    **/
  64. #define SPR_ANIM_FX_RET_STOP    (2)     /** stop the animation      **/
  65. #define SPR_ANIM_FX_RET_DELETE  (3)     /** delete the anim.sprite  **/
  66. #define SPR_ANIM_FX_RET_DESTROY (4)     /** destroy the anim.sprite **/
  67.  
  68. /***** Function prototypes *****/
  69.  
  70. ANIM_SPRITE spr_anim_create(WORD count, ...);
  71. /**********************************************************************
  72. * Create an animated sprite from the given simple sprites.
  73. * The sprites must have the same width and height.
  74. * Set the following defaults:
  75. *   x,y = 0,0
  76. *   dx,dy = 0,0
  77. *   lef,top,rig,bot = 0,0,spr_max_x,spr_max_y
  78. *   frame_delay, timeout = 0,0
  79. *   fx_mode = FX_ALL 
  80. *   fx_handler = default_fx (TIMEOUT & HIT_SPRITE delete, LIMITs bounce.)
  81. *
  82. * count The number of simple sprites, at most 20.
  83. * ...   The simple sprites
  84. *
  85. * Return: ANIM_SPRITE if no errors or 
  86. *          NULL if memory allocation error, count>20
  87. *           or ... contains a NULL sprite.
  88. **********************************************************************/
  89.  
  90. void spr_anim_start(ANIM_SPRITE aspr);
  91. /**********************************************************************
  92. * Start the sprite animation. 
  93. *
  94. * aspr  The animated sprite to use
  95. **********************************************************************/
  96.  
  97. void spr_anim_stop(ANIM_SPRITE aspr);
  98. /**********************************************************************
  99. * Stop the animation of the given sprite. This means that after the 
  100. * next pass this sprite will not be shown nor updated. Sprite can
  101. * be restarted with the function spr_anim_start.
  102. *
  103. * aspr  The animated sprite to stop
  104. **********************************************************************/
  105.  
  106. void spr_anim_delete(ANIM_SPRITE aspr);
  107. /**********************************************************************
  108. * Delete the given animated sprite. The simple sprites it contains are 
  109. * NOT deleted.
  110. *
  111. * aspr  The animated sprite to use
  112. **********************************************************************/
  113.  
  114. void spr_anim_destroy(ANIM_SPRITE aspr);
  115. /**********************************************************************
  116. * Delete the given animated sprite. The simple sprites it contains are 
  117. * ALSO deleted.
  118. *
  119. * aspr  The animated sprite to destroy
  120. **********************************************************************/
  121.  
  122. WORD spr_anim_next_pass(void);
  123. /**********************************************************************
  124. * This function handles the sprite animation and display.
  125. * 1. Spr_put all animated sprites.
  126. * 2. Check for special effects.
  127. *   a. Call fx_handlers if necessary.
  128. *   b. Act according to the fx_handler return values.
  129. * 3. Call spr_next_pass.
  130. * 4. Update frame indices and locations of all animated sprites.
  131. *
  132. * Return: The current visual page number
  133. **********************************************************************/
  134.  
  135.  
  136.  
  137. ANIM_SPR_INFO *spr_anim_get_info(ANIM_SPRITE aspr);
  138. /**********************************************************************
  139. * Return a pointer into a static info structure of the sprite.
  140. *
  141. * NOTE: the structure is only a copy which is overwritten by the 
  142. *       next call to this function.
  143. **********************************************************************/
  144.  
  145. void spr_anim_set_location(ANIM_SPRITE aspr, WORD x, WORD y);
  146. /**********************************************************************
  147. * Set the location of the animated sprite.
  148. **********************************************************************/
  149.  
  150. void spr_anim_set_vector(ANIM_SPRITE aspr, int dx, int dy);
  151. /**********************************************************************
  152. * Set the movement vector of the animated sprite. The (dx,dy) are added
  153. * to the (x,y) attributes of the sprite during every pass. Negative
  154. * values mean left and up directions in screen.
  155. **********************************************************************/
  156.  
  157. void spr_anim_set_limits(ANIM_SPRITE aspr,
  158.                          WORD lef, WORD top, WORD rig, WORD bot);
  159. /**********************************************************************
  160. * Set the limits for the animated sprite. The function takes care
  161. * of the bottom/right adjustments due to the size of the sprite.
  162. * The fx_handler will be triggered by these limits, if allowed.
  163. *
  164. * Note again, that all simple sprites belonging to the animated sprite
  165. * must have the same width & heigth or the limit checking will not work.
  166. **********************************************************************/
  167.  
  168. void spr_anim_set_time(ANIM_SPRITE aspr,
  169.                        int frame, int frame_delay, int timeout);
  170. /**********************************************************************
  171. * Set the frame delay and timeout values. (-1 means no change for
  172. * that value). 
  173. *
  174. * NOTE: The 'frame' MUST NOT be changed from an fx_handler!!
  175. *
  176. * frame         The current animation frame number (0..nr of frames-1)
  177. * frame_delay   The number of passes for each frame change (0=no change)
  178. * timeout       The number of passes before timeout action (0=infinite)
  179. **********************************************************************/
  180.  
  181. void spr_anim_set_fx_handler(ANIM_SPRITE aspr, 
  182.                              WORD fx_mask, 
  183.                              WORD (fx_handler)(ANIM_SPRITE,WORD,SPRITE));
  184. /**********************************************************************
  185. * Sets the special effects handler function for the given ANIM_SPRITE.
  186. *
  187. * The function should have the following prototype:
  188. *
  189. *   WORD handler_name(ANIM_SPRITE aspr, WORD fx_type, SPRITE spr);
  190. *
  191. * The function will be called with the following parameters:
  192. * aspr      the animated sprite whose handler this is, 
  193. * fx_type   the type of the effect which caused this call,
  194. * spr       the colliding sprite (if fx_type was HIT_SPRITE). 
  195. *
  196. * The function must return one of the SPR_ANIM_FX_RET values defined above.
  197. *
  198. * A NULL handler means that all special effects cause spr_anim_delete.
  199. *
  200. * fx_mask     The types of effects which cause a call to the handler,
  201. *             for example: SPR_ANIM_FX_HIT_Y_LIMIT|SPR_ANIM_FX_HIT_X_LIMIT
  202. * fx_handler  The handler function.
  203. **********************************************************************/
  204. #endif
  205.  
  206.