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

  1. #include "plasma.h"
  2. #include "gfx.h"
  3. #include "messages.h"
  4. #include "global.h"
  5.  
  6. Plasma::Plasma()
  7. {
  8.   loc.x=loc.y=0;
  9. }
  10.  
  11. void Plasma::initialize()
  12. {
  13.   load_gfxlib( "ss.gfx" );
  14. }
  15.  
  16. void Plasma::Reset(void)
  17. {
  18.   width=get_image_width( PLASMA );
  19.   height=get_image_height( PLASMA );
  20. }
  21.  
  22. boolean Plasma::Move(void)
  23. {
  24.   if ( !active )
  25.     return FALSE;
  26.  
  27.   // movement step
  28.   const int MoveLength=8;
  29.  
  30.   if ( loc.y<=0 )
  31.     return FALSE;
  32.   else
  33.     loc.y-=MoveLength;
  34.  
  35.   if ( CheckForHeliCollision() )
  36.   {
  37.     active=NO;
  38.     post_message( HelicopterHit );
  39.   }
  40.   if ( CheckForF15Collision() )
  41.   {
  42.     active=NO;
  43.     post_message( F15Hit );
  44.   }
  45.  
  46.   return TRUE;
  47. }
  48.  
  49. boolean Plasma::CheckForHeliCollision(void)
  50. {
  51.   rect MyPos={loc.x,loc.y,loc.x+width,loc.y+height,width,height};
  52.   // check to see if I hit the helicopter
  53.   if ( MyPos.b<HelicopterRect.t || MyPos.t>HelicopterRect.b )
  54.     return NO;
  55.   else
  56.   {
  57.     if ( MyPos.r<HelicopterRect.l || MyPos.l>HelicopterRect.r )
  58.       return NO;
  59.     else
  60.       return YES;
  61.   }
  62. }
  63.  
  64. boolean Plasma::CheckForF15Collision(void)
  65. {
  66.   rect MyPos={loc.x,loc.y,loc.x+width,loc.y+height,width,height};
  67.   // check to see if I hit the F15
  68.   if ( MyPos.b<F15Rect.t || MyPos.t>F15Rect.b )
  69.     return NO;
  70.   else
  71.   {
  72.     if ( MyPos.r<F15Rect.l || MyPos.l>F15Rect.r )
  73.       return NO;
  74.     else
  75.       return YES;
  76.   }
  77. }
  78.  
  79. void Plasma::OnDraw(void)
  80. {
  81.   show_image( loc.x, loc.y, PLASMA );
  82. }
  83.