home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / WTJ9403.ZIP / BARNHART / SO_MISL.CPP < prev    next >
C/C++ Source or Header  |  1993-11-21  |  2KB  |  76 lines

  1.  
  2. // so_misl.cpp - Implements class Missile - the bullets the Player fires
  3.  
  4. // Andy Barnhart
  5. // This program is provided as a sample to accompany an article on graphics
  6. //    animation using C++
  7. // This seems to work for me and I hope it works for you. No other warranty
  8. //    is expressed or implied.
  9.  
  10. #include <so_all.hpp>
  11.  
  12. Missile::Missile( char *res) : ScreenItem( res)
  13.     {
  14.     SOType = TYPE_MISSILE;
  15.     inuse = FALSE;
  16.     Show( FALSE);
  17.     }
  18.  
  19. BOOL Missile::Update( void)
  20.     {
  21.     ScreenObj *SONxt;
  22.     RECT rc;
  23.                                          
  24.     // We move twice per update cause Missiles are fast
  25.     // Rather than a convoluted loop (conditional logic would be hard to
  26.     //    follow) we just do it twice                                         
  27.     if( !inuse) return( FALSE);
  28.     SetRect( &rc);
  29.     inuse = ScreenItem::Update();
  30.     if( inuse)
  31.         {                            
  32.         // Loop through everything and see if we hit anything
  33.         for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
  34.             {
  35.             if( (SONxt != this) && (SONxt->InRect( &rc)))
  36.                 if( SONxt->Hit( TYPE_MISSILE))
  37.                     {
  38.                     inuse = FALSE;
  39.                     }
  40.             }
  41.         }
  42.     if( inuse)
  43.         {
  44.         SetRect( &rc);
  45.         inuse = ScreenItem::Update();
  46.         for( SONxt = Background->Next(); SONxt != NULL; SONxt = SONxt->Next())
  47.             {
  48.             if( (SONxt != this) && (SONxt->InRect( &rc)))
  49.                 if( SONxt->Hit( TYPE_MISSILE))
  50.                     {
  51.                     inuse = FALSE;
  52.                     }
  53.             }
  54.         }
  55.     if( !inuse && shown) Show( FALSE);
  56.     return( inuse);
  57.     }
  58.  
  59. // Being fired - set a target and let 'er rip...
  60. void Missile::Fire( int sx, int sy, int tx, int ty)
  61.     {
  62.     Move( sx, sy - (height/2));
  63.     Show( TRUE);
  64.     if( sx > tx) sx -= width;
  65.     SetTarget( tx, ty );
  66.     inuse = TRUE;
  67.     }
  68.                  
  69. // Note that we lie about our type if not in use. That's because we are just
  70. //   hidden at the last place we were shown, and not truly a hazard                 
  71. int Missile::Type( void)
  72.     {
  73.     if( inuse)return TYPE_MISSILE;
  74.     return( NULL);
  75.     }
  76.