Game.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. /*
  2. * This source file is part of RmlUi, the HTML/CSS Interface Middleware
  3. *
  4. * For the latest information, see http://github.com/mikke89/RmlUi
  5. *
  6. * Copyright (c) 2008-2010 CodePoint Ltd, Shift Technology Ltd
  7. * Copyright (c) 2019-2023 The RmlUi Team, and contributors
  8. *
  9. * Permission is hereby granted, free of charge, to any person obtaining a copy
  10. * of this software and associated documentation files (the "Software"), to deal
  11. * in the Software without restriction, including without limitation the rights
  12. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  13. * copies of the Software, and to permit persons to whom the Software is
  14. * furnished to do so, subject to the following conditions:
  15. *
  16. * The above copyright notice and this permission notice shall be included in
  17. * all copies or substantial portions of the Software.
  18. *
  19. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  20. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  21. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  22. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  23. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  24. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  25. * THE SOFTWARE.
  26. *
  27. */
  28. #ifndef RMLUI_LUAINVADERS_GAME_H
  29. #define RMLUI_LUAINVADERS_GAME_H
  30. #include <RmlUi/Core/Texture.h>
  31. #include <RmlUi/Core/Types.h>
  32. class Shield;
  33. class Invader;
  34. class Defender;
  35. class Mothership;
  36. /**
  37. Runs the game.
  38. - Updates the Invader positions, animations and bombs.
  39. - Updates the player position and bullets
  40. @author Lloyd Weehuizen
  41. */
  42. class Game {
  43. public:
  44. Game();
  45. ~Game();
  46. /// Initialise a new game
  47. void Initialise();
  48. /// Update the game
  49. void Update(double t);
  50. /// Render the game
  51. void Render(Rml::RenderManager& render_manager, float dp_ratio);
  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 Rml::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. double invader_frame_start;
  87. // How often the invaders move
  88. double 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. Rml::Texture texture;
  101. void InitialiseShields();
  102. void InitialiseWave();
  103. void OnGameOver();
  104. };
  105. #endif