From 162ab6e923cf0c065449cfc248102b5b92fac8a7 Mon Sep 17 00:00:00 2001 From: Aki Date: Sun, 17 Apr 2022 15:04:55 +0200 Subject: Separated bullet generator into class and created system for bullets --- ExampleGenerator.cpp | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 ExampleGenerator.cpp (limited to 'ExampleGenerator.cpp') diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp new file mode 100644 index 0000000..7f4d41b --- /dev/null +++ b/ExampleGenerator.cpp @@ -0,0 +1,47 @@ +#include "ExampleGenerator.h" + +#include +#include +#include + +#include + +#include "Bullets.h" + + +ExampleGenerator::ExampleGenerator() : + m_delay {0}, + m_interval {0.2f}, + m_cone {0.3f}, + m_speed {120}, + m_shift {10}, + m_segments {3}, + m_origin {400, 20} +{ +} + + +void +ExampleGenerator::update(const float dt, std::vector& bullets) +{ + m_delay += dt; + if (m_delay > m_interval) { + m_delay -= m_interval; + for (float i = 0; i <= m_segments; ++i) { + const float angle = ((1 - m_cone) / 2 + m_cone * i / m_segments) * M_PI; + const float cos = std::cos(angle); + const float sin = std::sin(angle); + ConstantVelocityBullet bullet; + bullet.color = RED; + bullet.radius = 4; + bullet.velocity.x = cos * m_speed; + bullet.velocity.y = sin * m_speed; + bullet.position.x = m_origin.x + cos * m_shift; + bullet.position.y = m_origin.y + sin * m_shift; + bullets.push_back(std::move(bullet)); + } + m_segments += 3; + if (m_segments > 20) + m_segments = 3; + } +} -- cgit v1.1