//------------------------------------------------------------------------------ // File: collide.c // Author: George Bain, // Date: May 24, 1997 // Description: Collision detection routines for game // Copyright (C) 1997 George Bain, All Rights Reserved //------------------------------------------------------------------------------ //------------------------------------------------------------------------------ // I N C L U D E S //------------------------------------------------------------------------------ #include // standard Sony library #include "gfx.h" #include "collide.h" //------------------------------------------------------------------------------ // Function: EnemyLeftCollide() // Description: Check if player has collided with one of the enemies // moving to the left of the screen // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void EnemyLeftCollide( void ) { int count; // loop var object_ptr current; // current enemy // check if player is ALIVE if( player.state == PLAYER_ALIVE ) { // check against all enemies for( count=0; countstate = ENEMY_DEAD; // start some explosions StartExplosions( current->sprite.x+10, current->sprite.y+10, EXPLOSION_SPEED ); StartExplosions( player.sprite.x+10, player.sprite.y+10, EXPLOSION_SPEED ); // decrease players score game_info.player_energy -= 5; break; }// end collision }// end if ENEMY_ALIVE }// end for NUM_ENEMIES }// end if PLAYER_ALIVE }// end EnemyLeftCollide //------------------------------------------------------------------------------ // Function: EnemyRightCollide() // Description: Check if player has collided with one of the enemies // moving to the right of the screen // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void EnemyRightCollide( void ) { int count; // loop var object_ptr current; // current enemy // check if player is ALIVE if( player.state == PLAYER_ALIVE ) { // check against all enemies for( count=0; countstate = ENEMY_DEAD; // start some explosions StartExplosions( current->sprite.x+10, current->sprite.y+10, EXPLOSION_SPEED ); StartExplosions( player.sprite.x+10, player.sprite.y+10, EXPLOSION_SPEED ); // decrease players score game_info.player_energy -= 5; break; }// end collision }// end if ENEMY_ALIVE }// end for NUM_ENEMIES }// end if PLAYER_ALIVE }// end EnemyRightCollide //------------------------------------------------------------------------------ // Function: PowerUpCollide() // Description: Check if player has collided with one of the power ups, // if player does collide perform certain actions // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void PowerUpCollide( void ) { int count, delta_x, delta_y; object_ptr power_one, // increase players health power_two, // destroy all enemies on screen power_three; // increase players lifes power_one = (object_ptr)&power_up[0]; power_two = (object_ptr)&power_up[1]; power_three = (object_ptr)&power_up[2]; // check if player is ALIVE if( player.state == PLAYER_ALIVE ) { // check if first powerup is ALIVE if( power_one->state == POWERUP_ALIVE ) { // test for collision if( SpriteCollision( (object_ptr)&player, (object_ptr)&power_up[0]) ) { // a hit!.. kill powerup power_one->state = POWERUP_DEAD; // make sure player isn't already full if( game_info.player_energy <= PLAYER_ENERGY ) game_info.player_energy += 100; // increase energy }// end collision }// end if first // check if second powerup is ALIVE if( power_two->state == POWERUP_ALIVE ) { // test for collision if( SpriteCollision( (object_ptr)&player, (object_ptr)&power_up[1]) ) { // a hit!.. kill powerup power_two->state = POWERUP_DEAD; // check if any enemies are ALIVE for( count=0; countstate == POWERUP_ALIVE ) { // test for collision if( SpriteCollision( (object_ptr)&player, (object_ptr)&power_up[2]) ) { // a hit!.. kill powerup power_three->state = POWERUP_DEAD; // increase players lifes game_info.player_lives += 1; }// end if collision }// end if third ALIVE }// end if PLAYER_ALIVE }// end PowerUpCollide //------------------------------------------------------------------------------ // Function: BossOneCollide() // Description: Check if player has collided with the Boss // Parameters: none // Returns: void // Notes: N/A //------------------------------------------------------------------------------ void BossOneCollide( void ) { // check if player and boss is ALIVE if( (player.state == PLAYER_ALIVE) && (boss_one.state == BOSS_ALIVE) ) { // test for collision if( SpriteCollision( (object_ptr)&player, (object_ptr)&boss_one) ) { // decrease energy game_info.boss_energy -= 15; game_info.player_energy -= 10; // start explosions StartExplosions( player.sprite.x+10, player.sprite.y+10, EXPLOSION_SPEED ); StartExplosions( boss_one.sprite.x+10, boss_one.sprite.y+10, EXPLOSION_SPEED ); }// end collision }// end if player ALIVE }// end BossOneCollide //-----------------------------------EOF----------------------------------------