home *** CD-ROM | disk | FTP | other *** search
- /**********************************************************************
- * smspr.c
- *
- * StarMines - a sprite toolkit demonstration game.
- *
- * The sprite creation functions.
- **********************************************************************
- This file is part of
-
- STK -- The sprite toolkit -- version 1.1
-
- Copyright (C) Jari Karjala 1991
-
- The sprite toolkit (STK) is a FreeWare toolkit for creating high
- resolution sprite graphics with PCompatible hardware. This toolkit
- is provided as is without any warranty or such thing. See the file
- COPYING for further information.
-
- **********************************************************************/
-
- #include "stk.h"
-
- #include "sm.h"
- #include "smspr.h"
-
- #include "smp\ship1.smp"
- #include "smp\ship2.smp"
- #include "smp\ship3.smp"
- #include "smp\ship4.smp"
- #include "smp\ship5.smp"
- #include "smp\ship6.smp"
- #include "smp\ship7.smp"
- #include "smp\ship8.smp"
- #include "smp\ship9.smp"
- #include "smp\ship10.smp"
- #include "smp\ship11.smp"
- #include "smp\ship12.smp"
- #include "smp\ship13.smp"
- #include "smp\ship14.smp"
- #include "smp\ship15.smp"
- #include "smp\ship16.smp"
-
- #include "smp\bullet.smp"
-
- #include "smp\expl1.smp"
- #include "smp\expl2.smp"
- #include "smp\expl3.smp"
- #include "smp\expl4.smp"
-
- #include "smp\mine1a.smp"
- #include "smp\mine1b.smp"
- #include "smp\mine2a.smp"
- #include "smp\mine2b.smp"
- #include "smp\mine3a.smp"
- #include "smp\mine3b.smp"
- #include "smp\mine4a.smp"
- #include "smp\mine4b.smp"
-
- typedef struct mine_bitmap {
- BITMAP mine1, mask1, mine2, mask2;
- BYTE w,h;
- } MINE_BITMAP;
-
- #define MAX_MINES 4
- MINE_BITMAP mines[MAX_MINES] = {
- { mine1a_shape, mine1a_mask, mine1b_shape, mine1b_mask,
- mine1a_width, mine1a_height },
-
- { mine2a_shape, mine2a_mask, mine2b_shape, mine2b_mask,
- mine2a_width, mine2a_height },
-
- { mine3a_shape, mine3a_mask, mine3b_shape, mine3b_mask,
- mine3a_width, mine3a_height },
-
- { mine4a_shape, mine4a_mask, mine4b_shape, mine4b_mask,
- mine4a_width, mine4a_height },
- };
-
- /**********************************************************************
- * Create the wave'th aliens
- * Return: 0 if OK, negative if out of memory, etc
- **********************************************************************/
- int smspr_init_aliens(int wave)
- {
- int ind;
-
- /** kill all existing aliens **/
- for (ind=0; ind<MAX_ALIEN; ind++) {
- if (aliens[ind].as!=NULL)
- spr_anim_delete(aliens[ind].as);
- if (aliens[ind].s1!=NULL)
- spr_delete(aliens[ind].s1);
- if (aliens[ind].s2!=NULL)
- spr_delete(aliens[ind].s2);
- aliens[ind].active = 0;
- }
- /** do one pass to really get rid of the sprites **/
- spr_anim_next_pass();
-
- wave %= MAX_MINES;
-
- /** create new ones **/
- aliens[0].s1 = spr_create(mines[wave].w, mines[wave].h,
- mines[wave].mine1, mines[wave].mask1,
- sprite_resolution, 0);
- aliens[0].s2 = spr_create(mines[wave].w, mines[wave].h,
- mines[wave].mine2, mines[wave].mask2,
- sprite_resolution, 0);
- aliens[0].s1 = spr_share(aliens[0].s1, MAX_ALIEN);
- aliens[0].s2 = spr_share(aliens[0].s2, MAX_ALIEN);
-
- if (aliens[0].s1==NULL)
- return -1;
- if (aliens[0].s2==NULL)
- return -1;
-
- aliens[0].as = spr_anim_create(2,aliens[0].s1,aliens[0].s2);
- if (aliens[0].as==NULL)
- return -1;
-
-
- for (ind=1; ind<MAX_ALIEN; ind++) {
- aliens[ind].s1 = spr_copy(aliens[0].s1, ind);
- aliens[ind].s2 = spr_copy(aliens[0].s2, ind);
- aliens[ind].as = spr_anim_create(2,aliens[ind].s1,aliens[ind].s2);
- }
-
- return 0;
- }
-
-
-
- /**********************************************************************
- * Create an animated alien into the next free slot in the global
- * 'aliens' array. Set fx_handler and start alien.
- * Return NULL if error or no more slots.
- **********************************************************************/
- ANIM_SPRITE smspr_create_alien(void)
- {
- int ind;
-
- for(ind=0; ind<MAX_ALIEN && aliens[ind].active; ind++)
- ;
- if (ind==MAX_ALIEN)
- return NULL;
-
- if (aliens[ind].as==NULL)
- aliens[ind].as = spr_anim_create(2,aliens[ind].s1,aliens[ind].s2);
-
- if (aliens[ind].as==NULL)
- return NULL;
-
- /** we do not need hit detection for aliens **/
- spr_anim_set_fx_handler(aliens[ind].as,
- SPR_ANIM_FX_ALL & ~SPR_ANIM_FX_HIT_SPRITE,
- alien_fx_handler);
- spr_anim_start(aliens[ind].as);
- aliens[ind].active = 1;
- aliens[ind].divide = 0;
- aliens[ind].divided = 0;
- aliens[ind].shot = 0;
-
- return aliens[ind].as;
- }
-
- /**********************************************************************
- * Creates an 'animated' sprite for the player. Actually it contains
- * only the different rotations for the player. Set fx_handler and
- * start the player.
- * Return: NULL if error, the player otherwise.
- **********************************************************************/
- ANIM_SPRITE smspr_create_player(void)
- {
- ANIM_SPRITE as;
-
-
- as = spr_anim_create(16,
- spr_create(ship1_width, ship1_height,
- ship1_shape, ship1_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship2_width, ship2_height,
- ship2_shape, ship2_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship3_width, ship3_height,
- ship3_shape, ship3_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship4_width, ship4_height,
- ship4_shape, ship4_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship5_width, ship5_height,
- ship5_shape, ship5_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship6_width, ship6_height,
- ship6_shape, ship6_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship7_width, ship7_height,
- ship7_shape, ship7_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship8_width, ship8_height,
- ship8_shape, ship8_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship9_width, ship9_height,
- ship9_shape, ship9_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship10_width, ship10_height,
- ship10_shape, ship10_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship11_width, ship11_height,
- ship11_shape, ship11_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship12_width, ship12_height,
- ship12_shape, ship12_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship13_width, ship13_height,
- ship13_shape, ship13_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship14_width, ship14_height,
- ship14_shape, ship14_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship15_width, ship15_height,
- ship15_shape, ship15_mask,
- sprite_resolution, PLAYER_ID),
- spr_create(ship16_width, ship16_height,
- ship16_shape, ship16_mask,
- sprite_resolution, PLAYER_ID));
- if (as==NULL)
- return NULL;
-
- spr_anim_set_fx_handler(as, SPR_ANIM_FX_ALL, player_fx_handler);
- spr_anim_start(as);
- return as;
- }
-
- /**********************************************************************
- * Create a bullet. Set fx_handler and start the bullet.
- * Return: NULL if error, the bullet otherwise.
- **********************************************************************/
- ANIM_SPRITE smspr_create_bullet(void)
- {
- static SPRITE ss = NULL;
- ANIM_SPRITE as;
-
- if (ss==NULL) {
- ss = spr_create(bullet_width, bullet_height,
- bullet_shape, bullet_mask,
- sprite_resolution, BULLET_ID);
- ss = spr_share(ss, 50); /** max 50 bullets **/
- }
- as = spr_anim_create(1, spr_copy(ss, BULLET_ID));
-
- if (as==NULL)
- return NULL;
-
- spr_anim_set_fx_handler(as, SPR_ANIM_FX_ALL, bullet_fx_handler);
- spr_anim_start(as);
- return as;
- }
-
-
- /**********************************************************************
- * Create an explosion. Set fx_handler and start the sprite.
- * Return: NULL if error, the ANIM_SPRITE otherwise.
- **********************************************************************/
- ANIM_SPRITE smspr_create_explosion(void)
- {
- static SPRITE ss1 = NULL, ss2 = NULL, ss3 = NULL, ss4 = NULL;
- ANIM_SPRITE as;
- int ind;
-
- if (ss1==NULL) {
- ss1 = spr_create(expl1_width, expl1_height, expl1_shape, expl1_mask,
- 4, EXPLO_ID);
- ss2 = spr_create(expl2_width, expl2_height, expl2_shape, expl2_mask,
- 4, EXPLO_ID);
- ss3 = spr_create(expl3_width, expl3_height, expl3_shape, expl3_mask,
- 4, EXPLO_ID);
- ss4 = spr_create(expl4_width, expl4_height, expl4_shape, expl4_mask,
- 4, EXPLO_ID);
- ss1 = spr_share(ss1, 20);
- ss2 = spr_share(ss2, 20);
- ss3 = spr_share(ss3, 20);
- ss4 = spr_share(ss4, 20);
- for (ind=0; ind<MAX_EXPL; ind++) {
- expls[ind].active = 0;
- expls[ind].as = spr_anim_create(4,
- spr_copy(ss1,EXPLO_ID+ind),
- spr_copy(ss2,EXPLO_ID+ind),
- spr_copy(ss3,EXPLO_ID+ind),
- spr_copy(ss4,EXPLO_ID+ind));
- if (expls[ind].as==NULL)
- break;
- }
- }
-
- for(ind=0; ind<MAX_EXPL && expls[ind].active; ind++)
- ;
- if (ind==MAX_EXPL)
- return NULL;
-
- if (expls[ind].as==NULL)
- return NULL;
-
- spr_anim_set_fx_handler(expls[ind].as,
- SPR_ANIM_FX_ALL & ~SPR_ANIM_FX_HIT_SPRITE,
- explo_fx_handler);
- spr_anim_start(expls[ind].as);
- expls[ind].active = 1;
- return expls[ind].as;
- }
-