Invader.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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 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 RMLUIINVADERSINVADER_H
  29. #define RMLUIINVADERSINVADER_H
  30. #include <RmlUi/Core/Types.h>
  31. class Game;
  32. /**
  33. An alien invader.
  34. @author Lloyd Weehuizen
  35. */
  36. class Invader
  37. {
  38. public:
  39. enum InvaderType { UNKNOWN, RANK1, RANK2, RANK3, MOTHERSHIP };
  40. enum BombType { NONE, RAY, MISSILE };
  41. /// Construct the invader
  42. Invader(Game* game, InvaderType type, int index);
  43. ~Invader();
  44. /// Set the invaders screen position
  45. /// @param position Position in screen space
  46. void SetPosition(const Rml::Core::Vector2f& position);
  47. /// Get the current invader position
  48. /// @returns The invaders position in screen space
  49. const Rml::Core::Vector2f& GetPosition() const;
  50. /// Update the invader
  51. virtual void Update();
  52. /// Render the invader
  53. void Render();
  54. /// Update the invaders animation
  55. void UpdateAnimation();
  56. /// The current invaders state
  57. enum InvaderState { ALIVE, EXPLODING, DEAD };
  58. /// Get the current invader state
  59. /// @returns Invader state
  60. InvaderState GetState();
  61. /// Returns true if the position hits the invader
  62. /// If a hit is detected, will explode and start the death timer
  63. /// @param position Position to do the hit check at
  64. /// @returns If the invader was hit
  65. bool CheckHit(const Rml::Core::Vector2f& position);
  66. protected:
  67. // Game this invader is in
  68. Game* game;
  69. // The index/id of this invader
  70. int invader_index;
  71. // The invader type we represent
  72. InvaderType type;
  73. // The current position in screen space of the invader
  74. Rml::Core::Vector2f position;
  75. // Our current animation frame
  76. int animation_frame;
  77. // Our current state
  78. InvaderState state;
  79. // Our current in-flight bomb, or none. (may be not none if we're dead.)
  80. BombType bomb;
  81. // The current position of the bomb in screen space
  82. Rml::Core::Vector2f bomb_position;
  83. // The animation frame the bomb is on
  84. int bomb_animation_frame;
  85. // When the last bomb update occured
  86. double bomb_frame_start;
  87. // Probability of us dropping a bomb - this is calculated
  88. // at construction time and based on our rank and the game
  89. // difficulty level
  90. float bomb_probability;
  91. // Time when we should die - 0, until we're hit
  92. double death_time;
  93. int GetSpriteIndex() const;
  94. };
  95. #endif