summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-18 11:35:25 +0200
committerAki <please@ignore.pl>2022-04-18 11:35:25 +0200
commit7c9c492f1555bb84a43fc68a56f69c25b54e7346 (patch)
treef7594050ed5f0f3a8f4100b9cae081ff3a73a995
parent9026eea38124b73b17f19b137dbc71eab4a7a2e9 (diff)
downloadbullethell2022-7c9c492f1555bb84a43fc68a56f69c25b54e7346.zip
bullethell2022-7c9c492f1555bb84a43fc68a56f69c25b54e7346.tar.gz
bullethell2022-7c9c492f1555bb84a43fc68a56f69c25b54e7346.tar.bz2
Separated Stage from GameScreen
-rw-r--r--CMakeLists.txt1
-rw-r--r--GameScreen.cpp24
-rw-r--r--GameScreen.h12
-rw-r--r--Stage.h10
-rw-r--r--TestStage.cpp35
-rw-r--r--TestStage.h20
-rw-r--r--TitleScreen.cpp3
7 files changed, 86 insertions, 19 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 32c3787..5b2d655 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -17,6 +17,7 @@ add_executable(
GameScreen.cpp
main.cpp
Player.cpp
+ TestStage.cpp
TitleScreen.cpp
)
target_link_libraries(${PROJECT_NAME} raylib)
diff --git a/GameScreen.cpp b/GameScreen.cpp
index 4315060..02aab00 100644
--- a/GameScreen.cpp
+++ b/GameScreen.cpp
@@ -1,11 +1,15 @@
#include "GameScreen.h"
+#include <memory>
+#include <utility>
+
#include <raylib.h>
+#include "Stage.h"
+
-GameScreen::GameScreen() :
- m_const {},
- m_generator {m_const.m_bullets}
+GameScreen::GameScreen(std::unique_ptr<Stage> stage) :
+ m_stage {std::move(stage)}
{
}
@@ -13,19 +17,17 @@ GameScreen::GameScreen() :
void
GameScreen::update(const float dt)
{
- m_player.update(dt);
- m_generator.update(dt);
- m_const.update(dt);
- bool collided = m_player.collide(m_const.m_bullets);
- (void) collided;
+ if (m_stage)
+ m_stage->update(dt);
}
void
GameScreen::draw()
{
- m_const.draw();
- m_player.draw();
+ if (m_stage) {
+ m_stage->draw();
+ DrawText(TextFormat("%d", m_stage->total_bullets()), 5, 25, 20, DARKGRAY);
+ }
DrawFPS(5, 5);
- DrawText(TextFormat("%d", m_const.m_bullets.size()), 5, 25, 20, DARKGRAY);
}
diff --git a/GameScreen.h b/GameScreen.h
index 11d5b73..5b43512 100644
--- a/GameScreen.h
+++ b/GameScreen.h
@@ -1,21 +1,19 @@
#pragma once
+#include <memory>
+
#include <raylib.h>
-#include "ConstantVelocity.h"
-#include "ExampleGenerator.h"
-#include "Player.h"
#include "Screen.h"
+#include "Stage.h"
class GameScreen : public Screen
{
public:
- GameScreen();
+ explicit GameScreen(std::unique_ptr<Stage> stage);
void update(float dt) override;
void draw() override;
private:
- Player m_player;
- ConstantVelocitySystem m_const;
- ExampleGenerator m_generator;
+ std::unique_ptr<Stage> m_stage;
};
diff --git a/Stage.h b/Stage.h
new file mode 100644
index 0000000..0a0cb46
--- /dev/null
+++ b/Stage.h
@@ -0,0 +1,10 @@
+#pragma once
+
+
+struct Stage
+{
+ virtual ~Stage() = default;
+ virtual void update(float dt) = 0;
+ virtual void draw() = 0;
+ virtual int total_bullets() const = 0;
+};
diff --git a/TestStage.cpp b/TestStage.cpp
new file mode 100644
index 0000000..b257cf6
--- /dev/null
+++ b/TestStage.cpp
@@ -0,0 +1,35 @@
+#include "TestStage.h"
+
+
+TestStage::TestStage() :
+ m_player {},
+ m_const {},
+ m_generator {m_const.m_bullets}
+{
+}
+
+
+void
+TestStage::update(const float dt)
+{
+ m_player.update(dt);
+ m_generator.update(dt);
+ m_const.update(dt);
+ bool collided = m_player.collide(m_const.m_bullets);
+ (void) collided;
+}
+
+
+void
+TestStage::draw()
+{
+ m_const.draw();
+ m_player.draw();
+}
+
+
+int
+TestStage::total_bullets() const
+{
+ return m_const.m_bullets.size();
+}
diff --git a/TestStage.h b/TestStage.h
new file mode 100644
index 0000000..10164cd
--- /dev/null
+++ b/TestStage.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "ConstantVelocity.h"
+#include "ExampleGenerator.h"
+#include "Player.h"
+#include "Stage.h"
+
+
+class TestStage : public Stage
+{
+public:
+ TestStage();
+ void update(float dt) override;
+ void draw() override;
+ int total_bullets() const override;
+private:
+ Player m_player;
+ ConstantVelocitySystem m_const;
+ ExampleGenerator m_generator;
+};
diff --git a/TitleScreen.cpp b/TitleScreen.cpp
index 3994fe9..0bf52f8 100644
--- a/TitleScreen.cpp
+++ b/TitleScreen.cpp
@@ -7,6 +7,7 @@
#include "Game.h"
#include "GameScreen.h"
#include "Globals.h"
+#include "TestStage.h"
static constexpr const char* TITLE {"Generic Bullet HELL"};
@@ -31,7 +32,7 @@ TitleScreen::update(const float dt)
if (m_blink > 2 * INTERVAL)
m_blink -= 2 * INTERVAL;
if (IsKeyPressed(KEY_SPACE))
- g_game.set(std::make_unique<GameScreen>());
+ g_game.set(std::make_unique<GameScreen>(std::make_unique<TestStage>()));
}