summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-20 01:56:47 +0200
committerAki <please@ignore.pl>2022-04-20 01:56:47 +0200
commit915dd2a9acda9c505ad82bd2dd8df282670ed5fd (patch)
tree8a8312ed102d16dc4a5a371c6d6c4af93a02bcac
parent97048f6c42ebcecd765403f51811cfb212952654 (diff)
downloadbullethell2022-915dd2a9acda9c505ad82bd2dd8df282670ed5fd.zip
bullethell2022-915dd2a9acda9c505ad82bd2dd8df282670ed5fd.tar.gz
bullethell2022-915dd2a9acda9c505ad82bd2dd8df282670ed5fd.tar.bz2
Added another generator and enemy for testing purposes
-rw-r--r--CMakeLists.txt1
-rw-r--r--EnemyFactory.cpp17
-rw-r--r--EnemyFactory.h1
-rw-r--r--TestStage.cpp2
-rw-r--r--WaveGenerator.cpp47
-rw-r--r--WaveGenerator.h26
6 files changed, 92 insertions, 2 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index f4c3228..f47ec87 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -28,5 +28,6 @@ add_executable(
Player.cpp
TestStage.cpp
TitleScreen.cpp
+ WaveGenerator.cpp
)
target_link_libraries(${PROJECT_NAME} raylib)
diff --git a/EnemyFactory.cpp b/EnemyFactory.cpp
index 8a51c3f..a154ae5 100644
--- a/EnemyFactory.cpp
+++ b/EnemyFactory.cpp
@@ -8,6 +8,7 @@
#include "Enemy.h"
#include "ExampleGenerator.h"
#include "FallingAndOscillating.h"
+#include "WaveGenerator.h"
Enemy
@@ -20,7 +21,6 @@ EnemyFactory::make_example(
auto position = std::make_shared<Vector2>(Vector2{x, y});
auto generator = std::make_shared<ExampleGenerator>(position, bullets);
auto behaviour = std::make_shared<FallingAndOscillating>(position, generator);
- generator->m_position = position;
if (mirror) {
generator->m_color = Color{100, 0, 255, 255};
generator->m_direction *= -1;
@@ -30,3 +30,18 @@ EnemyFactory::make_example(
enemy.m_hold = hold;
return enemy;
}
+
+
+Enemy
+EnemyFactory::make_waver(
+ ConstantVelocityBullet::Vector& bullets,
+ const float x, const float y,
+ const float hold)
+{
+ auto position = std::make_shared<Vector2>(Vector2{x, y});
+ auto generator = std::make_shared<WaveGenerator>(position, bullets);
+ auto behaviour = std::make_shared<Falling>(position, generator);
+ Enemy enemy(position, generator, behaviour);
+ enemy.m_hold = hold;
+ return enemy;
+}
diff --git a/EnemyFactory.h b/EnemyFactory.h
index 0475a25..6134ae9 100644
--- a/EnemyFactory.h
+++ b/EnemyFactory.h
@@ -7,4 +7,5 @@
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);
};
diff --git a/TestStage.cpp b/TestStage.cpp
index 00c27e1..fdd833d 100644
--- a/TestStage.cpp
+++ b/TestStage.cpp
@@ -10,7 +10,7 @@ TestStage::TestStage() :
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_example(m_const.m_bullets, 400, -10, 10));
+ 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));
}
diff --git a/WaveGenerator.cpp b/WaveGenerator.cpp
new file mode 100644
index 0000000..5d8dd9f
--- /dev/null
+++ b/WaveGenerator.cpp
@@ -0,0 +1,47 @@
+#include "WaveGenerator.h"
+
+#include <cmath>
+#include <memory>
+#include <utility>
+
+#include <raylib.h>
+
+#include "ConstantVelocity.h"
+
+
+WaveGenerator::WaveGenerator(std::shared_ptr<Vector2> 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
new file mode 100644
index 0000000..c3d52f5
--- /dev/null
+++ b/WaveGenerator.h
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <memory>
+
+#include <raylib.h>
+
+#include "ConstantVelocity.h"
+#include "Generator.h"
+
+
+class WaveGenerator : public Generator
+{
+public:
+ friend class EnemyFactory;
+ WaveGenerator(std::shared_ptr<Vector2> position, ConstantVelocityBullet::Vector& bullets);
+ void update(float dt) override;
+private:
+ std::shared_ptr<Vector2> m_position;
+ ConstantVelocityBullet::Vector& m_bullets;
+ float m_delay;
+ float m_interval;
+ int m_speed;
+ int m_shift;
+ int m_segments;
+ Color m_color;
+};