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

  1. #include "rocket.h"
  2. #include "gfx.h"
  3. #include "global.h"
  4. #include "messages.h"
  5.  
  6. Rocket::Rocket()
  7. {
  8.   loc.x=loc.y=0;
  9. }
  10.  
  11. void Rocket::initialize()
  12. {
  13.   load_gfxlib( "ss.gfx" );
  14. }
  15.  
  16. void Rocket::Reset(void)
  17. {
  18.   width=get_image_width( ROCKET );
  19.   height=get_image_height( ROCKET );
  20. }
  21.  
  22. boolean Rocket::Move(void)
  23. {
  24.   if ( !active )
  25.     return FALSE;
  26.  
  27.   // movement step
  28.   const int MoveLength=8;
  29.  
  30.   if ( loc.y>180 )
  31.     return FALSE;
  32.   else
  33.     loc.y+=MoveLength;
  34.  
  35.   if ( CheckForCollision() )
  36.   {
  37.     active=NO;
  38.     MsgInt=20;
  39.     post_message( StealthHit, 0 );
  40.   }
  41.  
  42.   return TRUE;
  43. }
  44.  
  45. boolean Rocket::CheckForCollision()
  46. {
  47.   rect MyPos={loc.x,loc.y,loc.x+width,loc.y+15,width,height};
  48.   // check to see if I hit the stealth
  49.   if ( MyPos.b<StealthRect.t || MyPos.t>StealthRect.b )
  50.     return NO;
  51.   else
  52.   {
  53.     if ( MyPos.r<StealthRect.l || MyPos.l>StealthRect.r )
  54.       return NO;
  55.     else
  56.       return YES;
  57.   }
  58. }
  59.  
  60. void Rocket::OnDraw(void)
  61. {
  62.   show_image( loc.x, loc.y, ROCKET );
  63. }
  64.