From 9dc6e5dcc108cd887891756a54748aab62f19626 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 18 Apr 2022 22:27:08 +0200 Subject: Fiddled with enemy building and test generator --- ExampleGenerator.cpp | 24 +++++++++++------------- ExampleGenerator.h | 1 + TestStage.cpp | 9 ++++++--- 3 files changed, 18 insertions(+), 16 deletions(-) diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp index 76c4cb7..dc9a6b9 100644 --- a/ExampleGenerator.cpp +++ b/ExampleGenerator.cpp @@ -11,12 +11,13 @@ ExampleGenerator::ExampleGenerator(ConstantVelocityBullet::Vector& bullets) : m_bullets {bullets}, m_delay {0}, - m_interval {0.05f}, + m_interval {0.08f}, m_cone {0.4f}, - m_angle {0.3f}, - m_speed {70}, + m_angle {0.5f}, + m_direction {-1.f}, + m_speed {80}, m_shift {10}, - m_segments {3}, + m_segments {6}, m_color {240, 0, 0, 255} { } @@ -29,26 +30,23 @@ ExampleGenerator::update(const float dt) if (m_delay > m_interval) { const auto pos = position(); m_delay -= m_interval; + m_color.g = 0; for (float i = 0; i <= m_segments; ++i) { const float angle = (m_angle - 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 = m_color; - bullet.radius = 4; + bullet.radius = 3; bullet.velocity.x = cos * m_speed; bullet.velocity.y = sin * m_speed; bullet.position.x = pos.x + cos * m_shift; bullet.position.y = pos.y + sin * m_shift; m_bullets.push_back(std::move(bullet)); + m_color.g += 20; } } - m_angle += dt * 0.5f; - if (m_angle >= 0.7f) { - m_angle -= 0.4f; - if (m_color.g == 0) - m_color.g = 120; - else - m_color.g = 0; - } + m_angle += dt * 0.3f * m_direction; + if (m_angle > 2.f) + m_angle -= 2.f; } diff --git a/ExampleGenerator.h b/ExampleGenerator.h index c74ccfd..2710d03 100644 --- a/ExampleGenerator.h +++ b/ExampleGenerator.h @@ -15,6 +15,7 @@ struct ExampleGenerator : public Generator float m_interval; float m_cone; float m_angle; + float m_direction; int m_speed; int m_shift; int m_segments; diff --git a/TestStage.cpp b/TestStage.cpp index 653d3c2..2ce4118 100644 --- a/TestStage.cpp +++ b/TestStage.cpp @@ -11,9 +11,12 @@ TestStage::TestStage() : m_const {} { m_enemies.reserve(2); - for (const float x : {200.f, 600.f}) { - Enemy enemy(std::make_unique(m_const.m_bullets)); - enemy.set_position(x, 20.f); + for (const float x : {300.f, 500.f}) { + auto generator = std::make_unique(m_const.m_bullets); + if (x > 400.f) + generator->m_direction *= -1; + Enemy enemy(std::move(generator)); + enemy.set_position(x, 100.f); m_enemies.push_back(std::move(enemy)); } } -- cgit v1.1