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