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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CLoner
  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. CLoner::CLoner()
  20. {
  21. }
  22.  
  23. //-------------------------------------------------------------
  24.  
  25. CLoner::~CLoner()
  26. {
  27. }
  28.  
  29. //-------------------------------------------------------------
  30.  
  31. bool CLoner::activate()
  32. {
  33.     if (!isActive()) {
  34.         m_weapon = new CSpinnerWeapon;
  35.         m_scene->addActor(m_weapon);
  36.         m_weapon->activate();
  37.         m_weapon->setOwner(this);
  38.         m_weapon->setOffset(gsCVector(0.f,0.f));
  39.  
  40.         m_timer.start();
  41.         }
  42.  
  43.     return CActor::activate();
  44. }
  45.  
  46. //-------------------------------------------------------------
  47.  
  48. void CLoner::kill()
  49. {
  50.     if (m_weapon) {
  51.         m_weapon->kill();
  52.         m_weapon = 0;
  53.         }
  54.  
  55.     CActor::kill();
  56. }
  57.  
  58. //-------------------------------------------------------------
  59.  
  60. bool CLoner::update(Controls *controls)
  61. {
  62.     if (m_shield == 0) {
  63.         explode();
  64.         kill();
  65.         return true;
  66.         }
  67.  
  68.     CShip *ship = m_scene->findShip();
  69.  
  70.     // fire weapon towards ship
  71.  
  72.     if (ship) {
  73.         gsCVector dir = ship->getPosition() - getPosition();
  74.         dir.normalize();
  75.         m_weapon->setDirection(dir);
  76.         }
  77.  
  78.     m_position += m_velocity;
  79.  
  80.     animate(ANIMATE_LOOP);
  81.  
  82.     return true;
  83. }
  84.  
  85. //-------------------------------------------------------------
  86.