summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-18 10:36:19 +0200
committerAki <please@ignore.pl>2022-04-18 10:36:19 +0200
commit7e1081ff8f1297486e177bd716fecebb42c0182a (patch)
tree031f47bce6b1ecab5303139cb425ebf6ed5709d4
parent8209bbaf2a046199b9c65438fb4454ce01b42500 (diff)
downloadbullethell2022-7e1081ff8f1297486e177bd716fecebb42c0182a.zip
bullethell2022-7e1081ff8f1297486e177bd716fecebb42c0182a.tar.gz
bullethell2022-7e1081ff8f1297486e177bd716fecebb42c0182a.tar.bz2
Added base class for generators
-rw-r--r--Bullets.h1
-rw-r--r--ExampleGenerator.cpp8
-rw-r--r--ExampleGenerator.h10
-rw-r--r--GameScreen.cpp5
-rw-r--r--GameScreen.h2
-rw-r--r--Generator.h8
6 files changed, 22 insertions, 12 deletions
diff --git a/Bullets.h b/Bullets.h
index 4a77100..3970aff 100644
--- a/Bullets.h
+++ b/Bullets.h
@@ -23,6 +23,7 @@ struct ConstantVelocitySystem
struct ConstantVelocityBullet
{
+ using Vector = std::vector<ConstantVelocityBullet>;
Vector2 position;
Vector2 velocity;
float radius;
diff --git a/ExampleGenerator.cpp b/ExampleGenerator.cpp
index 7f4d41b..bcead95 100644
--- a/ExampleGenerator.cpp
+++ b/ExampleGenerator.cpp
@@ -1,7 +1,6 @@
#include "ExampleGenerator.h"
#include <cmath>
-#include <vector>
#include <utility>
#include <raylib.h>
@@ -9,7 +8,8 @@
#include "Bullets.h"
-ExampleGenerator::ExampleGenerator() :
+ExampleGenerator::ExampleGenerator(ConstantVelocityBullet::Vector& bullets) :
+ m_bullets {bullets},
m_delay {0},
m_interval {0.2f},
m_cone {0.3f},
@@ -22,7 +22,7 @@ ExampleGenerator::ExampleGenerator() :
void
-ExampleGenerator::update(const float dt, std::vector<ConstantVelocityBullet>& bullets)
+ExampleGenerator::update(const float dt)
{
m_delay += dt;
if (m_delay > m_interval) {
@@ -38,7 +38,7 @@ ExampleGenerator::update(const float dt, std::vector<ConstantVelocityBullet>& bu
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_bullets.push_back(std::move(bullet));
}
m_segments += 3;
if (m_segments > 20)
diff --git a/ExampleGenerator.h b/ExampleGenerator.h
index 0e3372b..25c4ce3 100644
--- a/ExampleGenerator.h
+++ b/ExampleGenerator.h
@@ -1,16 +1,16 @@
#pragma once
-#include <vector>
-
#include <raylib.h>
#include "Bullets.h"
+#include "Generator.h"
-struct ExampleGenerator
+struct ExampleGenerator : public Generator
{
- ExampleGenerator();
- void update(float dt, std::vector<ConstantVelocityBullet>& bullets);
+ explicit ExampleGenerator(ConstantVelocityBullet::Vector& bullets);
+ void update(float dt) override;
+ ConstantVelocityBullet::Vector& m_bullets;
float m_delay;
float m_interval;
float m_cone;
diff --git a/GameScreen.cpp b/GameScreen.cpp
index 4a2fc22..774956e 100644
--- a/GameScreen.cpp
+++ b/GameScreen.cpp
@@ -4,7 +4,8 @@
GameScreen::GameScreen() :
- m_const {}
+ m_const {},
+ m_generator {m_const.m_bullets}
{
}
@@ -13,7 +14,7 @@ void
GameScreen::update(const float dt)
{
m_player.update(dt);
- m_generator.update(dt, m_const.m_bullets);
+ m_generator.update(dt);
m_const.update(dt);
bool collided = false;
for (const auto& bullet : m_const.m_bullets) {
diff --git a/GameScreen.h b/GameScreen.h
index 2b5152f..144bd82 100644
--- a/GameScreen.h
+++ b/GameScreen.h
@@ -16,6 +16,6 @@ public:
void draw() override;
private:
Player m_player;
- ExampleGenerator m_generator;
ConstantVelocitySystem m_const;
+ ExampleGenerator m_generator;
};
diff --git a/Generator.h b/Generator.h
new file mode 100644
index 0000000..5beef2c
--- /dev/null
+++ b/Generator.h
@@ -0,0 +1,8 @@
+#pragma once
+
+
+struct Generator
+{
+ virtual ~Generator() = default;
+ virtual void update(float dt) = 0;
+};