diff options
author | Aki <please@ignore.pl> | 2022-04-25 01:49:48 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2022-04-25 01:49:48 +0200 |
commit | c1c7fb82aed0c403865896a941388a9e2cc486d0 (patch) | |
tree | 7407e44a90d394bd285d5a02841188ed219a3267 /ArcGenerator.cpp | |
parent | 63c64254a80564e11987ba4af289cf8d47774668 (diff) | |
download | bullethell2022-c1c7fb82aed0c403865896a941388a9e2cc486d0.zip bullethell2022-c1c7fb82aed0c403865896a941388a9e2cc486d0.tar.gz bullethell2022-c1c7fb82aed0c403865896a941388a9e2cc486d0.tar.bz2 |
Extended test staged with new enemies
Diffstat (limited to 'ArcGenerator.cpp')
-rw-r--r-- | ArcGenerator.cpp | 54 |
1 files changed, 54 insertions, 0 deletions
diff --git a/ArcGenerator.cpp b/ArcGenerator.cpp new file mode 100644 index 0000000..0f442b5 --- /dev/null +++ b/ArcGenerator.cpp @@ -0,0 +1,54 @@ +#include "ArcGenerator.h" + +#include <cmath> +#include <memory> +#include <utility> + +#include <raylib.h> + +#include "ConstantVelocity.h" + + +ArcGenerator::ArcGenerator(std::shared_ptr<Vector2> position, ConstantVelocityBullet::Vector& bullets) : + m_position {position}, + m_bullets {bullets}, + m_delay {0}, + m_interval {0.22f}, + m_arc {2.f}, + m_angle {0}, + m_rotation {0}, + m_radius {3}, + m_last {false}, + m_speed {80}, + m_shift {10}, + m_segments {30}, + m_color {100, 100, 240, 255} +{ +} + + +void +ArcGenerator::update(const float dt) +{ + if (!m_enabled) + return; + m_delay += dt; + m_angle += m_rotation * dt; + const int segments = m_last ? m_segments + 1 : m_segments; + if (m_delay > m_interval) { + m_delay -= m_interval; + for (float i = 0; i < segments; ++i) { + const float angle = (m_angle - m_arc / 2 + m_arc * i / m_segments) * M_PI; + const float cos = std::cos(angle); + const float sin = std::sin(angle); + ConstantVelocityBullet bullet; + bullet.color = m_color; + bullet.radius = m_radius; + bullet.velocity.x = cos * m_speed; + bullet.velocity.y = sin * m_speed; + bullet.position.x = m_position->x + cos * m_shift; + bullet.position.y = m_position->y + sin * m_shift; + m_bullets.push_back(std::move(bullet)); + } + } +} |