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

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