Invader.h 3.4 KB

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