home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include "heli.h"
- #include "gfx.h"
- #include "sfx.h"
- #include "global.h"
- #include "messages.h"
-
- void Helicopter::Setup( Director* director )
- {
- MaxNumShots=10-1;
- set_director( director );
- for ( int i=0; i<MaxNumShots; i++ )
- rocket[i].set_director( director );
- }
-
- void Helicopter::initialize()
- {
- load_gfxlib( "ss.gfx" );
- load_sfxlib( "ss.sfx" );
- // check for kill
- request_message_cue( HelicopterHit, (callback)&Helicopter::OnHit );
- }
-
- void Helicopter::GetNewLocation(void)
- {
- if ( my_director() )
- {
- loc.y=1-get_image_height( HELICOPTERa );
- randomize();
- loc.x=rand()%320;
- }
- }
-
- void Helicopter::Reset(void)
- {
- for ( int i=0; i<MaxNumShots; i++ )
- rocket[i].Reset();
- HelicopterRect.w=width=get_image_width( HELICOPTERa );
- HelicopterRect.h=height=get_image_height( HELICOPTERa );
- ExplosionWidth=get_image_width( EXPLOSION )/2;
- ExplosionHeight=get_image_height( EXPLOSION )/2;
- GetNewLocation();
- alive=YES;
- for ( i=0; i<MaxNumShots; i++ )
- rocket[i].Deactivate();
- }
-
- void Helicopter::Move(void)
- {
- if ( !alive )
- return;
-
- // movement step
- const int MoveLength=4;
- // 0=left, 1=right
- static int dir=1;
- static int hmax=160-(width/2);
- // move ship left and right
- if ( dir==1 )
- {
- if ( loc.x>=hmax )
- dir=0, loc.x-=MoveLength;
- else
- loc.x+=MoveLength;
- }
- else
- {
- if ( loc.x==0 || loc.x-MoveLength<0 )
- dir=1, loc.x+=MoveLength;
- else
- loc.x-=MoveLength;
- }
- // 0=up, 1=down
- static int vdir=1;
- // move ship up and down
- if ( vdir==1 )
- {
- if ( loc.y>200 )
- {
- static GoneUp=FALSE;
- randomize();
- vdir=rand()%2;
- if ( vdir==0 && GoneUp==FALSE )
- loc.y-=MoveLength, GoneUp=TRUE;
- else
- GetNewLocation(), GoneUp=FALSE;
- }
- else
- loc.y+=MoveLength;
- }
- else
- {
- if ( loc.y<=100 )
- vdir=1, loc.y+=MoveLength;
- else
- loc.y-=MoveLength;
- }
- HelicopterRect.l=loc.x, HelicopterRect.r=loc.x+width;
- HelicopterRect.t=loc.y, HelicopterRect.b=loc.y+height;
- // check to see if stealth is in our line of fire
- if ( HorizontalProximityCheck( HelicopterRect, StealthRect ) )
- FireRocket();
- }
-
- void Helicopter::OnDraw(void)
- {
- static int ImageNum;
-
- if ( !alive )
- {
- // display and sound explosion
- int x=(HelicopterRect.l+(width/2))-ExplosionWidth;
- int y=(HelicopterRect.t+(height/2))-ExplosionHeight;
- show_clipped_image( x, y, EXPLOSION );
- return;
- }
-
- ImageNum=1-ImageNum;
- show_clipped_image( loc.x, loc.y, ImageNum ? HELICOPTERa:HELICOPTERb );
- for ( int i=0; i<MaxNumShots; i++ )
- {
- if ( rocket[i].IsActive() )
- {
- if ( rocket[i].Move()==FALSE )
- rocket[i].Deactivate();
- else
- rocket[i].OnDraw();
- }
- }
- }
-
- void Helicopter::FireRocket(void)
- {
- static int FirePause;
- FirePause++;
- if ( FirePause<5 )
- return;
- FirePause=0;
-
- for ( int i=0; i<MaxNumShots; i++ )
- {
- if ( !rocket[i].IsActive() )
- {
- play_sound_clip( SND_ROCKET );
- rocket[i].Activate( loc.x+16, loc.y+32 );
- break;
- }
- }
- }
-
- static int HelisLeft=2;
- void Helicopter::OnHit(int)
- {
- HelisLeft--;
- if ( HelisLeft==0 )
- {
- // do the kill thang
- for ( int i=0; i<MaxNumShots; i++ )
- rocket[i].Deactivate();
- alive=NO;
- HelisLeft=2;
- MsgInt=250;
- post_message( ScoreUpdate, 0 );
- post_message( HelicopterDestroyed, 0 );
- }
- }
-
- void Helicopter::SoundDestroy(void)
- {
- play_sound_clip( SND_EXPLODE );
- }