#pragma once #include #include #include "IEntity.hpp" #define CHAOS_OVERLAY_THRESHOLD 0.6f #define CHAOS_CAMERASHAKE_THRESHOLD 0.7f #define CHAOS_SCALE_THRESHOLD 0.2f class Player; class Spectre: public sf::Drawable, public sf::Transformable, public IEntity { public: struct Settings { std::string sheet{ "" }; unsigned frames{ 1 }; unsigned alt{ 1 }; float frameDuration{ 1.f }; float size{ 1.f }; float scareRange{ 200.f }; float duration{ 10.f }; bool scale{ false }; bool skew{ false }; bool rotate{ false }; // whether to rotate to the player bool rotateRandom{ false }; // whether to rotate randomly bool follow{ false }; // whether to follow the player; otherwise move parabolically bool overlay{ false }; // whether to sometimes display multiple frames at once bool rainbow{ false }; }; Spectre() = delete; Spectre(Spectre::Settings settings); virtual ~Spectre(); void update(float dt) override; static void setMinChaos(float chaos) { if (chaos > 1.f) { chaos = 1.f; } if (s_chaos < chaos) { s_chaos = chaos; } s_limit.x = chaos; } static void setMaxChaos(float chaos) { if (chaos < 0.f) { chaos = 0.f; } if (s_chaos > chaos) { s_chaos = chaos; } s_limit.y = chaos; } static float getMaxChaos() { return s_limit.y; } static void setChaos(float chaos); static void addChaos(float chaos); static void setPlayer(Player* player); static float getChaos(); void pleaseDie() { m_total_clock = 10000.f; } bool isDead() { return m_dead; } private: virtual void draw(sf::RenderTarget& rt, sf::RenderStates states) const override; Settings m_settings; float m_clock{ 0.f }; float m_total_clock{ 0.f }; float m_announceClock{ 0.f }; float m_alpha{ 0.f }; unsigned m_frame{ 0 }; std::vector> m_sprites; static float s_chaos; static sf::Vector2f s_limit; static Player* s_player; bool m_dead{ false }; sf::Sound m_sound; sf::Clock m_scale_clock; float m_m1{ -100.f }; float m_m2{ -100.f }; float m_x{ 0.f }; float m_rai[3]{ 255.f, 255.f }; int m_rdir[3]{ 0, 0 }; };