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

  1. //-------------------------------------------------------------
  2. //
  3. // Class:    CPlayer
  4. //
  5. // Author:    John M Phillips
  6. //
  7. // Started:    06/05/00
  8. //
  9. // Base:    None
  10. //
  11. // Derived:    None
  12. //
  13. //-------------------------------------------------------------
  14.  
  15. #include "game.h"
  16.  
  17. //-------------------------------------------------------------
  18.  
  19. int CPlayer::m_extra_life_scores[] = {
  20.      5000000,
  21.     10000000,
  22.     15000000,
  23.     20000000,
  24.     0
  25. };
  26.  
  27. //-------------------------------------------------------------
  28.  
  29. CPlayer::CPlayer()
  30. {
  31.     m_lives = INITIAL_LIVES;
  32.     m_score = 0;
  33.     m_has_dive_pickup = false;
  34.     m_checkpoint = gsCVector(0.f,0.f);
  35. }
  36.  
  37. //-------------------------------------------------------------
  38.  
  39. CPlayer::~CPlayer()
  40. {
  41. }
  42.  
  43. //-------------------------------------------------------------
  44.  
  45. int CPlayer::getScore()
  46. {
  47.     return m_score;
  48. }
  49.  
  50. //-------------------------------------------------------------
  51.  
  52. void CPlayer::scoreBonus(int bonus)
  53. {
  54.     int old_score = m_score;
  55.  
  56.     m_score += bonus;
  57.  
  58.     int *score_level = m_extra_life_scores;
  59.  
  60.     while (*score_level != 0) {
  61.         if (old_score < *score_level &&
  62.             m_score >= *score_level) {
  63.             extraLife();
  64.             break;
  65.             }
  66.         score_level++;
  67.         }
  68. }
  69.  
  70. //-------------------------------------------------------------
  71.  
  72. int CPlayer::getLives()
  73. {
  74.     return m_lives;
  75. }
  76.  
  77. //-------------------------------------------------------------
  78.  
  79. void CPlayer::extraLife()
  80. {
  81.     if (m_lives < MAX_LIVES)
  82.         m_lives++;
  83. }
  84.  
  85. //-------------------------------------------------------------
  86.  
  87. void CPlayer::loseLife()
  88. {
  89.     if (m_lives > 0)
  90.         m_lives--;
  91.  
  92.     m_has_dive_pickup = false;
  93. }
  94.  
  95. //-------------------------------------------------------------
  96.  
  97. void CPlayer::diveBonus()
  98. {
  99.     m_has_dive_pickup = true;
  100. }
  101.  
  102. //-------------------------------------------------------------
  103.  
  104. bool CPlayer::hasDive()
  105. {
  106.     return m_has_dive_pickup;
  107. }
  108.  
  109. //-------------------------------------------------------------
  110.  
  111. void CPlayer::useDive()
  112. {
  113.     m_has_dive_pickup = false;
  114. }
  115.  
  116. //-------------------------------------------------------------
  117.  
  118. void CPlayer::setCheckpoint(const gsCVector& checkpoint)
  119. {
  120.     m_checkpoint = checkpoint;
  121. }
  122.  
  123. //-------------------------------------------------------------
  124.  
  125. gsCVector CPlayer::getCheckpoint()
  126. {
  127.     return m_checkpoint;
  128. }
  129.  
  130. //-------------------------------------------------------------
  131.