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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CEngine
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    CActor
  10. //
  11. // Derived:    CShipEngine
  12. //            CCloneEngine
  13. //
  14. //-------------------------------------------------------------
  15.  
  16. #include "game.h"
  17.  
  18. //-------------------------------------------------------------
  19.  
  20. CEngine::CEngine()
  21. {
  22.     m_offset = gsCVector(0.f,0.f);
  23.     m_thrust = 0;
  24.  
  25.     m_min_extent = gsCVector(0.f,0.f);
  26.     m_max_extent = gsCVector(0.f,0.f);
  27.     m_thrust_rate = 0.f;
  28. }
  29.  
  30. //-------------------------------------------------------------
  31.  
  32. CEngine::~CEngine()
  33. {
  34. //    CActor::~CActor();
  35. }
  36.  
  37. //-------------------------------------------------------------
  38.  
  39. bool CEngine::activate()
  40. {
  41.     if (!isActive()) {
  42.         m_timer.start();
  43.         m_thrust_timer.start();
  44.         }
  45.  
  46.     return CActor::activate();
  47. }
  48.  
  49. //-------------------------------------------------------------
  50.  
  51. void CEngine::applyThrust(int thrust)
  52. {
  53.     if (m_thrust_timer.getTime() > m_thrust_rate) {
  54.         m_thrust_timer.start();
  55.  
  56.         if (thrust) {
  57.             m_thrust++;
  58.             if (m_thrust > ENGINE_MAX_THRUST)
  59.                 m_thrust = ENGINE_MAX_THRUST;
  60.             }
  61.         else {
  62.             m_thrust--;
  63.             if (m_thrust < 0)
  64.                 m_thrust = 0;
  65.             }
  66.         }
  67. }
  68.  
  69. //-------------------------------------------------------------
  70.  
  71. void CEngine::setOffset(const gsCVector& offset)
  72. {
  73.     m_offset = offset;
  74. }
  75.  
  76. //-------------------------------------------------------------
  77.  
  78. bool CEngine::update(Controls *controls)
  79. {
  80.     float p = (float) m_thrust / ENGINE_MAX_THRUST;
  81.  
  82.     gsCVector extent = m_min_extent + (m_max_extent - m_min_extent) * p;
  83.  
  84.     m_position = getOwner()->getPosition() + m_offset + extent;
  85.  
  86.     return true;
  87. }
  88.  
  89. //-------------------------------------------------------------
  90.  
  91. void CEngine::setParams(const gsCVector& min_extent,const gsCVector& max_extent,float thrust_rate)
  92. {
  93.     m_min_extent = min_extent;
  94.     m_max_extent = max_extent;
  95.     m_thrust_rate = thrust_rate;
  96. }
  97.  
  98. //-------------------------------------------------------------
  99.