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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CBossMouth
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CBoss
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. gsCRandom CBossMouth::m_random;
  20.  
  21. //-------------------------------------------------------------
  22.  
  23. CBossMouth::CBossMouth()
  24. {
  25.     m_mouth = this;
  26.     m_mode = -1;
  27. }
  28.  
  29. //-------------------------------------------------------------
  30.  
  31. CBossMouth::~CBossMouth()
  32. {
  33.     m_mouth = 0;
  34. }
  35.  
  36. //-------------------------------------------------------------
  37.  
  38. bool CBossMouth::activate()
  39. {
  40.     if (!isActive()) {
  41.         m_timer.start();
  42.         m_firing_timer.reset();
  43.         }
  44.  
  45.     return CActor::activate();
  46. }
  47.  
  48. //-------------------------------------------------------------
  49.  
  50. bool CBossMouth::update(Controls *controls)
  51. {
  52.     if (m_shield == 0) {
  53.         explode();
  54.         kill();
  55.         return true;
  56.         }
  57.  
  58.     if (m_mode != -1) {
  59.         if (m_firing_timer.getTime() >= m_shot_delay) {
  60.  
  61.             m_firing_timer.start();
  62.  
  63.             CSpinner *s = 0;
  64.  
  65.             if (m_mode == 0) {
  66.                 s = new CSpinner;
  67.                 m_scene->addActor(s);
  68.                 s->activate();
  69.                 s->setPosition(getPosition());
  70.  
  71.                 float x = -2.f + 4.f * (float) m_shots_fired / (m_shots_total - 1);
  72.  
  73.                 s->setVelocity(gsCVector(x,1.f));
  74.                 s->setGrade(BULLET_STANDARD);
  75.                 }
  76.             else if (m_mode == 1) {
  77.                 s = new CSpinner;
  78.                 m_scene->addActor(s);
  79.                 s->activate();
  80.                 s->setPosition(getPosition());
  81.  
  82.                 float x = 2.f - 4.f * (float) m_shots_fired / (m_shots_total - 1);
  83.  
  84.                 s->setVelocity(gsCVector(x,2.f));
  85.                 s->setGrade(BULLET_MEDIUM);
  86.                 }
  87.             else if (m_mode == 2) {
  88.                 s = new CSpinner;
  89.                 m_scene->addActor(s);
  90.                 s->activate();
  91.                 s->setPosition(getPosition());
  92.  
  93.                 float x = -2.f + 4.f * (float) m_shots_fired / (m_shots_total - 1);
  94.  
  95.                 s->setVelocity(gsCVector(x,1.f));
  96.                 s->setGrade(BULLET_BEST);
  97.                 }
  98.             else {
  99.                 s = new CSpinner;
  100.                 m_scene->addActor(s);
  101.                 s->activate();
  102.                 s->setPosition(getPosition());
  103.  
  104.                 float x = 2.f - 4.f * (float) m_shots_fired / (m_shots_total - 1);
  105.  
  106.                 s->setVelocity(gsCVector(x,2.f));
  107.                 s->setGrade(BULLET_BEST);
  108.                 }
  109.  
  110.             m_shots_fired++;
  111.  
  112.             if (m_shots_fired >= m_shots_total) {
  113.                 m_firing_timer.reset();
  114.                 m_mode = -1;
  115.                 }
  116.             }
  117.         }
  118.  
  119.     return true;
  120. }
  121.  
  122. //-------------------------------------------------------------
  123.  
  124. void CBossMouth::trigger(int mode,int shots,float delay)
  125. {
  126.     m_mode = mode;
  127.     m_shots_total = shots;
  128.     m_shots_fired = 0;
  129.     m_shot_delay = delay;
  130.  
  131.     m_firing_timer.start();
  132. }
  133.  
  134. //-------------------------------------------------------------
  135.