//------------------------------------------------------------------------------ // File: missile.c // Author: George Bain // Date: May 24, 1997 // Descriptions: Missile related routines and collision routines // Copyright (C) 1997 George Bain, All Rights Reserved //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // I N C L U D E S //------------------------------------------------------------------------------ #include // standard Sony library #include "missile.h" #include "gfx.h" //------------------------------------------------------------------------------ // G L O B A L S //------------------------------------------------------------------------------ particle_handler missile[NUM_MISSILES]; // the missiles //------------------------------------------------------------------------------ // Function: InitMissiles() // Description: Initialize the missiles // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void InitMissiles( void ) { int count; for( count=0; count= (SCREEN_WIDTH-2)) || (miss_x <=3) || (miss_y >= (SCREEN_HEIGHT-2)) || (miss_y <=3) ) { // missile has hit edge of screen ..kill it missile[count].state = MISSILE_DEAD; // go on with other tests continue; }// end if // test for player missile -> enemy moving left collision PlayerMissileCollideLeft( miss_x, miss_y ); // test for player missile -> enemy moving right collision PlayerMissileCollideRight( miss_x, miss_y ); // test for enemy missile -> player collision EnemyMissileCollide( miss_x, miss_y ); // tests for player missile -> boss_one collision PlayerBossMissile( miss_x, miss_y ); // test for player missile -> rocket collision PlayerRocketCollision( miss_x, miss_y ); }// end if missile ALIVE }// end NUM_MISSILES }// end MoveMissiles //------------------------------------------------------------------------------ // Function: PlayerMissileCollideLeft() // Description: Check if players missiles hit enemies moving to the // left of the screen, if TRUE destroy the enemy and // display explosion animation // Parameters: miss_x: x location of missile // miss_y: y location of missile // Returns: void // Notes: This could be improved //------------------------------------------------------------------------------ void PlayerMissileCollideLeft( int miss_x, int miss_y ) { int count, count_2, // loop vars enemy_hit = 0; // hit indicator object_ptr current; // current enemy // check against all missiles for( count=0; countstate == ENEMY_ALIVE ) { // test for collision if( MissileCollision( (particle_ptr)&missile[count], (object_ptr)&blue_enemy[count_2] ) ) { // kill missile missile[count].state = MISSILE_DEAD; // kill enemy current->state = ENEMY_DEAD; // enemy hit indicator enemy_hit = 1; // start an explosion StartExplosions( current->sprite.x+10, current->sprite.y+10, EXPLOSION_SPEED ); // increase players score game_info.money += 10; }// end if collision }// end if enemy ALIVE if( enemy_hit ) break; }// end for NUM_ENEMIES }// end if Missile is ALIVE and is players }// end for NUM_MISSILES }// end PlayerMissileCollideLeft //------------------------------------------------------------------------------ // Function: PlayerMissileCollideRight() // Description: Check if players missiles hit enemies moving to the // right of the screen, if TRUE destroy the enemy and // display explosion animation // Parameters: miss_x: x location of missile // miss_y: y location of missile // Returns: void // Notes: This could be improved //------------------------------------------------------------------------------ void PlayerMissileCollideRight( int miss_x, int miss_y ) { int count, count_2, // loop vars enemy_hit = 0; // hit indicator object_ptr current; // current enemy // check against all missiles for( count=0; countstate == ENEMY_ALIVE ) { // test for collision if( MissileCollision( (particle_ptr)&missile[count], (object_ptr)&red_enemy[count_2] ) ) { // kill missile missile[count].state = MISSILE_DEAD; // kill enemy current->state = ENEMY_DEAD; // enemy hit indicator enemy_hit = 1; // start an explosion StartExplosions( current->sprite.x+10, current->sprite.y+10, EXPLOSION_SPEED ); // increase players score game_info.money += 10; }// end if collision }// end if enemy ALIVE if( enemy_hit ) break; }// end for NUM_ENEMIES }// end if Missile is ALIVE and is players }// end for NUM_MISSILES }// end PlayerMissileCollideRight //------------------------------------------------------------------------------ // Function: EnemyMissileCollide() // Description: Check if enemy missiles hit player, if true // players energy level goes down a bit // Parameters: miss_x: x location of missile // miss_y: y location of missile // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void EnemyMissileCollide( int miss_x, int miss_y ) { int count, player_hit = 0; // check all missiles for( count=0; countstate = ROCKET_DEAD; // start an explosion StartExplosions( current->sprite.x+5, current->sprite.y+2, EXPLOSION_SPEED ); // increase players score game_info.money +=5; }// end bounding boxes if( rocket_hit ) break; }// end if missile is PLAYERS }// end for NUM_MISSILES }// end if rocket is ALIVE }// end for NUM_ROCKETS }// end PlayerRocketCollision //--------------------------------EOF--------------------------------------------