home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / STK100.ZIP / STK.DOC < prev    next >
Encoding:
Text File  |  1990-10-20  |  36.6 KB  |  910 lines

  1. **********************************************************************
  2.                     This file is part of
  3.  
  4.          STK -- The sprite toolkit -- version 1.0
  5.  
  6.               Copyright (C) Jari Karjala 1990
  7.  
  8. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  9. resolution sprite graphics with PCompatible hardware. This toolkit 
  10. is provided as is without any warranty or such thing. See the file
  11. COPYING and the end of this file for further information.
  12.  
  13. **********************************************************************
  14.  
  15.  
  16. STK -- The Sprite ToolKit -- version 1.0, Oct 20, 1990 
  17.  
  18.  
  19.  
  20. Intro
  21. =====
  22.  
  23. The Sprite Toolkit (STK) contains the following sets of functions,
  24. (each function has its set name in front of it):
  25.  
  26. SPR             lowlevel interface to the sprite functions
  27. SPR_HIT         lowlevel collision detection routines
  28. SPR_FIO         lowlevel sprite file IO
  29. SPR_ANIM        higher level interface to the sprite functions
  30. GR              text IO in the graphics mode and keyboard functions
  31. MOUSE           INT 33 interface to the mouse functions.
  32.  
  33. Note that there are two different interface levels to the sprite
  34. routines. 
  35.  
  36. The lowlevel functions provide support for simple sprites which
  37. can be put into the screen, hidden from the screen or deleted.
  38. Collisions between them can be detected. The sprite data can
  39. be read from a file, too.
  40.  
  41. The higher level interface supports animated sprites which are
  42. composed of simple sprites. These animated sprites can move
  43. automatically along some preset direction vector and act on
  44. different special cases, such as hitting the boundary or other
  45. sprite.
  46.  
  47. The GR functions provide a familiar set of basic text IO
  48. functions, like putch, put and printf, but these functions work
  49. in the graphics mode. There are also GR functions for direct
  50. reading of the keymap. These functions detect multiple
  51. simultaneus keypresses, as required by most arcade style games.
  52.  
  53. The MOUSE functions provide a very simple interface to the mouse
  54. driver. They are not much more that names to the INT 33 functions.
  55.  
  56.  
  57.  
  58.  
  59. Using the lowlevel sprite functions
  60. ===================================
  61.  
  62.  
  63. Initializing
  64. ------------
  65.  
  66. The first thing to do in a program which uses the STK is to
  67. start the graphics mode and initialize the sprites. This is done
  68. by the functions gr_detect, gr_start and spr_initialize (for
  69. further information, see The STK Function Reference). Now we are
  70. ready to use the STK functions.
  71.  
  72.  
  73. Creating and destroying sprites
  74. -------------------------------
  75.  
  76. The sprites are represented by SPRITE handles. The exact definition
  77. of the object pointed by a handle is private to the STK
  78. implementation, therefore the sprites can be manipulated only
  79. with the provided functions.
  80.  
  81. Each sprite has a shape defined by a sprite map. These can be
  82. created by the SPRED sprite editor. Each sprite map contains the
  83. actual shape of the sprite and the mask which describe the
  84. transparent parts of the sprite.
  85.  
  86. We must create sprites before we can do anything with them. This
  87. is done with the function spr_create, if we have the sprite
  88. shape bitmaps in static arrays, or with the function
  89. spr_fio_read_smp if the shape is in a sprite map file. Both of
  90. these functions return a SPRITE handle. You can make copies of
  91. sprites by the spr_copy function (you should spr_share the
  92. sprite first to save memory, since copies of shared sprites
  93. share the shape data which can take quite much memory).
  94.  
  95. The sprite resolution parameter in the spr_create means the
  96. number of shifted images per 8 pixels, ie 4 means that the X
  97. coordinates 0 and 1 will map into the same screen position.  Try
  98. giving a numeric parameter (1,2,4,8) to the StarMines program to
  99. see the effect of resolution parameter (for example "sm 4").
  100.  
  101. Each sprite should be though of as an object with its own
  102. identity and properties like the current location, the shape
  103. data and the identifier. If you need many sprites with the same
  104. shape, you should use the spr_copy to make copies, NOT to try to
  105. display the same sprite many times at different locations.
  106.  
  107. When the sprite is no longer needed it should be destroyed with
  108. the spr_delete function, which releases all the resources used
  109. by the sprite.
  110.  
  111.  
  112. How much memory do we need
  113. --------------------------
  114.  
  115. A sprite which is W bytes wide and H scanlines tall and uses
  116. sprite resolution S takes 2*S*((W+1)*H) + 2*(W+1)*H bytes of
  117. memory from far heap and only about 40 bytes from the near heap.
  118. This means that the small memory model is big enough in most
  119. applications. 
  120.  
  121. Example: the sprite is 32 pixels (4 bytes) wide, 24 pixels tall
  122. and we want the best resolution (8). The sprite will need
  123. 2*8*((4+1)*24) + 2*(4+1)*24 = 2160 bytes memory. 
  124.  
  125. The memory consumption is one of the reasons why my sprites are
  126. monochrome, they would need 4 times as much memory (in the
  127. example over 8 kbytes for one sprite!) if they had 16 colors.
  128. Also the output would be four times slower making it impossible
  129. to use one pixel resolution in movements with anything slower
  130. than 16 MHz.
  131.  
  132. If sharing is used then the N copies will take 2*S*((W+1)*H) +
  133. 2*(W+1)*H*N bytes of memory from the far heap plus those 40
  134. bytes of near heap for each copy.
  135.  
  136.  
  137. Manipulating sprites
  138. --------------------
  139.  
  140. A sprite can be put into the screen with the function spr_put.
  141. A sprite which has been put into the screen can be hidden by the
  142. function spr_hide.  Displaying and hiding sprites do not take
  143. place immediately, but only after the next call to the function
  144. spr_next_pass. This function should be called in the main loop
  145. of the program after all sprites have been spr_put into their
  146. current positions.
  147.  
  148. What the spr_next_pass really does? It draws all the sprites
  149. which have been spr_put after the previous spr_next_pass into
  150. the hidden display page (and saves the background below them).
  151. Then that display page is activated and the sprites which are in
  152. the now-hidden page are deleted by restoring the previously
  153. saved background data. Therefore you must spr_put the sprites
  154. during every pass of the main loop of the program.
  155.  
  156. The method described above makes it possible to achieve
  157. reasonably fast flicker-free animation. There is a problem with
  158. this approach: EGA graphics cards are slow changing video pages,
  159. and therefore we must waste about 10 milliseconds waiting after
  160. the screen flip. Hercules cards do not need this wait-state,
  161. therefore Hercules mode is preferred in slower machines. Note
  162. that this wait-state affects the frame speed, and it should be
  163. regulated with the spr_regulate_speed function.
  164.  
  165. The collision detection should be done after all the sprites
  166. have been spr_put but before the spr_next_pass. It is possible
  167. to either check the collision between a sprite and a coordinate
  168. position, the collision between two sprites (spr_hit) or find
  169. all the sprites a given sprite collides (spr_hit_first and
  170. spr_hit_next). All collisions are first checked by the bounding
  171. box and after that by using the mask map of the sprite.
  172.  
  173. You can retrieve information about a given sprite by the
  174. functions spr_get_id, spr_get_x, spr_get_y, spr_get_width and
  175. spr_get_height.
  176.  
  177.  
  178.  
  179.  
  180. Using the higher level sprite functions
  181. =======================================
  182.  
  183.  
  184. Creating and destroying animated sprites
  185. ----------------------------------------
  186.  
  187. The animated sprites are represented by ANIM_SPRITE handles. The
  188. exact definition of the object pointed by a handle is private to
  189. the STK implementation, therefore the sprites can be manipulated
  190. only with the provided functions.
  191.  
  192. The ANIM_SPRITEs are created by the function spr_anim_create.
  193. This function takes simple sprites as parameters. These should
  194. have been generated earlier, for example by the function
  195. spr_create. Note that you must have different instances of
  196. simple sprites for each animated sprite you create. 
  197.  
  198. An animated sprite is deleted by the function spr_anim_delete.
  199. This function will not delete the simple sprites it contains. If
  200. also the simple sprites need to be deleted the function
  201. spr_anim_destroy must be used.
  202.  
  203.  
  204. Manipulating animated sprites
  205. -----------------------------
  206.  
  207. After the animated sprites have been created their locations,
  208. direction vectors, area limits and animation speeds should be
  209. set. After that they must be started to get them active.
  210.  
  211. A program that uses animated sprites must call the function
  212. spr_anim_next_pass instead of the spr_next_pass function. This
  213. function will spr_put all the animated sprites, handle the
  214. special effects (see below), call the spr_next_pass and then
  215. update the positions and advance the animation of the animated
  216. sprites for the next pass.
  217.  
  218. The special effects (fx) can be used to change the behavior of
  219. the animated sprites in certain special situations, for example
  220. in collisions with limits or other sprites. The fx_handler
  221. function can be set for each animated sprite and this handler is
  222. called whenever such special situation occurs. This handler can
  223. then adjust the sprite properties etc, and then return a code
  224. which defines further actions, for example re-put (location
  225. changed) or destroy the sprite (somebody shot us!).
  226.  
  227. The default fx_handler will delete the animated sprite in
  228. collisions and timeouts, and bounce it off the limits. See the
  229. StarMines source for further examples of fx_handlers.
  230.  
  231. You can retrieve information about a given animated sprite by
  232. the function spr_anim_get_info which returns a pointer into a
  233. static structure describing the animated sprite. These values
  234. may be changed, but it does not affect the animated sprite.
  235.  
  236.  
  237.  
  238.  
  239. Compiling and linking with the STK
  240. ==================================
  241.  
  242. You need only the files STK.H (include file for function
  243. prototypes and type definitions) and STKS.LIB (small model
  244. library). The include file should be included into every module
  245. which uses the STK functions and the library must be included
  246. into the linking.  The examples below assume that these files
  247. are in the current working directory and the Turbo C is
  248. configured to use small memory model (default).
  249.  
  250. You should have received the SPRTEST.C example source code with
  251. the STK distribution archieve. (Also the file SPRTEST.SMP is
  252. needed for the sprite data.)  To compile and link the example,
  253. use the following command line:
  254.  
  255.         tcc sprtest.c stks.lib graphics.lib
  256.         
  257. Now you should have a working example program SPRTEST.EXE which
  258. will bounce two alien lifeforms around the screen. If they
  259. collide, the first one will be destroyed. After 5000 steps both
  260. the aliens are destroyed. Press Esc to exit the program.
  261.  
  262. If you prefer the integrated environment, you should include the
  263. file STKS.LIB in the project file. You might like to use the
  264. supplied file SPRTEST.PRJ to compile and link the test program
  265. in the integrated environment. If you get "multiply defined
  266. symbol" errors from the linker, you have probably the graphics
  267. library option enabled in the options/linker menu. Either
  268. disable that option or edit the project file.
  269.  
  270.  
  271.  
  272.  
  273. The STK Function Reference
  274. ==========================
  275.  
  276.  
  277. The basic sprite functions and variables (SPR)
  278. ----------------------------------------------
  279.  
  280. /**********************************************************************
  281. * The delay after setvisualpage() before removing old objects in
  282. * the funtion spr_next_pass(). 
  283. * Many EGA/VGA cards need some milliseconds to switch pages, 
  284. * and therefore the sprites flash if this delay is too short.
  285. *
  286. * If someone has better solutions in dealing with this problem,
  287. * I sure would like to know about them.
  288. *
  289. * Time is given in milliseconds and the default is 10 ms for EGA
  290. * and 0 ms for Hercules (use spr_regulate_speed to balance the frame
  291. * rate with different display adapters).
  292. **********************************************************************/
  293. extern int spr_pass_delay;
  294.  
  295. /**********************************************************************
  296. * The maximum coordinate values for current graphics adapter.
  297. * (Variables defined in module grmisc.c, and initialized in gr_start)
  298. * (It is faster to use variables instead of getmaxx() and getmaxy());
  299. **********************************************************************/
  300. #define spr_max_x gr_max_x
  301. #define spr_max_y gr_max_y
  302.  
  303. /**********************************************************************
  304. * The sprite type is private. 
  305. **********************************************************************/
  306. typedef void *SPRITE;
  307.  
  308. /**********************************************************************
  309. * Initialize the sprite system to the given display hardware.
  310. * Supported graphicsdrivers: EGAMONO and HERCMONO
  311. * NOTE: This function must be called before any other sprite funtions
  312. *       and the graphics mode must have been set before this call.
  313. * graphicsdriver  The BGI identifier for the graphics driver used.
  314. **********************************************************************/
  315. void spr_initialize(int graphicsdriver);
  316.  
  317. /**********************************************************************
  318. * Create a sprite from the given bitmaps.
  319. *
  320. * w,h   Width (must be < 512) and height (<256) of sprite in pixels
  321. * pic   The picture bitmap for the sprite
  322. * mask  The mask bitmap for the sprite
  323. * res   The number of steps wanted per 8 bit interval in horizontal
  324. *       direction (1,2,4,8). For example, the value 8 gives one
  325. *       pixel resolution in X-direction.
  326. * ID    The user supplied ID for the sprite (not obligatory)
  327. *
  328. * Return: the newly created sprite or NULL if parameter error,
  329. *           sprite too big or out-of-memory
  330. **********************************************************************/
  331. SPRITE spr_create(WORD w, WORD h, 
  332.                   BITMAP pic, BITMAP mask, 
  333.                   BYTE res, WORD ID);
  334.  
  335. /**********************************************************************
  336. * Create a shared version of the given sprite. This allows
  337. * n spr_copies which all share the shape data thus saving
  338. * quite much memory.
  339. *
  340. * spr   The sprite to share
  341. * n     The maximum number of shared copies
  342. *
  343. * Return: New SPRITE or NULL if error (out of memory, spr==NULL, etc)
  344. **********************************************************************/
  345. SPRITE spr_share(SPRITE spr, BYTE n);
  346.  
  347. /**********************************************************************
  348. * Create a copy of the given sprite. If the sprite was shared
  349. * then a shared copy is created (if possible).
  350. *
  351. * spr   The sprite to share
  352. * id    The ID for the new sprite
  353. *
  354. * Return: New SPRITE of NULL if error (out of memory, spr was NULL, 
  355. * no more shared copies)
  356. **********************************************************************/
  357. SPRITE spr_copy(SPRITE spr, WORD id);
  358.  
  359. /**********************************************************************
  360. * Put the sprite into the given position into the display.
  361. * NOTE: the call has no effect on screen until a call to 
  362. *       spr_next_pass() is made.
  363. * NOTE: Cannot be called twice for the same sprite before spr_hide or
  364. *       spr_next_pass().
  365. *
  366. * spr   The sprite to put
  367. * x     The X coordinate
  368. * y     The Y coordinate
  369. **********************************************************************/
  370. void spr_put(SPRITE spr, WORD x, WORD y);
  371.  
  372. /**********************************************************************
  373. * Remove the sprite from the display.
  374. * NOTE: the call has no effect on screen until a call to 
  375. *       spr_next_pass() is made.
  376. *
  377. * spr   The sprite to hide
  378. **********************************************************************/
  379. void spr_hide(SPRITE spr);
  380.  
  381. /**********************************************************************
  382. * Delete the given sprite and release associated memory buffers.
  383. *
  384. * spr   The sprite to delete
  385. **********************************************************************/
  386. void spr_delete(SPRITE spr);
  387.  
  388. /**********************************************************************
  389. * Draw all sprites into hidden screen page,
  390. * activate hidden screen page,
  391. * delete old sprites from the new hidden page.
  392. *
  393. * Return: The current visual page
  394. **********************************************************************/
  395. WORD spr_next_pass(void);
  396.  
  397. /**********************************************************************
  398. * This function tries to regulate the frame speed by delaying if
  399. * we are doing more frames per second than we should. The target 
  400. * speed is 1 frame per one clock tick (about 18 frames per second).
  401. * This is reasonable target speed at least for 286 machines.
  402. * This function should be called after each spr_next_pass() call.
  403. **********************************************************************/
  404. void spr_regulate_speed(void);
  405.  
  406.  
  407.  
  408. Information retrieving functions:
  409.  
  410.  
  411. /**********************************************************************
  412. * Return the user supplied identifier of the sprite
  413. **********************************************************************/
  414. WORD spr_get_id(SPRITE spr);
  415.  
  416. /**********************************************************************
  417. * Return the X coordinate of the sprite in pixels from top-left
  418. **********************************************************************/
  419. WORD spr_get_x(SPRITE spr);
  420.  
  421. /**********************************************************************
  422. * Return the Y coordinate of the sprite in pixels from top-left
  423. **********************************************************************/
  424. WORD spr_get_y(SPRITE spr);
  425.  
  426. /**********************************************************************
  427. * Return the width of the sprite in pixels
  428. **********************************************************************/
  429. WORD spr_get_width(SPRITE spr);
  430.  
  431. /**********************************************************************
  432. * Return the height of the sprite in pixels
  433. **********************************************************************/
  434. WORD spr_get_height(SPRITE spr);
  435.  
  436.  
  437.  
  438. The sprite file IO functions (SPR_FIO)
  439. --------------------------------------
  440.  
  441. There is not many sprite file IO functions currently, but there
  442. are many possibilities for future expansion. For example, some
  443. kind of binary library of ready made SPRITE objects. Let me
  444. know, if you do something...
  445.  
  446.  
  447. /**********************************************************************
  448. * Create a sprite from the given SMP file.
  449. *
  450. * smpfile   The sprite bitmap file name.
  451. * res       The number of steps wanted per 8 bit interval in horizontal
  452. *           direction (1,2,4,8). For example, the value 8 gives one
  453. *           pixel resolution in X-direction.
  454. * ID        The user supplied ID for the sprite (not obligatory)
  455. *
  456. * Return: the newly created sprite or NULL if file not found, read
  457. *         error or out-of-memory
  458. **********************************************************************/
  459. SPRITE spr_fio_read_smp(char *smpfile, BYTE res, WORD ID);
  460.  
  461.  
  462.  
  463. The collision detection functions (SPR_HIT)
  464. -------------------------------------------
  465.  
  466. Collisions may be checked only for the sprites which have been 
  467. spr_put() since the last call to spr_next_pass().
  468. First bouding boxes are checked, and after that the possible
  469. collisions are checked by comparing the mask bitmaps.
  470.  
  471.  
  472. /**********************************************************************
  473. * Check whether the given point is inside the given sprite.
  474. * Return: 0 if no collision, negative otherwise.
  475. **********************************************************************/
  476. int spr_hit_with_point(SPRITE spr, WORD x, WORD y);
  477.  
  478. /**********************************************************************
  479. * Check whether the given sprites collide against each other.
  480. * Return: 0 if no collision, negative otherwise.
  481. **********************************************************************/
  482. int spr_hit(SPRITE spr1, SPRITE spr2);
  483.  
  484. /**********************************************************************
  485. * Find the first sprite colliding the given sprite. Use spr_hit_next 
  486. * to get the next sprites.
  487. * Return: The colliding sprite or NULL if no collision
  488. **********************************************************************/
  489. SPRITE spr_hit_first(SPRITE spr);
  490.  
  491. /**********************************************************************
  492. * Find the next sprite colliding with the given sprite. 
  493. * Return: The colliding sprite or NULL if no collision
  494. **********************************************************************/
  495. SPRITE spr_hit_next(SPRITE spr);
  496.  
  497.  
  498.  
  499. The animated sprite handling defines, variables and functions (SPR_ANIM)
  500. -------------------------------------------------------------------------
  501.  
  502.  
  503. /**********************************************************************
  504. * The animated sprite is a private datatype
  505. **********************************************************************/
  506. typedef void *ANIM_SPRITE;
  507.  
  508. /**********************************************************************
  509. * The information structure returned by the spr_anim_get_info()
  510. **********************************************************************/
  511. typedef struct _anim_spr_info {
  512.     int     x,y;                            /** location        **/
  513.     int     dx,dy;                          /** movement vector **/
  514.     int     lef, top, rig, bot;             /** limits          **/
  515.     WORD    frame, frame_delay, timeout;    /** time info       **/
  516.     WORD    id;     /** the user spesified id of current sprite **/
  517.     int     w,h;                            /** width&height    **/
  518. } ANIM_SPR_INFO;
  519.  
  520.  
  521. /**********************************************************************
  522. * The values for fx_mode and fx_type. (See spr_anim_set_fx_handler)
  523. **********************************************************************/
  524. #define SPR_ANIM_FX_ALL       (0xFFFF) /** all fx       **/
  525. #define SPR_ANIM_FX_TIMEOUT     (1<<0) /** timeout      **/
  526. #define SPR_ANIM_FX_HIT_X_LIMIT (1<<1) /** hit x limit  **/
  527. #define SPR_ANIM_FX_HIT_Y_LIMIT (1<<2) /** hit y limit  **/
  528. #define SPR_ANIM_FX_HIT_SPRITE  (1<<3) /** hit other spr**/
  529.  
  530. /**********************************************************************
  531. * The FX_RET values for the fx_handler return
  532. **********************************************************************/
  533. #define SPR_ANIM_FX_RET_NOTHING (0)     /** continue normally       **/
  534. #define SPR_ANIM_FX_RET_RE_PUT  (1)     /** put the sprite again    **/
  535. #define SPR_ANIM_FX_RET_STOP    (2)     /** stop the animation      **/
  536. #define SPR_ANIM_FX_RET_DELETE  (3)     /** delete the anim.sprite  **/
  537. #define SPR_ANIM_FX_RET_DESTROY (4)     /** destroy the anim.sprite **/
  538.  
  539.  
  540.  
  541. /**********************************************************************
  542. * Create an animated sprite from the given simple sprites.
  543. * The sprites must have the same width and height attributes.
  544. * Set the following defaults:
  545. *   x,y = 0,0
  546. *   dx,dy = 0,0
  547. *   lef,top,rig,bot = 0,0,spr_max_x,spr_max_y
  548. *   frame_delay, timeout = 0,0
  549. *   fx_mode = FX_ALL 
  550. *   fx_handler = default_fx (TIMEOUT & HIT_SPRITE delete, LIMITs bounce.)
  551. *
  552. * count The number of simple sprites
  553. * ...   The simple sprites
  554. *
  555. * Return: ANIM_SPRITE if no errors or 
  556. *          NULL if memory allocation error, count>ANIM_SPRITE_MAX 
  557. *           or ... contains a NULL sprite.
  558. **********************************************************************/
  559. ANIM_SPRITE spr_anim_create(WORD count, ...);
  560.  
  561. /**********************************************************************
  562. * Start the sprite animation. 
  563. *
  564. * aspr  The animated sprite to use
  565. **********************************************************************/
  566. void spr_anim_start(ANIM_SPRITE aspr);
  567.  
  568. /**********************************************************************
  569. * Stop the animation of the given sprite. This means that after the 
  570. * next pass this sprite will not be shown nor updated.
  571. *
  572. * aspr  The animated sprite to stop
  573. **********************************************************************/
  574. void spr_anim_stop(ANIM_SPRITE aspr);
  575.  
  576. /**********************************************************************
  577. * Delete the given animated sprite. The simple sprites it contains are 
  578. * NOT deleted.
  579. *
  580. * aspr  The animated sprite to use
  581. **********************************************************************/
  582. void spr_anim_delete(ANIM_SPRITE aspr);
  583.  
  584. /**********************************************************************
  585. * Delete the given animated sprite. The simple sprites it contains are 
  586. * ALSO deleted.
  587. *
  588. * aspr  The animated sprite to destroy
  589. **********************************************************************/
  590. void spr_anim_destroy(ANIM_SPRITE aspr);
  591.  
  592. /**********************************************************************
  593. * spr_put all animated sprites then check for special effects (call
  594. * fx_handler(s) if necessary, and act according to the return values). 
  595. * Call spr_next_pass and after that update frame indices and locations 
  596. * of all animated sprites.
  597. *
  598. * Return: The current visual page
  599. **********************************************************************/
  600. WORD spr_anim_next_pass(void);
  601.  
  602.  
  603.  
  604. /**********************************************************************
  605. * Return a pointer into a static info structure of the sprite.
  606. * Note: the structure is only a copy which is overwritten by the 
  607. *       next call to this function.
  608. **********************************************************************/
  609. ANIM_SPR_INFO *spr_anim_get_info(ANIM_SPRITE aspr);
  610.  
  611. /**********************************************************************
  612. * Set the location of the animated sprite.
  613. **********************************************************************/
  614. void spr_anim_set_location(ANIM_SPRITE aspr, WORD x, WORD y);
  615.  
  616. /**********************************************************************
  617. * Set the movement vector of the animated sprite.
  618. **********************************************************************/
  619. void spr_anim_set_vector(ANIM_SPRITE aspr, int dx, int dy);
  620.  
  621. /**********************************************************************
  622. * Set the limits for the animated sprite. The function takes care
  623. * of the bottom/right adjustments due to the size of the sprite.
  624. *
  625. * Note again, that all simple sprites belonging to the animated sprite
  626. * must have the same width & heigth.
  627. **********************************************************************/
  628. void spr_anim_set_limits(ANIM_SPRITE aspr,
  629.                          WORD lef, WORD top, WORD rig, WORD bot);
  630.  
  631.  
  632. /**********************************************************************
  633. * Set the frame delay and timeout values. (-1 means no change for
  634. * that value). 
  635. *
  636. * NOTE: The 'frame' MUST NOT be changed from an fx_handler!!
  637. *
  638. * frame         The current animation frame number (0..nr of frames-1)
  639. * frame_delay   The number of passes for each frame change (0=no change)
  640. * timeout       The number of passes before timeout action (0=infinite)
  641. **********************************************************************/
  642. void spr_anim_set_time(ANIM_SPRITE aspr,
  643.                        int frame, int frame_delay, int timeout);
  644.  
  645. /**********************************************************************
  646. * Sets the special effects handler function.
  647. * The function should have the following prototype:
  648. *
  649. *   WORD func(ANIM_SPRITE aspr, WORD fx_type, SPRITE spr);
  650. *
  651. * The aspr is the animated sprite, fx_type is the type of the
  652. * effect which caused this call and spr is the colliding sprite
  653. * (if fx_type was HIT_SPRITE). 
  654. *
  655. * The function should return one of the FX_RET values defined above.
  656. *
  657. * A NULL handler means that all special effects cause spr_anim_delete.
  658. *
  659. * fx_mask     The types of effects relayed to the handler.
  660. * fx_handler  The handler function.
  661. **********************************************************************/
  662. void spr_anim_set_fx_handler(ANIM_SPRITE aspr, 
  663.                              WORD fx_mask, 
  664.                              WORD (fx_handler)(ANIM_SPRITE,WORD,SPRITE));
  665.  
  666.  
  667.  
  668. The text IO and keyboard variables and functions (GR)
  669. -----------------------------------------------------
  670.  
  671. Modes for the gr_detect:
  672.  
  673. #define GR_TYPE_ANY 0   /* Any mode will do */
  674. #define GR_TYPE_SPR 1   /* The best possible mode for the sprite toolkit */
  675.  
  676. /**********************************************************************
  677. * Detect the graphics card and mode of the system.
  678. * The type parameter can be used to specify special requests (see above).
  679. * graphdriver and graphmode parameters are returned. They contain -1
  680. * if some error occured (cannot find requested mode, etc)
  681. **********************************************************************/
  682. void gr_detect(int type, int *graphdriver, int *graphmode);
  683.  
  684. /***************************************************************************
  685. * Initializes the graphics system. Search BGI drivers from the path defined
  686. * in the enviroment variable BGIDIR or current directory. Set videomode
  687. * into the BIOS are to fool mouse drivers with Hercules graphics.
  688. * Set gr_end at exit and ctrl-C signals.
  689. * Terminate with error message if initialization fails.
  690. *
  691. * graphdriver   pointer to the driver ID (or DETECT)
  692. * graphmode     pointer to the mode ID
  693. ***************************************************************************/
  694. void gr_start(int *graphdriver, int *graphmode);
  695.  
  696. /***************************************************************************
  697. * Returns to the text mode
  698. ***************************************************************************/
  699. void gr_end(void);
  700.  
  701.  
  702. /**********************************************************************
  703. * gr_putch, gr_puts, gr_printf work as the as in text modes.
  704. * '\n', '\r' are handled as in standard text modes. 
  705. * Scrolling or backspacing not implemented.
  706. **********************************************************************/
  707. void gr_putch(char ch);
  708. void gr_puts(char *s);
  709. void gr_printf(char *s,...);
  710. #define gr_gotoxy(x, y) moveto(x*8, y*8)
  711.  
  712. /**********************************************************************
  713. * Print text at the given position. (x and y in pixels) 
  714. **********************************************************************/
  715. void gr_xy_printf(int x, int y, char *s,...);
  716.  
  717. /**********************************************************************
  718. * Print text into both graphics pages at the given position.
  719. * (x and y in pixels) Page 0 is left active.
  720. **********************************************************************/
  721. void gr_dual_xy_printf(int x, int y, char *s,...);
  722.  
  723. /**********************************************************************
  724. * Return a keypress if one pending, otherwise 0.
  725. * Extended codes contain 0 in the low byte.
  726. *
  727. * Automatic key repeat disabled by setting kbd buffer head and tail
  728. * equal. 
  729. **********************************************************************/
  730. int gr_inkey(void);
  731.  
  732. /**********************************************************************
  733. * Read a string from screen in graphics mode. (Max len 80)
  734. * Backspace deletes characters, Esc returns a null pointer.
  735. **********************************************************************/
  736. char *gr_gets(char *cpdest, int max_len);
  737.  
  738. /**********************************************************************
  739. * This variable defines the text writing mode (default GR_MODE_CLEAR)
  740. **********************************************************************/
  741. extern int gr_text_mode;
  742.  
  743. /**********************************************************************
  744. * The maximum coordinate values for current graphics adapter.
  745. * (It is faster to use variables instead of getmaxx() and getmaxy());
  746. **********************************************************************/
  747. extern int gr_max_x;
  748. extern int gr_max_y;
  749.  
  750. #define GR_MODE_OR      (1<<0)      /* OR the text over previous graphics */
  751. #define GR_MODE_CLEAR   (1<<1)      /* Clear the backgroud bvefore print  */
  752.  
  753.  
  754. /**********************************************************************
  755. * Array of booleans for each key of the keyboard (indexed by the scan
  756. * code value). Non-zero if key pressed, zero otherwise.
  757. * The array is updated during the kbd_grab, see the function 
  758. * gr_start_kbd_grab below.
  759. **********************************************************************/
  760. extern char gr_keys[128];
  761.  
  762. /**********************************************************************
  763. * Set a new handler for the keyboard. This handler sets and resets
  764. * the gr_keys array values for each scancode received, then calls
  765. * the old handler and after all that flushes the keyboard buffer.
  766. **********************************************************************/
  767. void gr_start_kbd_grab(void);
  768.  
  769. /**********************************************************************
  770. * End the kbd grab, ie restore the original keyboard handler
  771. **********************************************************************/
  772. void gr_end_kbd_grab(void);
  773.  
  774. /**********************************************************************
  775. * Defines for the scan codes of some keys. See others from
  776. * some book, for example Peter Norton's Programmers guide or
  777. * write a small program to try them...
  778. **********************************************************************/
  779.  
  780. #define GR_KEY_ESC  1
  781. #define GR_KEY_1    2
  782. #define GR_KEY_2    3
  783. #define GR_KEY_3    4
  784. #define GR_KEY_4    5
  785. #define GR_KEY_5    6
  786. #define GR_KEY_6    7
  787. #define GR_KEY_7    8
  788. #define GR_KEY_8    9
  789. #define GR_KEY_9    10
  790. #define GR_KEY_0    11
  791.  
  792. #define GR_KEY_TAB  15
  793. #define GR_KEY_Q    16
  794. #define GR_KEY_W    17
  795. #define GR_KEY_E    18
  796. #define GR_KEY_R    19 
  797. #define GR_KEY_T    20
  798. #define GR_KEY_Y    21
  799. #define GR_KEY_U    22
  800. #define GR_KEY_I    23
  801. #define GR_KEY_O    24
  802. #define GR_KEY_P    25
  803.  
  804. #define GR_KEY_A    30
  805. #define GR_KEY_S    31
  806. #define GR_KEY_D    32
  807. #define GR_KEY_F    33
  808. #define GR_KEY_G    34
  809. #define GR_KEY_H    35
  810. #define GR_KEY_J    36
  811. #define GR_KEY_K    37
  812. #define GR_KEY_L    38
  813.  
  814. #define GR_KEY_Z    44
  815. #define GR_KEY_X    45 
  816. #define GR_KEY_C    46
  817. #define GR_KEY_V    47
  818. #define GR_KEY_B    48
  819. #define GR_KEY_N    49
  820. #define GR_KEY_M    50
  821. #define GR_KEY_COMMA    51
  822. #define GR_KEY_DOT      52
  823.  
  824. #define GR_KEY_SPACE    57
  825.  
  826. #define GR_KEY_ARROW_UP     72
  827. #define GR_KEY_ARROW_DOWN   80
  828. #define GR_KEY_ARROW_LEFT   75
  829. #define GR_KEY_ARROW_RIGHT  77
  830.  
  831.  
  832.  
  833. The mouse interface variables and functions (MOUSE)
  834. ---------------------------------------------------
  835.  
  836. /** Codes for button presses **/
  837. #define BUTTON_LEFT         1
  838. #define BUTTON_RIGHT        2
  839. #define BUTTON_MS_MIDDLE    (BUTTON_RIGHT | BUTTON_LEFT)
  840. #define BUTTON_MIDDLE       4
  841.  
  842. /* First mask and then shape bitmap (must be WORDs) */
  843. typedef unsigned int MOUSE_POINTER[2][16];
  844.  
  845. extern MOUSE_POINTER mouse_pointer_arrow;    /* HotSpot 1,1   */
  846. extern MOUSE_POINTER mouse_pointer_hourglass;/* HotSpot 7,7  */
  847. extern MOUSE_POINTER mouse_pointer_cross;    /* HotSpot 7,7   */
  848.  
  849. /** For further information, see the mouse documention **/
  850. int     mouse_driver_init(void);                                /**  0 **/
  851. void    mouse_show_pointer(void);                               /**  1 **/
  852. void    mouse_hide_pointer(void);                               /**  2 **/
  853. void    mouse_get_pointer_xy(int *x, int *y);                   /**  3 **/
  854. void    mouse_get_rel_pointer_xy(int *x, int *y);               /** 11 **/
  855. int     mouse_get_buttons(void);                                /**  3 **/
  856. int     mouse_get_presses(int buttons);                         /**  5 **/
  857. int     mouse_get_releases(int buttons);                        /**  6 **/
  858. void    mouse_set_pointer_xy(int x, int y);                     /**  4 **/
  859. void    mouse_set_sensitivity(int x, int y);                    /** 15 **/
  860. void    mouse_set_pointer_shape(int HotX, int HotY, MOUSE_POINTER shape);
  861. void    mouse_set_pointer_window(int a, int b, int c, int d);    /**  7 **/
  862. void    mouse_disable_pointer_window(int a, int b, int c, int d);/** 16 **/
  863. void    mouse_set_light_pen(int a);                         /** 13 & 14 **/
  864.  
  865. /**********************************************************************
  866. * Initialize the mouse driver, set the pointer shape and pointer window.
  867. * Return: the number of buttons or 0 if no mouse driver detected
  868. **********************************************************************/
  869. int     mouse_initialize(void);
  870.  
  871.  
  872.  
  873. GRTYPES - typedefs for the Sprite Toolkit
  874. -----------------------------------------
  875.  
  876. #ifndef NULL
  877. #define NULL ((void*)0)
  878. #endif
  879.  
  880. typedef unsigned char BYTE;
  881. typedef unsigned int  WORD;
  882. typedef BYTE *BITMAP;
  883.  
  884.  
  885.  
  886. **********************************************************************
  887.  
  888.  
  889.  
  890. If you have any comments, suggestions, extensions, bug reports
  891. (and fixes), let me know. I would also like to hear about the
  892. programs you create with the aid of the Sprite Toolkit. In fact,
  893. the main reason for writing the Sprite Toolkit was to increase
  894. the number of good Public Domain and ShareWare games for PC
  895. compatibles. I hope this toolkit will give you the initial
  896. thrust you needed to implement that game you have been dreaming
  897. about!
  898.  
  899.  
  900. Jari Karjala
  901. Veropellontie 11
  902. 00780 Helsinki
  903. Finland
  904.  
  905. FUNET: jka@niksula.hut.fi
  906.  
  907.