diff options
-rw-r--r-- | SpiralGenerator.cpp | 57 | ||||
-rw-r--r-- | SpiralGenerator.h | 30 |
2 files changed, 87 insertions, 0 deletions
diff --git a/SpiralGenerator.cpp b/SpiralGenerator.cpp new file mode 100644 index 0000000..ea3268f --- /dev/null +++ b/SpiralGenerator.cpp @@ -0,0 +1,57 @@ +#include "SpiralGenerator.h" + +#include <cmath> +#include <memory> +#include <utility> + +#include <raylib.h> + +#include "Spiral.h" + + +SpiralGenerator::SpiralGenerator(std::shared_ptr<Vector2> position, SpiralBullet::Vector& bullets) : + m_position {position}, + m_bullets {bullets}, + m_delay {0}, + m_interval {0.08f}, + m_cone {0.4f}, + m_angle {1.0f}, + m_redirect {0.1f}, + float timer {0f}, + float redirect_time {1f}, + float redirect_decrease {0.2f}, + m_direction {-1.f}, + m_speed {80}, + m_shift {10}, + m_segments {1}, + m_color {240, 0, 0, 255} +{ +} + + +void +SpiralGenerator::update(const float dt) +{ + if (!m_enabled) + return; + m_delay += dt; + if (m_delay > m_interval) { + m_delay -= m_interval; + m_color.g = 0; + for (float i = 0; i <= m_segments; ++i) { + SpiralBullet bullet; + bullet.color = m_color; + bullet.radius = 3; + bullet.velocity = m_speed; + bullet.position.x = m_position->x + cos * m_shift; + bullet.position.y = m_position->y + sin * m_shift; + bullet.angle = m_angle; + bullet.redirect = m_redirect; + bullet.timer = m_timer; + bullet.redirect_time = m_redirect_time; + bullet.redirect_decrease = m_redirect_decrease; + m_bullets.push_back(std::move(bullet)); + m_color.g += 20; + } + } +} diff --git a/SpiralGenerator.h b/SpiralGenerator.h new file mode 100644 index 0000000..25fe9ba --- /dev/null +++ b/SpiralGenerator.h @@ -0,0 +1,30 @@ +#pragma once + +#include <memory> + +#include <raylib.h> + +#include "Spiral.h" +#include "Generator.h" + + +class SpiralGenerator : public Generator +{ +public: + friend class EnemyFactory; + SpiralGenerator(std::shared_ptr<Vector2> position, SpiralBullet::Vector& bullets); + void update(float dt) override; +private: + std::shared_ptr<Vector2> m_position; + SpiralBullet::Vector& m_bullets; + float m_delay; + float m_interval; + int m_speed; + float m_angle; + float m_redirect; + float m_timer; + float m_redirect_time; + float m_redirect_decrease; + int m_segments; + Color m_color; +}; |