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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CRusher
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CAlien
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. gsCRandom CRusher::m_random;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. CRusher::CRusher()
  24. {
  25.     m_weapon = 0;
  26. }
  27.  
  28. //-------------------------------------------------------------
  29.  
  30. CRusher::~CRusher()
  31. {
  32. }
  33.  
  34. //-------------------------------------------------------------
  35.  
  36. void CRusher::kill()
  37. {
  38.     if (m_weapon) {
  39.         m_weapon->kill();
  40.         m_weapon = 0;
  41.         }
  42.  
  43.     CActor::kill();
  44. }
  45.  
  46. //-------------------------------------------------------------
  47.  
  48. bool CRusher::activate()
  49. {
  50.     if (!isActive()) {
  51.  
  52. /*        if (m_random.getInt(100) < 25) {
  53.             m_weapon = new CSpinnerWeapon;
  54.             m_scene->addActor(m_weapon);
  55.             m_weapon->activate();
  56.             m_weapon->setOwner(this);
  57.             m_weapon->setOffset(gsCVector(0.f,0.f));
  58.             }
  59. */
  60.         m_timer.start();
  61.         }
  62.  
  63.     return CActor::activate();
  64. }
  65.  
  66. //-------------------------------------------------------------
  67.  
  68. bool CRusher::update(Controls *controls)
  69. {
  70.     if (m_shield == 0) {
  71.         explode();
  72.         kill();
  73.         return true;
  74.         }
  75.  
  76.     if (m_weapon) {
  77.         CShip *ship = m_scene->findShip();
  78.  
  79.         // fire weapon towards ship
  80.  
  81.         if (ship &&
  82.             getPosition().getY() < ship->getPosition().getY()) {
  83.             gsCVector dir = ship->getPosition() - getPosition();
  84.             dir.normalize();
  85.             m_weapon->setDirection(dir);
  86.             }
  87.         }
  88.  
  89.     m_position += m_velocity;
  90.  
  91.     animate(ANIMATE_LOOP);
  92.  
  93.     return true;
  94. }
  95.  
  96. //-------------------------------------------------------------
  97.