home *** CD-ROM | disk | FTP | other *** search
- #include <stdlib.h>
- #include "stealth.h"
- #include "gfx.h"
- #include "sfx.h"
-
- void Stealth::Setup( Director* director )
- {
- MaxNumShots=10;
- set_director( director );
- for ( int i=0; i<MaxNumShots; i++ )
- plasma[i].set_director( director );
- }
-
- void Stealth::initialize()
- {
- load_gfxlib( "ss.gfx" );
- load_sfxlib( "ss.sfx" );
- request_hotkey_cue( SCAN_LEFT, (callback)&Stealth::OnLeftKey );
- request_hotkey_cue( SCAN_RIGHT, (callback)&Stealth::OnRightKey );
- request_hotkey_cue( SCAN_UP, (callback)&Stealth::OnUpKey );
- request_hotkey_cue( SCAN_DOWN, (callback)&Stealth::OnDownKey );
- request_hotkey_cue( SCAN_SPACE, (callback)&Stealth::OnFireKey );
- request_joystickbutton_cue( BUTTONONE, (callback)&Stealth::OnFireKey );
- request_joystickmove_cue( (callback)&Stealth::OnMove );
- }
-
- void Stealth::Reset(void)
- {
- for ( int i=0; i<MaxNumShots; i++ )
- plasma[i].Reset();
- width=get_image_width( STEALTH );
- height=get_image_height( STEALTH );
- ExplosionWidth=get_image_width( EXPLOSION )/2;
- ExplosionHeight=get_image_height( EXPLOSION )/2;
-
- StealthRect.l=loc.x=(320/2)-(width/2);
- StealthRect.t=loc.y=200-height;
- StealthRect.r=StealthRect.l+width;
- StealthRect.b=StealthRect.t+height;
- StealthRect.w=width;
- StealthRect.h=height;
- alive=YES;
- }
-
- void Stealth::OnFireKey()
- {
- static int FirePause;
- FirePause++;
- if ( FirePause<5 )
- return;
- FirePause=0;
-
- for ( int i=0; i<MaxNumShots; i++ )
- {
- if ( !plasma[i].IsActive() )
- {
- play_sound_clip( SND_PLASMA );
- plasma[i].Activate( loc.x+16, loc.y );
- break;
- }
- }
- }
-
- void Stealth::OnMove(int x,int y)
- {
- MoveLength = max(abs(x) / 16, 4);
- x > 0 ? OnRightKey() : OnLeftKey();
- MoveLength = max(abs(y) / 16, 4);
- y > 0 ? OnUpKey() : OnDownKey();
- MoveLength = 4;
- }
- void Stealth::OnDraw(void)
- {
- if ( !alive )
- {
- // draw explosion in middle
- int x=(StealthRect.l+(width/2))-ExplosionWidth;
- int y=(StealthRect.t+(height/2))-ExplosionHeight;
- show_clipped_image( x, y, EXPLOSION );
- return;
- }
-
- show_image( loc.x, loc.y, STEALTH );
- for ( int i=0; i<MaxNumShots; i++ )
- {
- if ( plasma[i].IsActive() )
- {
- if ( plasma[i].Move()==FALSE )
- plasma[i].Deactivate();
- else
- plasma[i].OnDraw();
- }
- }
- }
-
- void Stealth::SoundDestroy(void)
- {
- // sound the explosion
- play_sound_clip( SND_EXPLODE );
- while ( sound_clip_is_playing() ) ;
- }
-