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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CBossControl
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CActor
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. bool CBossControl::m_is_started = false;
  20. int CBossControl::m_yscroll = 0;
  21.  
  22. //-------------------------------------------------------------
  23.  
  24. BossScriptItem CBossControl::m_script[] = {
  25.     {    BOSS_MOVE_DOWN,500    },
  26.     {    BOSS_BEGIN_LOOP,0    },
  27.     {    BOSS_STATIC,50        },
  28.     {    BOSS_ROAR,0            },
  29.     {    BOSS_OPEN_EYES,0    },
  30.     {    BOSS_MOVE_UP,200    },
  31.     {    BOSS_SNORT,0        },
  32.     {    BOSS_TRIGGER,0        },
  33.     {    BOSS_STATIC,50        },
  34.     {    BOSS_TRIGGER,0        },
  35.     {    BOSS_SHUT_EYES,0    },
  36.     {    BOSS_MOVE_DOWN,200    },
  37.     {    BOSS_STATIC,50        },
  38.     {    BOSS_ROAR,0            },
  39.     {    BOSS_OPEN_EYES,0    },
  40.     {    BOSS_MOVE_UP,200    },
  41.     {    BOSS_SNORT,0        },
  42.     {    BOSS_TRIGGER,1        },
  43.     {    BOSS_STATIC,50        },
  44.     {    BOSS_TRIGGER,1        },
  45.     {    BOSS_SHUT_EYES,0    },
  46.     {    BOSS_MOVE_DOWN,200    },
  47.     {    BOSS_STATIC,50        },
  48.     {    BOSS_ROAR,0            },
  49.     {    BOSS_OPEN_EYES,0    },
  50.     {    BOSS_MOVE_UP,200    },
  51.     {    BOSS_SNORT,0        },
  52.     {    BOSS_TRIGGER,2        },
  53.     {    BOSS_STATIC,50        },
  54.     {    BOSS_TRIGGER,2        },
  55.     {    BOSS_SHUT_EYES,0    },
  56.     {    BOSS_MOVE_DOWN,200    },
  57.     {    BOSS_STATIC,50        },
  58.     {    BOSS_ROAR,0            },
  59.     {    BOSS_OPEN_EYES,0    },
  60.     {    BOSS_MOVE_UP,200    },
  61.     {    BOSS_SNORT,0        },
  62.     {    BOSS_TRIGGER,3        },
  63.     {    BOSS_STATIC,50        },
  64.     {    BOSS_TRIGGER,3        },
  65.     {    BOSS_SHUT_EYES,0    },
  66.     {    BOSS_MOVE_DOWN,200    },
  67.     {    BOSS_END_LOOP,0        }
  68. };
  69.  
  70. //-------------------------------------------------------------
  71.  
  72. CBossControl::CBossControl()
  73. {
  74.     m_is_started = false;
  75. }
  76.  
  77. //-------------------------------------------------------------
  78.  
  79. CBossControl::~CBossControl()
  80. {
  81. }
  82.  
  83. //-------------------------------------------------------------
  84.  
  85. bool CBossControl::activate()
  86. {
  87.     if (!isActive()) {
  88.         m_timer.start();
  89.         m_is_started = true;
  90.         m_yscroll = 0;
  91.         m_script_pointer = m_loop_point = m_script;
  92.         m_active_eyes = BOSS_EYES_TOTAL;
  93.         interpretScript();
  94.         }
  95.  
  96.     return CActor::activate();
  97. }
  98.  
  99. //-------------------------------------------------------------
  100.  
  101. void CBossControl::kill()
  102. {
  103.     m_is_started = false;
  104.  
  105.     CActor::kill();
  106. }
  107.  
  108. //-------------------------------------------------------------
  109.  
  110. bool CBossControl::update(Controls *controls)
  111. {
  112.     if (m_state == BOSS_DEAD)
  113.         return true;
  114.  
  115.     if (m_active_eyes == 0 && m_state != BOSS_DESTROY)
  116.         initiateDestructionSequence();
  117.  
  118.     if (m_state == BOSS_DESTROY)
  119.         updateDestructionSequence();
  120.     else {
  121.         if (m_counter <= 0)
  122.             interpretScript();
  123.  
  124.         switch (m_state) {
  125.             case BOSS_MOVE_DOWN:
  126.                 m_yscroll = 1;
  127.                 break;
  128.             case BOSS_STATIC:
  129.                 m_yscroll = 0;
  130.                 break;
  131.             case BOSS_MOVE_UP:
  132.                 m_yscroll = -1;
  133.                 break;
  134.             }
  135.  
  136.         m_counter--;
  137.         }
  138.  
  139.     return true;
  140. }
  141.  
  142. //-------------------------------------------------------------
  143.  
  144. void CBossControl::interpretScript()
  145. {
  146.     if (m_script_pointer->m_state == BOSS_BEGIN_LOOP)
  147.         m_loop_point = ++m_script_pointer;
  148.  
  149.     if (m_script_pointer->m_state == BOSS_END_LOOP)
  150.         m_script_pointer = m_loop_point;
  151.  
  152.     if (m_script_pointer->m_state == BOSS_TRIGGER) {
  153.         switch (m_script_pointer->m_param) {
  154.             case 0:
  155.                 m_mouth->trigger(0,16,0.05f);
  156.                 break;
  157.             case 1:
  158.                 m_mouth->trigger(1,16,0.05f);
  159.                 break;
  160.             case 2:
  161.                 m_mouth->trigger(2,16,0.05f);
  162.                 break;
  163.             case 3:
  164.                 m_mouth->trigger(3,16,0.05f);
  165.                 break;
  166.             }
  167.  
  168.         m_script_pointer++;
  169.         }
  170.  
  171.     if (m_script_pointer->m_state == BOSS_ROAR) {
  172.         CGameState::playSample(SAMPLE_ROAR);
  173.         m_script_pointer++;
  174.         }
  175.  
  176.     if (m_script_pointer->m_state == BOSS_SNORT) {
  177.         CGameState::playSample(SAMPLE_SNORT);
  178.         m_script_pointer++;
  179.         }
  180.  
  181.     if (m_script_pointer->m_state == BOSS_OPEN_EYES) {
  182.         CBossEye::setState(BOSSEYE_OPEN);
  183.         m_script_pointer++;
  184.         }
  185.  
  186.     if (m_script_pointer->m_state == BOSS_SHUT_EYES) {
  187.         CBossEye::setState(BOSSEYE_SHUT);
  188.         m_script_pointer++;
  189.         }
  190.     
  191.     m_counter = m_script_pointer->m_param;
  192.     m_state = m_script_pointer->m_state;
  193.  
  194.     m_script_pointer++;
  195. }
  196.  
  197. //-------------------------------------------------------------
  198.  
  199. bool CBossControl::isStarted()
  200. {
  201.     return m_is_started;
  202. }
  203.  
  204. //-------------------------------------------------------------
  205.  
  206. int CBossControl::getYScroll()
  207. {
  208.     return m_yscroll;
  209. }
  210.  
  211. //-------------------------------------------------------------
  212.  
  213. void CBossControl::initiateDestructionSequence()
  214. {
  215.     m_state = BOSS_DESTROY;
  216.  
  217.     m_scene->findShip()->setCloak(1000.f);
  218.  
  219.     m_yscroll = 1;
  220.  
  221.     gsCVector epicentre = m_mouth->getPosition();
  222.  
  223.     gsCPoint tile_size = m_scene->getMap()->getImage()->getTileSize();
  224.  
  225.     m_tile_pos = gsCPoint(epicentre) / tile_size;
  226.  
  227.     m_size = 1;
  228.  
  229.     m_destruction_timer.start();
  230. }
  231.  
  232. //-------------------------------------------------------------
  233.  
  234. void CBossControl::updateDestructionSequence()
  235. {
  236.     if (m_destruction_timer.getTime() > 0.1f) {
  237.         m_destruction_timer.start();
  238.  
  239.         for (int x = 0; x < m_size; x++) {
  240.             explodeTile(m_tile_pos + gsCPoint(x,0));
  241.             explodeTile(m_tile_pos + gsCPoint(x,m_size - 1));
  242.             explodeTile(m_tile_pos + gsCPoint(0,x));
  243.             explodeTile(m_tile_pos + gsCPoint(m_size - 1,x));
  244.             }
  245.  
  246.         m_tile_pos = m_tile_pos - gsCPoint(1,1);
  247.         m_size += 2;
  248.  
  249.         if (m_size > 21)
  250.             m_state = BOSS_DEAD;
  251.         }
  252. }
  253.  
  254. //-------------------------------------------------------------
  255.  
  256. void CBossControl::explodeTile(const gsCPoint& pos)
  257. {
  258.     gsCMap *map = m_scene->getMap();
  259.  
  260.     gsCMapTile *tile = map->getMapTile(pos);
  261.  
  262.     if (tile) {
  263.         if (!tile->isEmpty() && !tile->isHidden()) {
  264.             tile->setHidden();
  265.  
  266.                 CBigExplosion *exp = new CBigExplosion();
  267.                 m_scene->addActor(exp);
  268.  
  269.                 gsCPoint tile_size = map->getImage()->getTileSize();
  270.                 gsCPoint tile_centre = tile_size / gsCPoint(2,2);
  271.  
  272.                 gsCPoint p = pos * tile_size + tile_centre;
  273.                 exp->setPosition(gsCVector((float) p.getX(),(float) p.getY()));
  274.                 exp->activate();
  275.             }
  276.         }
  277. }
  278.  
  279. //-------------------------------------------------------------
  280.