Shield.h 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_SHIELD_H
  29. #define RMLUI_LUAINVADERS_SHIELD_H
  30. #include <RmlUi/Core/Types.h>
  31. class Game;
  32. const int NUM_SHIELD_CELLS = 6;
  33. const int PIXEL_SIZE = 4;
  34. /**
  35. A shield, protecting the player.
  36. @author Robert Curry
  37. */
  38. class Shield {
  39. public:
  40. enum ShieldType { REGULAR, TOP_LEFT, TOP_RIGHT, BOTTOM_LEFT, BOTTOM_RIGHT };
  41. /// Construct the invader
  42. Shield(Game* game, ShieldType type);
  43. ~Shield();
  44. /// Sets up which cells are on and off, based on the type.
  45. void InitialiseCells();
  46. /// Set the shield's screen position
  47. /// @param position Position in screen space
  48. void SetPosition(const Rml::Vector2f& position);
  49. /// Get the current shield position
  50. /// @returns The shield's position in screen space
  51. const Rml::Vector2f& GetPosition() const;
  52. /// Render the shield.
  53. void Render(Rml::RenderManager& render_manager, float dp_ratio);
  54. /// Returns true if the position hits the shield
  55. /// If a hit is detected, will degrade the shield.
  56. /// @param position Position to do the hit check at
  57. /// @returns If the shield was hit
  58. bool CheckHit(const Rml::Vector2f& position);
  59. protected:
  60. void SustainDamage();
  61. // Game this shield is in
  62. Game* game;
  63. // The invader type we represent
  64. ShieldType type;
  65. // The current position in screen space of the shield
  66. Rml::Vector2f position;
  67. // Our current state - starts at 4, degrades once per hit.
  68. int health;
  69. enum ShieldCellState { ON, OFF, DESTROYED };
  70. ShieldCellState shield_cells[NUM_SHIELD_CELLS][NUM_SHIELD_CELLS];
  71. };
  72. #endif