Game.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. /*
  2. * This source file is part of libRocket, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://www.librocket.com
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. *
  8. * Permission is hereby granted, free of charge, to any person obtaining a copy
  9. * of this software and associated documentation files (the "Software"), to deal
  10. * in the Software without restriction, including without limitation the rights
  11. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  12. * copies of the Software, and to permit persons to whom the Software is
  13. * furnished to do so, subject to the following conditions:
  14. *
  15. * The above copyright notice and this permission notice shall be included in
  16. * all copies or substantial portions of the Software.
  17. *
  18. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  19. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  20. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  21. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  22. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  23. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  24. * THE SOFTWARE.
  25. *
  26. */
  27. #ifndef ROCKETINVADERSGAME_H
  28. #define ROCKETINVADERSGAME_H
  29. #include <Rocket/Core/Types.h>
  30. #include <Rocket/Core/Texture.h>
  31. class Shield;
  32. class Invader;
  33. class Defender;
  34. class Mothership;
  35. /**
  36. Runs the game.
  37. - Updates the Invader positions, animations and bombs.
  38. - Updates the player position and bullets
  39. @author Lloyd Weehuizen
  40. */
  41. class Game
  42. {
  43. public:
  44. Game();
  45. ~Game();
  46. /// Initialise a new game
  47. void Initialise();
  48. /// Update the game
  49. void Update();
  50. /// Render the game
  51. void Render();
  52. /// Access the defender
  53. Defender* GetDefender();
  54. /// Access the invaders
  55. Invader* GetInvader(int index);
  56. /// Get the total number of invaders
  57. int GetNumInvaders();
  58. /// Returns true if the given invader can drop bomb
  59. bool CanDropBomb(int invader_index);
  60. /// Access the shields.
  61. Shield* GetShield(int index);
  62. /// Get the total number of shields
  63. int GetNumShields();
  64. /// Adds a score onto the player's score.
  65. void AddScore(int score);
  66. /// Sets the player's score.
  67. void SetScore(int score);
  68. /// Sets the player's high-score.
  69. void SetHighScore(int score);
  70. /// Set the number of defender lives.
  71. void SetLives(int lives);
  72. /// Set the current wave
  73. void SetWave(int wave);
  74. /// Remove a defender life
  75. void RemoveLife();
  76. /// Checks if the game is over
  77. bool IsGameOver() const;
  78. /// Get the dimensions of the game window.
  79. const Rocket::Core::Vector2f GetWindowDimensions();
  80. private:
  81. // The current invaders
  82. Invader** invaders;
  83. // The direction they're moving
  84. float current_invader_direction;
  85. // Time of the last invader update
  86. Rocket::Core::Time invader_frame_start;
  87. // How often the invaders move
  88. Rocket::Core::Time invader_move_freq;
  89. // Is the game over
  90. bool game_over;
  91. // Helper function to move the invaders
  92. void MoveInvaders();
  93. // Our current defener
  94. Defender* defender;
  95. // Number of lives the defender has left
  96. int defender_lives;
  97. // The current shields
  98. Shield** shields;
  99. // Texture that contains the sprites
  100. Rocket::Core::TextureHandle texture;
  101. void InitialiseShields();
  102. void InitialiseWave();
  103. void OnGameOver();
  104. };
  105. #endif