home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / GRAPHICS / MISC / STK100.ZIP / DEMOSRC.COM / SMSPR.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-10-20  |  9.3 KB  |  241 lines

  1. /**********************************************************************
  2. * smspr.c
  3. *
  4. * StarMines - a sprite toolkit demonstration game.
  5. *
  6. * The sprite creation functions.
  7. **********************************************************************
  8.                     This file is part of
  9.  
  10.           STK -- The sprite toolkit -- version 1.0
  11.  
  12.               Copyright (C) Jari Karjala 1990
  13.  
  14. The sprite toolkit (STK) is a FreeWare toolkit for creating high
  15. resolution sprite graphics with PCompatible hardware. This toolkit 
  16. is provided as is without any warranty or such thing. See the file
  17. COPYING for further information.
  18.  
  19. **********************************************************************/
  20.  
  21. #include "stk.h"
  22.  
  23. #include "sm.h"
  24. #include "smspr.h"
  25.  
  26. #include "smp\mine1a.smp"
  27. #include "smp\mine1b.smp"
  28.  
  29. #include "smp\ship1.smp"
  30. #include "smp\ship2.smp"
  31. #include "smp\ship3.smp"
  32. #include "smp\ship4.smp"
  33. #include "smp\ship5.smp"
  34. #include "smp\ship6.smp"
  35. #include "smp\ship7.smp"
  36. #include "smp\ship8.smp"
  37. #include "smp\ship9.smp"
  38. #include "smp\ship10.smp"
  39. #include "smp\ship11.smp"
  40. #include "smp\ship12.smp"
  41. #include "smp\ship13.smp"
  42. #include "smp\ship14.smp"
  43. #include "smp\ship15.smp"
  44. #include "smp\ship16.smp"
  45.  
  46. #include "smp\bullet.smp"
  47.  
  48. #include "smp\expl1.smp"
  49. #include "smp\expl2.smp"
  50. #include "smp\expl3.smp"
  51. #include "smp\expl4.smp"
  52.  
  53. /**********************************************************************
  54. * Create an animated alien into the next free slot in the global 
  55. * 'aliens' array. Set fx_handler and start alien.
  56. * Return NULL if error or no more slots.
  57. **********************************************************************/
  58. ANIM_SPRITE smspr_create_alien(void)
  59. {
  60.     int ind;
  61.     static int created=0;
  62.  
  63.     if (!created) {
  64.         /** Create the simple sprites at the first call **/
  65.         aliens[0].s1 = spr_create(mine1a_width, mine1a_height, 
  66.                                   mine1a_shape, mine1a_mask, 
  67.                                   sprite_resolution, 0);
  68.         aliens[0].s2 = spr_create(mine1b_width, mine1b_height, 
  69.                                   mine1b_shape, mine1b_mask, 
  70.                                   sprite_resolution, 0);
  71.         aliens[0].s1 = spr_share(aliens[0].s1, MAX_ALIEN);
  72.         aliens[0].s2 = spr_share(aliens[0].s2, MAX_ALIEN);
  73.         
  74.         if (aliens[0].s1==NULL)
  75.             return NULL;
  76.         if (aliens[0].s2==NULL)
  77.             return NULL;
  78.         
  79.         for (ind=1; ind<MAX_ALIEN; ind++) {
  80.             if (aliens[ind].s1==NULL)
  81.                 aliens[ind].s1 = spr_copy(aliens[0].s1, ind);
  82.             if (aliens[ind].s2==NULL)
  83.                 aliens[ind].s2 = spr_copy(aliens[0].s2, ind);
  84.         }        
  85.         created = 1;
  86.     }
  87.     
  88.     ind=0;
  89.     while(ind<MAX_ALIEN)
  90.         if (aliens[ind].as==NULL)
  91.             break;
  92.         else
  93.             ind++;
  94.     if (ind==MAX_ALIEN)
  95.         return NULL;
  96.  
  97.     aliens[ind].as = spr_anim_create(2,aliens[ind].s1,aliens[ind].s2);
  98.     if (aliens[ind].as==NULL)
  99.         return NULL;
  100.     
  101.     /** we do not need hit detection for aliens **/
  102.     spr_anim_set_fx_handler(aliens[ind].as, 
  103.                             SPR_ANIM_FX_ALL & ~SPR_ANIM_FX_HIT_SPRITE,
  104.                             alien_fx_handler);
  105.     spr_anim_start(aliens[ind].as);
  106.     aliens[ind].divide = 0;
  107.     
  108.     return aliens[ind].as;
  109. }
  110.  
  111. /**********************************************************************
  112. * Creates an 'animated' sprite for the player. Actually it contains
  113. * only the different rotations for the player. Set fx_handler and 
  114. * start the player.
  115. * Return: NULL if error, the player otherwise.
  116. **********************************************************************/
  117. ANIM_SPRITE smspr_create_player(void)
  118. {
  119.     ANIM_SPRITE as;
  120.     
  121.     
  122.     as = spr_anim_create(16,
  123.                          spr_create(ship1_width, ship1_height, 
  124.                                     ship1_shape, ship1_mask, 
  125.                                     sprite_resolution, PLAYER_ID),
  126.                          spr_create(ship2_width, ship2_height, 
  127.                                     ship2_shape, ship2_mask, 
  128.                                     sprite_resolution, PLAYER_ID),
  129.                          spr_create(ship3_width, ship3_height, 
  130.                                     ship3_shape, ship3_mask, 
  131.                                     sprite_resolution, PLAYER_ID),
  132.                          spr_create(ship4_width, ship4_height, 
  133.                                     ship4_shape, ship4_mask, 
  134.                                     sprite_resolution, PLAYER_ID),
  135.                          spr_create(ship5_width, ship5_height, 
  136.                                     ship5_shape, ship5_mask, 
  137.                                     sprite_resolution, PLAYER_ID),
  138.                          spr_create(ship6_width, ship6_height, 
  139.                                     ship6_shape, ship6_mask, 
  140.                                     sprite_resolution, PLAYER_ID),
  141.                          spr_create(ship7_width, ship7_height, 
  142.                                     ship7_shape, ship7_mask, 
  143.                                     sprite_resolution, PLAYER_ID),
  144.                          spr_create(ship8_width, ship8_height, 
  145.                                     ship8_shape, ship8_mask, 
  146.                                     sprite_resolution, PLAYER_ID),
  147.                          spr_create(ship9_width, ship9_height, 
  148.                                     ship9_shape, ship9_mask, 
  149.                                     sprite_resolution, PLAYER_ID),
  150.                          spr_create(ship10_width, ship10_height, 
  151.                                     ship10_shape, ship10_mask, 
  152.                                     sprite_resolution, PLAYER_ID),
  153.                          spr_create(ship11_width, ship11_height, 
  154.                                     ship11_shape, ship11_mask, 
  155.                                     sprite_resolution, PLAYER_ID),
  156.                          spr_create(ship12_width, ship12_height, 
  157.                                     ship12_shape, ship12_mask, 
  158.                                     sprite_resolution, PLAYER_ID),
  159.                          spr_create(ship13_width, ship13_height, 
  160.                                     ship13_shape, ship13_mask, 
  161.                                     sprite_resolution, PLAYER_ID),
  162.                          spr_create(ship14_width, ship14_height, 
  163.                                     ship14_shape, ship14_mask, 
  164.                                     sprite_resolution, PLAYER_ID),
  165.                          spr_create(ship15_width, ship15_height, 
  166.                                     ship15_shape, ship15_mask, 
  167.                                     sprite_resolution, PLAYER_ID),
  168.                          spr_create(ship16_width, ship16_height, 
  169.                                     ship16_shape, ship16_mask, 
  170.                                     sprite_resolution, PLAYER_ID));
  171.    if (as==NULL)
  172.        return NULL;
  173.    
  174.    spr_anim_set_fx_handler(as, SPR_ANIM_FX_ALL, player_fx_handler);
  175.    spr_anim_start(as);
  176.    return as; 
  177. }
  178.  
  179. /**********************************************************************
  180. * Create a bullet. Set fx_handler and start the bullet.
  181. * Return: NULL if error, the bullet otherwise.
  182. **********************************************************************/
  183. ANIM_SPRITE smspr_create_bullet(void)
  184. {
  185.     static SPRITE ss = NULL;
  186.     ANIM_SPRITE as;
  187.         
  188.     if (ss==NULL) {
  189.         ss = spr_create(bullet_width, bullet_height, 
  190.                             bullet_shape, bullet_mask, 
  191.                             sprite_resolution, BULLET_ID);
  192.         ss = spr_share(ss, 50); /** max 50 bullets **/
  193.     }
  194.     as = spr_anim_create(1, spr_copy(ss, BULLET_ID));
  195.                              
  196.     if (as==NULL)
  197.         return NULL;
  198.    
  199.     spr_anim_set_fx_handler(as, SPR_ANIM_FX_ALL, bullet_fx_handler);
  200.     spr_anim_start(as);
  201.     return as;     
  202. }
  203.  
  204.  
  205. /**********************************************************************
  206. * Create an explosion. Set fx_handler and start the sprite.
  207. * Return: NULL if error, the ANIM_SPRITE otherwise.
  208. **********************************************************************/
  209. ANIM_SPRITE smspr_create_explosion(void)
  210. {
  211.     static SPRITE ss1 = NULL, ss2 = NULL, ss3 = NULL, ss4 = NULL;
  212.     ANIM_SPRITE as;
  213.     
  214.     if (ss1==NULL) {
  215.         ss1 = spr_create(expl1_width, expl1_height, expl1_shape, expl1_mask, 
  216.                          4, EXPLO_ID);
  217.         ss2 = spr_create(expl2_width, expl2_height, expl2_shape, expl2_mask, 
  218.                          4, EXPLO_ID);
  219.         ss3 = spr_create(expl3_width, expl3_height, expl3_shape, expl3_mask, 
  220.                          4, EXPLO_ID);
  221.         ss4 = spr_create(expl4_width, expl4_height, expl4_shape, expl4_mask, 
  222.                          4, EXPLO_ID);
  223.         ss1 = spr_share(ss1, 20);
  224.         ss2 = spr_share(ss2, 20);
  225.         ss3 = spr_share(ss3, 20);
  226.         ss4 = spr_share(ss4, 20);
  227.     }
  228.  
  229.     as = spr_anim_create(4, 
  230.                          spr_copy(ss1,EXPLO_ID), spr_copy(ss2,EXPLO_ID), 
  231.                          spr_copy(ss3,EXPLO_ID), spr_copy(ss4,EXPLO_ID));
  232.     if (as==NULL)
  233.         return NULL;
  234.    
  235.     spr_anim_set_fx_handler(as, 
  236.                             SPR_ANIM_FX_ALL & ~SPR_ANIM_FX_HIT_SPRITE,
  237.                             explo_fx_handler);
  238.     spr_anim_start(as);
  239.     return as;     
  240. }
  241.