home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / STK100.ZIP / STKSRC.COM / SPR_ANIM.H < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-20  |  7.9 KB  |  190 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.0
  8.  
  9.               Copyright (C) Jari Karjala 1990
  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.  
  25. #ifndef __ANIM_SPRITE_
  26. typedef void *ANIM_SPRITE;
  27. #endif
  28.  
  29. /**********************************************************************
  30. * The information structure returned by the spr_anim_get_info()
  31. **********************************************************************/
  32. typedef struct _anim_spr_info {
  33.     int     x,y;                            /** location        **/
  34.     int     dx,dy;                          /** movement vector **/
  35.     int     lef, top, rig, bot;             /** limits          **/
  36.     WORD    frame, frame_delay, timeout;    /** time info       **/
  37.     WORD    id;     /** the user spesified id of current sprite **/
  38.     int     w,h;                            /** width&height    **/
  39. } ANIM_SPR_INFO;
  40.  
  41.  
  42. /**********************************************************************
  43. * The values for fx_mode and fx_type. (See spr_anim_set_fx_handler)
  44. **********************************************************************/
  45. #define SPR_ANIM_FX_ALL       (0xFFFF) /** all fx       **/
  46. #define SPR_ANIM_FX_TIMEOUT     (1<<0) /** timeout      **/
  47. #define SPR_ANIM_FX_HIT_X_LIMIT (1<<1) /** hit x limit  **/
  48. #define SPR_ANIM_FX_HIT_Y_LIMIT (1<<2) /** hit y limit  **/
  49. #define SPR_ANIM_FX_HIT_SPRITE  (1<<3) /** hit other spr**/
  50.  
  51. /**********************************************************************
  52. * The FX_RET values for the fx_handler return
  53. **********************************************************************/
  54. #define SPR_ANIM_FX_RET_NOTHING (0)     /** continue normally       **/
  55. #define SPR_ANIM_FX_RET_RE_PUT  (1)     /** put the sprite again    **/
  56. #define SPR_ANIM_FX_RET_STOP    (2)     /** stop the animation      **/
  57. #define SPR_ANIM_FX_RET_DELETE  (3)     /** delete the anim.sprite  **/
  58. #define SPR_ANIM_FX_RET_DESTROY (4)     /** destroy the anim.sprite **/
  59.  
  60.  
  61.  
  62. /**********************************************************************
  63. * Create an animated sprite from the given simple sprites.
  64. * The sprites must have the same width and height attributes.
  65. * Set the following defaults:
  66. *   x,y = 0,0
  67. *   dx,dy = 0,0
  68. *   lef,top,rig,bot = 0,0,spr_max_x,spr_max_y
  69. *   frame_delay, timeout = 0,0
  70. *   fx_mode = FX_ALL 
  71. *   fx_handler = default_fx (TIMEOUT & HIT_SPRITE delete, LIMITs bounce.)
  72. *
  73. * count The number of simple sprites
  74. * ...   The simple sprites
  75. *
  76. * Return: ANIM_SPRITE if no errors or 
  77. *          NULL if memory allocation error, count>ANIM_SPRITE_MAX 
  78. *           or ... contains a NULL sprite.
  79. **********************************************************************/
  80. ANIM_SPRITE spr_anim_create(WORD count, ...);
  81.  
  82. /**********************************************************************
  83. * Start the sprite animation. 
  84. *
  85. * aspr  The animated sprite to use
  86. **********************************************************************/
  87. void spr_anim_start(ANIM_SPRITE aspr);
  88.  
  89. /**********************************************************************
  90. * Stop the animation of the given sprite. This means that after the 
  91. * next pass this sprite will not be shown nor updated.
  92. *
  93. * aspr  The animated sprite to stop
  94. **********************************************************************/
  95. void spr_anim_stop(ANIM_SPRITE aspr);
  96.  
  97. /**********************************************************************
  98. * Delete the given animated sprite. The simple sprites it contains are 
  99. * NOT deleted.
  100. *
  101. * aspr  The animated sprite to use
  102. **********************************************************************/
  103. void spr_anim_delete(ANIM_SPRITE aspr);
  104.  
  105. /**********************************************************************
  106. * Delete the given animated sprite. The simple sprites it contains are 
  107. * ALSO deleted.
  108. *
  109. * aspr  The animated sprite to destroy
  110. **********************************************************************/
  111. void spr_anim_destroy(ANIM_SPRITE aspr);
  112.  
  113. /**********************************************************************
  114. * spr_put all animated sprites then check for special effects (call
  115. * fx_handler(s) if necessary, and act according to the return values). 
  116. * Call spr_next_pass and after that update frame indices and locations 
  117. * of all animated sprites.
  118. *
  119. * Return: The current visual page
  120. **********************************************************************/
  121. WORD spr_anim_next_pass(void);
  122.  
  123.  
  124.  
  125. /**********************************************************************
  126. * Return a pointer into a static info structure of the sprite.
  127. * Note: the structure is only a copy which is overwritten by the 
  128. *       next call to this function.
  129. **********************************************************************/
  130. ANIM_SPR_INFO *spr_anim_get_info(ANIM_SPRITE aspr);
  131.  
  132. /**********************************************************************
  133. * Set the location of the animated sprite.
  134. **********************************************************************/
  135. void spr_anim_set_location(ANIM_SPRITE aspr, WORD x, WORD y);
  136.  
  137. /**********************************************************************
  138. * Set the movement vector of the animated sprite.
  139. **********************************************************************/
  140. void spr_anim_set_vector(ANIM_SPRITE aspr, int dx, int dy);
  141.  
  142. /**********************************************************************
  143. * Set the limits for the animated sprite. The function takes care
  144. * of the bottom/right adjustments due to the size of the sprite.
  145. *
  146. * Note again, that all simple sprites belonging to the animated sprite
  147. * must have the same width & heigth.
  148. **********************************************************************/
  149. void spr_anim_set_limits(ANIM_SPRITE aspr,
  150.                          WORD lef, WORD top, WORD rig, WORD bot);
  151.  
  152.  
  153. /**********************************************************************
  154. * Set the frame delay and timeout values. (-1 means no change for
  155. * that value). 
  156. *
  157. * NOTE: The 'frame' MUST NOT be changed from an fx_handler!!
  158. *
  159. * frame         The current animation frame number (0..nr of frames-1)
  160. * frame_delay   The number of passes for each frame change (0=no change)
  161. * timeout       The number of passes before timeout action (0=infinite)
  162. **********************************************************************/
  163. void spr_anim_set_time(ANIM_SPRITE aspr,
  164.                        int frame, int frame_delay, int timeout);
  165.  
  166. /**********************************************************************
  167. * Sets the special effects handler function.
  168. * The function should have the following prototype:
  169. *
  170. *   WORD func(ANIM_SPRITE aspr, WORD fx_type, SPRITE spr);
  171. *
  172. * The aspr is the animated sprite, fx_type is the type of the
  173. * effect which caused this call and spr is the colliding sprite
  174. * (if fx_type was HIT_SPRITE). 
  175. *
  176. * The function should return one of the FX_RET values defined above.
  177. *
  178. * A NULL handler means that all special effects cause spr_anim_delete.
  179. *
  180. * fx_mask     The types of effects relayed to the handler.
  181. * fx_handler  The handler function.
  182. **********************************************************************/
  183. void spr_anim_set_fx_handler(ANIM_SPRITE aspr, 
  184.                              WORD fx_mask, 
  185.                              WORD (fx_handler)(ANIM_SPRITE,WORD,SPRITE));
  186.  
  187. #endif
  188.  
  189.