summaryrefslogtreecommitdiffhomepage
path: root/SpiralGenerator.cpp
diff options
context:
space:
mode:
authorMichal <michrydz@wp.pl>2022-04-23 21:16:22 +0200
committerMichal <michrydz@wp.pl>2022-04-23 21:16:22 +0200
commit6f6b09dcf2c5306471c3febfa658bbd984664884 (patch)
treed0613d75f1b534e2cd6411556ba80e384c4510b0 /SpiralGenerator.cpp
parent22b52bffbe51ade791fa50a995e0b47a9978efed (diff)
downloadbullethell2022-6f6b09dcf2c5306471c3febfa658bbd984664884.zip
bullethell2022-6f6b09dcf2c5306471c3febfa658bbd984664884.tar.gz
bullethell2022-6f6b09dcf2c5306471c3febfa658bbd984664884.tar.bz2
Add spiral generator
Diffstat (limited to 'SpiralGenerator.cpp')
-rw-r--r--SpiralGenerator.cpp57
1 files changed, 57 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;
+ }
+ }
+}