From 5bb6b95fe71d33956491b98c29bf464a440ad221 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 22:40:41 +0200 Subject: Added toggle for base generator --- ExampleGenerator.cpp | 2 ++ Generator.cpp | 14 ++++++++++++++ Generator.h | 3 +++ 3 files changed, 19 insertions(+) diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp index dc9a6b9..5bdade8 100644 --- a/ExampleGenerator.cpp +++ b/ExampleGenerator.cpp @@ -26,6 +26,8 @@ ExampleGenerator::ExampleGenerator(ConstantVelocityBullet::Vector& bullets) : void ExampleGenerator::update(const float dt) { + if (!m_enabled) + return; m_delay += dt; if (m_delay > m_interval) { const auto pos = position(); diff --git a/Generator.cpp b/Generator.cpp index 32ad608..448872d 100644 --- a/Generator.cpp +++ b/Generator.cpp @@ -6,6 +6,20 @@ #include +Generator::Generator() : + m_enabled {true}, + m_origin {} +{ +} + + +void +Generator::toggle(const bool enabled) +{ + m_enabled = enabled; +} + + void Generator::attach(std::shared_ptr origin) { diff --git a/Generator.h b/Generator.h index 1679055..de3812a 100644 --- a/Generator.h +++ b/Generator.h @@ -8,11 +8,14 @@ class Generator { public: + Generator(); virtual ~Generator() = default; virtual void update(float dt) = 0; + void toggle(bool enabled); void attach(std::shared_ptr origin); void detach(); Vector2 position() const; protected: + bool m_enabled; std::shared_ptr m_origin; }; -- cgit v1.1