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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    COrganicGun
  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 COrganicGun::m_random;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. COrganicGun::COrganicGun()
  24. {
  25.     m_weapon = 0;
  26.     m_fired = false;
  27. }
  28.  
  29. //-------------------------------------------------------------
  30.  
  31. COrganicGun::~COrganicGun()
  32. {
  33. }
  34.  
  35. //-------------------------------------------------------------
  36.  
  37. void COrganicGun::setDirection(int dir)
  38. {
  39.     if (dir > 0) {
  40.         m_side = ORGANICGUN_LEFT;
  41.         m_weapon->setDirection(gsCVector(1.f,0.f));
  42.         }
  43.     else {
  44.         m_side = ORGANICGUN_RIGHT;
  45.         m_weapon->setDirection(gsCVector(-1.f,0.f));
  46.         }
  47. }
  48.  
  49. //-------------------------------------------------------------
  50.  
  51. bool COrganicGun::activate()
  52. {
  53.     if (!isActive()) {
  54.         m_weapon = new CSpinnerWeapon;
  55.         m_scene->addActor(m_weapon);
  56.         m_weapon->activate();
  57.         m_weapon->setOwner(this);
  58.         m_weapon->setOffset(gsCVector(16.f,16.f));
  59.         m_weapon->setFiringMode(WEAPON_MANUAL);
  60.         m_weapon->setGrade(WEAPON_BEST);
  61.  
  62.         m_state = ORGANICGUN_STILL;
  63.         m_timer.start();
  64.         }
  65.  
  66.     return CActor::activate();
  67. }
  68.  
  69. //-------------------------------------------------------------
  70. void COrganicGun::kill()
  71. {
  72.     if (m_weapon) {
  73.         m_weapon->kill();
  74.         m_weapon = 0;
  75.         }
  76.  
  77.     CActor::kill();
  78. }
  79.  
  80. //-------------------------------------------------------------
  81.         
  82. bool COrganicGun::update(Controls *controls)
  83. {
  84.     if (m_shield == 0) {
  85.         explode();
  86.         kill();
  87.         return true;
  88.         }
  89.  
  90.     switch (m_state) {
  91.         case ORGANICGUN_STILL:
  92.             {
  93.             m_sprite.setFrame(m_side + ORGANICGUN_SHOT_START);
  94.  
  95.             if (m_timer.getTime() >= ORGANICGUN_STILL_TIME) {
  96.  
  97.                 m_state = ORGANICGUN_SHOOTING;
  98.                 m_fired = false;
  99.                 m_timer.start();
  100.                 }
  101.             }
  102.             break;
  103.         case ORGANICGUN_SHOOTING:
  104.             {
  105.                 int frame = (int) (m_timer.getTime() * getActorInfo().m_anim_rate);
  106.                 if (frame >= ORGANICGUN_SHOT_FRAMES) {
  107.                     m_sprite.setFrame(m_side + ORGANICGUN_SHOT_START);
  108.                     m_state = ORGANICGUN_STILL;
  109.                     m_timer.start();
  110.                     }            
  111.                 else {
  112.                     m_sprite.setFrame(m_side + ORGANICGUN_SHOT_START + frame);
  113.                     if (!m_fired && frame >= ORGANICGUN_LAUNCH_FRAME) {
  114.                         m_weapon->fire();
  115.                         m_fired = true;
  116.                         }
  117.                     }
  118.             }
  119.             break;
  120.         }
  121.  
  122.     return true;
  123. }
  124.  
  125. //-------------------------------------------------------------
  126.  
  127. void COrganicGun::onLeavingScreen()
  128. {
  129.     if (!CPlayGameState::reachedBoss())
  130.         kill();
  131. }
  132.  
  133. //-------------------------------------------------------------
  134.  
  135.