From c1c7fb82aed0c403865896a941388a9e2cc486d0 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 25 Apr 2022 01:49:48 +0200 Subject: Extended test staged with new enemies --- ArcGenerator.cpp | 54 ++++++++++++++++++++++++++++++++++++++++++++ ArcGenerator.h | 31 +++++++++++++++++++++++++ CMakeLists.txt | 3 +-- EnemyFactory.cpp | 64 +++++++++++++++++++++++++++++++++++++++++++++------- EnemyFactory.h | 5 ++-- ExampleGenerator.cpp | 55 -------------------------------------------- ExampleGenerator.h | 29 ------------------------ Falling.h | 1 + TestStage.cpp | 24 +++++++++++++++----- WaveGenerator.cpp | 47 -------------------------------------- WaveGenerator.h | 26 --------------------- 11 files changed, 164 insertions(+), 175 deletions(-) create mode 100644 ArcGenerator.cpp create mode 100644 ArcGenerator.h delete mode 100644 ExampleGenerator.cpp delete mode 100644 ExampleGenerator.h delete mode 100644 WaveGenerator.cpp delete mode 100644 WaveGenerator.h 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 +#include +#include + +#include + +#include "ConstantVelocity.h" + + +ArcGenerator::ArcGenerator(std::shared_ptr 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)); + } + } +} diff --git a/ArcGenerator.h b/ArcGenerator.h new file mode 100644 index 0000000..ae02040 --- /dev/null +++ b/ArcGenerator.h @@ -0,0 +1,31 @@ +#pragma once + +#include + +#include + +#include "ConstantVelocity.h" +#include "Generator.h" + + +class ArcGenerator : public Generator +{ +public: + friend class EnemyFactory; + ArcGenerator(std::shared_ptr position, ConstantVelocityBullet::Vector& bullets); + void update(float dt) override; +private: + std::shared_ptr m_position; + ConstantVelocityBullet::Vector& m_bullets; + float m_delay; + float m_interval; + float m_arc; + float m_angle; + float m_rotation; + float m_radius; + bool m_last; + int m_speed; + int m_shift; + int m_segments; + Color m_color; +}; diff --git a/CMakeLists.txt b/CMakeLists.txt index e3e9cea..c3e431d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -17,10 +17,10 @@ endif() find_package(raylib 3 REQUIRED) add_executable( ${PROJECT_NAME} + ArcGenerator.cpp ConstantVelocity.cpp Enemy.cpp EnemyFactory.cpp - ExampleGenerator.cpp Falling.cpp FallingAndOscillating.cpp Game.cpp @@ -34,7 +34,6 @@ add_executable( Stats.cpp TestStage.cpp TitleScreen.cpp - WaveGenerator.cpp ) target_link_libraries(${PROJECT_NAME} raylib) if(MSVC) diff --git a/EnemyFactory.cpp b/EnemyFactory.cpp index a154ae5..fc94cd5 100644 --- a/EnemyFactory.cpp +++ b/EnemyFactory.cpp @@ -4,28 +4,35 @@ #include +#include "ArcGenerator.h" #include "ConstantVelocity.h" #include "Enemy.h" -#include "ExampleGenerator.h" #include "FallingAndOscillating.h" -#include "WaveGenerator.h" Enemy -EnemyFactory::make_example( +EnemyFactory::make_small( ConstantVelocityBullet::Vector& bullets, const float x, const float y, const float hold, const bool mirror) { auto position = std::make_shared(Vector2{x, y}); - auto generator = std::make_shared(position, bullets); + auto generator = std::make_shared(position, bullets); auto behaviour = std::make_shared(position, generator); + generator->m_interval = 1.2f; + generator->m_speed = 60; + generator->m_segments = 15; + generator->m_radius = 5; if (mirror) { generator->m_color = Color{100, 0, 255, 255}; - generator->m_direction *= -1; + generator->m_rotation = -0.2f; + generator->m_angle = 1.f; behaviour->m_phase = 1.f; } + else { + generator->m_rotation = 0.2f; + } Enemy enemy(position, generator, behaviour); enemy.m_hold = hold; return enemy; @@ -33,14 +40,55 @@ EnemyFactory::make_example( Enemy -EnemyFactory::make_waver( +EnemyFactory::make_thick( ConstantVelocityBullet::Vector& bullets, const float x, const float y, - const float hold) + const float hold, + const float angle) { auto position = std::make_shared(Vector2{x, y}); - auto generator = std::make_shared(position, bullets); + auto generator = std::make_shared(position, bullets); auto behaviour = std::make_shared(position, generator); + generator->m_interval = 2.3f; + generator->m_arc = 0.3f; + generator->m_angle = 0.5f; + generator->m_last = true; + generator->m_segments = 25; + generator->m_radius = 9; + generator->m_color = Color{160, 30, 50, 200}; + generator->m_angle = angle; + behaviour->m_speed = 20; + Enemy enemy(position, generator, behaviour); + enemy.m_hold = hold; + return enemy; +} + + +Enemy +EnemyFactory::make_rotator( + ConstantVelocityBullet::Vector& bullets, + const float x, const float y, + const float hold, + const bool mirror) +{ + auto position = std::make_shared(Vector2{x, y}); + auto generator = std::make_shared(position, bullets); + auto behaviour = std::make_shared(position, generator); + generator->m_interval = 0.4f; + generator->m_speed = 100; + generator->m_arc = 0.1f; + generator->m_segments = 2; + generator->m_last = true; + generator->m_radius = 4; + if (mirror) { + generator->m_color = Color{30, 80, 170, 255}; + generator->m_rotation = -0.6f; + generator->m_angle = 1.f; + } + else { + generator->m_color = Color{30, 170, 80, 255}; + generator->m_rotation = 0.6f; + } Enemy enemy(position, generator, behaviour); enemy.m_hold = hold; return enemy; diff --git a/EnemyFactory.h b/EnemyFactory.h index 6134ae9..934b0ea 100644 --- a/EnemyFactory.h +++ b/EnemyFactory.h @@ -6,6 +6,7 @@ struct EnemyFactory { - static Enemy make_example(ConstantVelocityBullet::Vector& bullets, float x, float y, float hold, bool mirror=false); - static Enemy make_waver(ConstantVelocityBullet::Vector& bullets, float x, float y, float hold); + static Enemy make_small(ConstantVelocityBullet::Vector& bullets, float x, float y, float hold, bool mirror=false); + static Enemy make_thick(ConstantVelocityBullet::Vector& bullets, float x, float y, float hold, float angle=0.5f); + static Enemy make_rotator(ConstantVelocityBullet::Vector& bullets, float x, float y, float hold, bool mirror=false); }; diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp deleted file mode 100644 index f405f58..0000000 --- a/ExampleGenerator.cpp +++ /dev/null @@ -1,55 +0,0 @@ -#include "ExampleGenerator.h" - -#include -#include -#include - -#include - -#include "ConstantVelocity.h" - - -ExampleGenerator::ExampleGenerator(std::shared_ptr position, ConstantVelocityBullet::Vector& bullets) : - m_position {position}, - m_bullets {bullets}, - m_delay {0}, - m_interval {0.08f}, - m_cone {0.4f}, - m_angle {0.5f}, - m_direction {-1.f}, - m_speed {80}, - m_shift {10}, - m_segments {6}, - m_color {240, 0, 0, 255} -{ -} - - -void -ExampleGenerator::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) { - 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 = 3; - 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)); - m_color.g += 20; - } - } - m_angle += dt * 0.3f * m_direction; - if (m_angle > 2.f) - m_angle -= 2.f; -} diff --git a/ExampleGenerator.h b/ExampleGenerator.h deleted file mode 100644 index 6db4151..0000000 --- a/ExampleGenerator.h +++ /dev/null @@ -1,29 +0,0 @@ -#pragma once - -#include - -#include - -#include "ConstantVelocity.h" -#include "Generator.h" - - -class ExampleGenerator : public Generator -{ -public: - friend class EnemyFactory; - ExampleGenerator(std::shared_ptr position, ConstantVelocityBullet::Vector& bullets); - void update(float dt) override; -private: - std::shared_ptr m_position; - ConstantVelocityBullet::Vector& m_bullets; - float m_delay; - float m_interval; - float m_cone; - float m_angle; - float m_direction; - int m_speed; - int m_shift; - int m_segments; - Color m_color; -}; diff --git a/Falling.h b/Falling.h index b50228a..fa4f4fc 100644 --- a/Falling.h +++ b/Falling.h @@ -11,6 +11,7 @@ class Falling : virtual public Behaviour { public: + friend class EnemyFactory; Falling(std::shared_ptr position, std::shared_ptr generator); void update(float dt) override; private: diff --git a/TestStage.cpp b/TestStage.cpp index 4aa1767..e873699 100644 --- a/TestStage.cpp +++ b/TestStage.cpp @@ -11,12 +11,24 @@ static constexpr Color DEEPSPACE {3, 5, 22, 255}; TestStage::TestStage() : m_const {} { - m_enemies.reserve(5); - m_enemies.push_back(EnemyFactory::make_example(m_const.m_bullets, 300, -10, 0)); - m_enemies.push_back(EnemyFactory::make_example(m_const.m_bullets, 500, -10, 0, true)); - m_enemies.push_back(EnemyFactory::make_waver(m_const.m_bullets, 400, -10, 10)); - m_enemies.push_back(EnemyFactory::make_example(m_const.m_bullets, 550, -10, 20)); - m_enemies.push_back(EnemyFactory::make_example(m_const.m_bullets, 250, -10, 20, true)); + m_enemies.reserve(17); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 300, -10, 0)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 500, -10, 0, true)); + m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 400, -10, 10)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 550, -10, 20)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 250, -10, 20, true)); + m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 200, -20, 26, -0.2)); + m_enemies.push_back(EnemyFactory::make_thick(m_const.m_bullets, 600, -10, 26, 0.7)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 400, -10, 32)); + m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 260, -10, 44)); + m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 540, -10, 44, true)); + m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 300, -10, 49, true)); + m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 500, -10, 50)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 360, -10, 56)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 440, -10, 56, true)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 365, -10, 62, true)); + m_enemies.push_back(EnemyFactory::make_small(m_const.m_bullets, 435, -10, 62)); + m_enemies.push_back(EnemyFactory::make_rotator(m_const.m_bullets, 400, -10, 66)); } diff --git a/WaveGenerator.cpp b/WaveGenerator.cpp deleted file mode 100644 index 5d8dd9f..0000000 --- a/WaveGenerator.cpp +++ /dev/null @@ -1,47 +0,0 @@ -#include "WaveGenerator.h" - -#include -#include -#include - -#include - -#include "ConstantVelocity.h" - - -WaveGenerator::WaveGenerator(std::shared_ptr position, ConstantVelocityBullet::Vector& bullets) : - m_position {position}, - m_bullets {bullets}, - m_delay {0}, - m_interval {0.22f}, - m_speed {100}, - m_shift {10}, - m_segments {30}, - m_color {100, 100, 240, 255} -{ -} - - -void -WaveGenerator::update(const float dt) -{ - if (!m_enabled) - return; - m_delay += dt; - if (m_delay > m_interval) { - m_delay -= m_interval; - for (float i = 0; i < m_segments; ++i) { - const float angle = (2.f / m_segments * i) * M_PI; - const float cos = std::cos(angle); - const float sin = std::sin(angle); - ConstantVelocityBullet bullet; - bullet.color = m_color; - bullet.radius = 3; - 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)); - } - } -} diff --git a/WaveGenerator.h b/WaveGenerator.h deleted file mode 100644 index c3d52f5..0000000 --- a/WaveGenerator.h +++ /dev/null @@ -1,26 +0,0 @@ -#pragma once - -#include - -#include - -#include "ConstantVelocity.h" -#include "Generator.h" - - -class WaveGenerator : public Generator -{ -public: - friend class EnemyFactory; - WaveGenerator(std::shared_ptr position, ConstantVelocityBullet::Vector& bullets); - void update(float dt) override; -private: - std::shared_ptr m_position; - ConstantVelocityBullet::Vector& m_bullets; - float m_delay; - float m_interval; - int m_speed; - int m_shift; - int m_segments; - Color m_color; -}; -- cgit v1.1