Spectre.hpp 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. #pragma once
  2. #include <SFML/Graphics.hpp>
  3. #include <SFML/Audio.hpp>
  4. #include "IEntity.hpp"
  5. #define CHAOS_OVERLAY_THRESHOLD 0.6f
  6. #define CHAOS_CAMERASHAKE_THRESHOLD 0.7f
  7. #define CHAOS_SCALE_THRESHOLD 0.2f
  8. class Player;
  9. class Spectre: public sf::Drawable, public sf::Transformable, public IEntity {
  10. public:
  11. struct Settings {
  12. std::string sheet{ "" };
  13. unsigned frames{ 1 };
  14. unsigned alt{ 1 };
  15. float frameDuration{ 1.f };
  16. float size{ 1.f };
  17. float scareRange{ 200.f };
  18. float duration{ 10.f };
  19. bool scale{ false };
  20. bool skew{ false };
  21. bool rotate{ false }; // whether to rotate to the player
  22. bool rotateRandom{ false }; // whether to rotate randomly
  23. bool follow{ false }; // whether to follow the player; otherwise move parabolically
  24. bool overlay{ false }; // whether to sometimes display multiple frames at once
  25. bool rainbow{ false };
  26. };
  27. Spectre() = delete;
  28. Spectre(Spectre::Settings settings);
  29. virtual ~Spectre();
  30. void update(float dt) override;
  31. static void setMinChaos(float chaos) {
  32. if (chaos > 1.f) {
  33. chaos = 1.f;
  34. }
  35. if (s_chaos < chaos) {
  36. s_chaos = chaos;
  37. }
  38. s_limit.x = chaos;
  39. }
  40. static void setMaxChaos(float chaos) {
  41. if (chaos < 0.f) {
  42. chaos = 0.f;
  43. }
  44. if (s_chaos > chaos) {
  45. s_chaos = chaos;
  46. }
  47. s_limit.y = chaos;
  48. }
  49. static float getMaxChaos() {
  50. return s_limit.y;
  51. }
  52. static void setChaos(float chaos);
  53. static void addChaos(float chaos);
  54. static void setPlayer(Player* player);
  55. static float getChaos();
  56. void pleaseDie() {
  57. m_total_clock = 10000.f;
  58. }
  59. bool isDead() {
  60. return m_dead;
  61. }
  62. private:
  63. virtual void draw(sf::RenderTarget& rt, sf::RenderStates states) const override;
  64. Settings m_settings;
  65. float m_clock{ 0.f };
  66. float m_total_clock{ 0.f };
  67. float m_announceClock{ 0.f };
  68. float m_alpha{ 0.f };
  69. unsigned m_frame{ 0 };
  70. std::vector<std::pair<bool, sf::Sprite>> m_sprites;
  71. static float s_chaos;
  72. static sf::Vector2f s_limit;
  73. static Player* s_player;
  74. bool m_dead{ false };
  75. sf::Sound m_sound;
  76. sf::Clock m_scale_clock;
  77. float m_m1{ -100.f };
  78. float m_m2{ -100.f };
  79. float m_x{ 0.f };
  80. float m_rai[3]{ 255.f, 255.f };
  81. int m_rdir[3]{ 0, 0 };
  82. };