home *** CD-ROM | disk | FTP | other *** search
/ C++ Games Programming / CPPGAMES.ISO / thx / demos / skyscrap / build / stealth.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1995-04-09  |  2.4 KB  |  103 lines

  1. #include <stdlib.h>
  2. #include "stealth.h"
  3. #include "gfx.h"
  4. #include "sfx.h"
  5.  
  6. void Stealth::Setup( Director* director )
  7. {
  8.   MaxNumShots=10;
  9.   set_director( director );
  10.   for ( int i=0; i<MaxNumShots; i++ )
  11.     plasma[i].set_director( director );
  12. }
  13.  
  14. void Stealth::initialize()
  15. {
  16.   load_gfxlib( "ss.gfx" );
  17.   load_sfxlib( "ss.sfx" );
  18.   request_hotkey_cue( SCAN_LEFT,  (callback)&Stealth::OnLeftKey  );
  19.   request_hotkey_cue( SCAN_RIGHT, (callback)&Stealth::OnRightKey );
  20.   request_hotkey_cue( SCAN_UP,    (callback)&Stealth::OnUpKey    );
  21.   request_hotkey_cue( SCAN_DOWN,  (callback)&Stealth::OnDownKey  );
  22.   request_hotkey_cue( SCAN_SPACE, (callback)&Stealth::OnFireKey  );
  23.   request_joystickbutton_cue( BUTTONONE, (callback)&Stealth::OnFireKey );
  24.   request_joystickmove_cue( (callback)&Stealth::OnMove );
  25. }
  26.  
  27. void Stealth::Reset(void)
  28. {
  29.   for ( int i=0; i<MaxNumShots; i++ )
  30.     plasma[i].Reset();
  31.   width=get_image_width( STEALTH );
  32.   height=get_image_height( STEALTH );
  33.   ExplosionWidth=get_image_width( EXPLOSION )/2;
  34.   ExplosionHeight=get_image_height( EXPLOSION )/2;
  35.  
  36.   StealthRect.l=loc.x=(320/2)-(width/2);
  37.   StealthRect.t=loc.y=200-height;
  38.   StealthRect.r=StealthRect.l+width;
  39.   StealthRect.b=StealthRect.t+height;
  40.   StealthRect.w=width;
  41.   StealthRect.h=height;
  42.   alive=YES;
  43. }
  44.  
  45. void Stealth::OnFireKey()
  46. {
  47.   static int FirePause;
  48.   FirePause++;
  49.   if ( FirePause<5 )
  50.     return;
  51.   FirePause=0;
  52.  
  53.   for ( int i=0; i<MaxNumShots; i++ )
  54.   {
  55.     if ( !plasma[i].IsActive() )
  56.     {
  57.       play_sound_clip( SND_PLASMA );
  58.       plasma[i].Activate( loc.x+16, loc.y );
  59.       break;
  60.     }
  61.   }
  62. }
  63.  
  64. void Stealth::OnMove(int x,int y)
  65. {
  66.     MoveLength = max(abs(x) / 16, 4);
  67.     x > 0 ? OnRightKey() : OnLeftKey();
  68.     MoveLength = max(abs(y) / 16, 4);
  69.     y > 0 ? OnUpKey() : OnDownKey();
  70.     MoveLength = 4;
  71. }
  72. void Stealth::OnDraw(void)
  73. {
  74.   if ( !alive )
  75.   {
  76.     // draw explosion in middle
  77.     int x=(StealthRect.l+(width/2))-ExplosionWidth;
  78.     int y=(StealthRect.t+(height/2))-ExplosionHeight;
  79.     show_clipped_image( x, y, EXPLOSION );
  80.     return;
  81.   }
  82.  
  83.   show_image( loc.x, loc.y, STEALTH );
  84.   for ( int i=0; i<MaxNumShots; i++ )
  85.   {
  86.     if ( plasma[i].IsActive() )
  87.     {
  88.       if ( plasma[i].Move()==FALSE )
  89.         plasma[i].Deactivate();
  90.       else
  91.         plasma[i].OnDraw();
  92.     }
  93.   }
  94. }
  95.  
  96. void Stealth::SoundDestroy(void)
  97. {
  98.   // sound the explosion
  99.   play_sound_clip( SND_EXPLODE );
  100.   while ( sound_clip_is_playing() ) ;
  101. }
  102. 
  103.