home *** CD-ROM | disk | FTP | other *** search
/ PC Format (South-Africa) 2001 June / PCFJune.iso / Xenon / XenonSource.exe / xenon / source / homingmissileweapon.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2000-09-11  |  1.9 KB  |  76 lines

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CHomingMissileWeapon
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CWeapon
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. CHomingMissileWeapon::CHomingMissileWeapon()
  20. {
  21. }
  22.  
  23. //-------------------------------------------------------------
  24.  
  25. CHomingMissileWeapon::~CHomingMissileWeapon()
  26. {
  27. //    CWeapon::~CWeapon();
  28. }
  29.  
  30. //-------------------------------------------------------------
  31.  
  32. bool CHomingMissileWeapon::fire()
  33. {
  34.     if (!isValidFiringPosition())
  35.         return false;    
  36.  
  37.     CHomingMissile *h = new CHomingMissile;
  38.     m_scene->addActor(h);
  39.  
  40.     CAlien *alien;
  41.     switch (m_direction) {
  42.         case WEAPON_FORWARD:
  43.             alien = (CAlien *) m_scene->findNearestActor(ACTOR_TYPE_ALIEN,getPosition(),-1);
  44.             
  45.             if (alien)
  46.                 h->setTarget(alien->getPosition());
  47.             else
  48.                 h->setTarget(gsCVector(320.f,getPosition().getY() - 480.f));
  49.  
  50.             h->setPosition(getPosition() - gsCVector(0.f,24.f));
  51.             h->setVelocity(gsCVector(0.f,-h->getActorInfo().m_speed[m_grade]));
  52.             break;
  53.         case WEAPON_REVERSE:
  54.             alien = (CAlien *) m_scene->findNearestActor(ACTOR_TYPE_ALIEN,getPosition(),1);
  55.             
  56.             if (alien)
  57.                 h->setTarget(alien->getPosition());
  58.             else
  59.                 h->setTarget(gsCVector(320.f,getPosition().getY() + 480.f));
  60.  
  61.             h->setPosition(getPosition() + gsCVector(0.f,24.f));
  62.             h->setVelocity(gsCVector(0.f,h->getActorInfo().m_speed[m_grade]));
  63.             break;
  64.         }
  65.  
  66.     h->activate();
  67.     h->setGrade((BulletGrade) m_grade);
  68.     
  69.     if (getOwner() && getOwner()->getActorInfo().m_type == ACTOR_TYPE_SHIP)
  70.         CGameState::playSample(SAMPLE_FIRE_HOMING_MISSILE,getPosition().getX());
  71.  
  72.     return true;
  73. }
  74.  
  75. //-------------------------------------------------------------
  76.