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.0
-
- Copyright (C) Jari Karjala 1990
-
- 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\mine1a.smp"
- #include "smp\mine1b.smp"
-
- #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"
-
- /**********************************************************************
- * 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;
- static int created=0;
-
- if (!created) {
- /** Create the simple sprites at the first call **/
- aliens[0].s1 = spr_create(mine1a_width, mine1a_height,
- mine1a_shape, mine1a_mask,
- sprite_resolution, 0);
- aliens[0].s2 = spr_create(mine1b_width, mine1b_height,
- mine1b_shape, mine1b_mask,
- 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 NULL;
- if (aliens[0].s2==NULL)
- return NULL;
-
- for (ind=1; ind<MAX_ALIEN; ind++) {
- if (aliens[ind].s1==NULL)
- aliens[ind].s1 = spr_copy(aliens[0].s1, ind);
- if (aliens[ind].s2==NULL)
- aliens[ind].s2 = spr_copy(aliens[0].s2, ind);
- }
- created = 1;
- }
-
- ind=0;
- while(ind<MAX_ALIEN)
- if (aliens[ind].as==NULL)
- break;
- else
- ind++;
- if (ind==MAX_ALIEN)
- return 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].divide = 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;
-
- 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);
- }
-
- as = spr_anim_create(4,
- spr_copy(ss1,EXPLO_ID), spr_copy(ss2,EXPLO_ID),
- spr_copy(ss3,EXPLO_ID), spr_copy(ss4,EXPLO_ID));
- if (as==NULL)
- return NULL;
-
- spr_anim_set_fx_handler(as,
- SPR_ANIM_FX_ALL & ~SPR_ANIM_FX_HIT_SPRITE,
- explo_fx_handler);
- spr_anim_start(as);
- return as;
- }
-