summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-22 01:11:24 +0200
committerAki <please@ignore.pl>2022-04-22 01:11:24 +0200
commit804e71083e4df85c4f0692553de3084f0ed4cd9a (patch)
tree6cfdf65ee7de9c14984677ca4a607b27d9080e00
parent7b8e199b0b6cccdf022bcd072bcdd8ab6c4072b1 (diff)
downloadbullethell2022-804e71083e4df85c4f0692553de3084f0ed4cd9a.zip
bullethell2022-804e71083e4df85c4f0692553de3084f0ed4cd9a.tar.gz
bullethell2022-804e71083e4df85c4f0692553de3084f0ed4cd9a.tar.bz2
Added Stats for lifes points and other kind of gameplay state
-rw-r--r--CMakeLists.txt1
-rw-r--r--Game.h1
-rw-r--r--GameScreen.cpp15
-rw-r--r--GameScreen.h2
-rw-r--r--Stage.h6
-rw-r--r--Stats.cpp8
-rw-r--r--Stats.h10
-rw-r--r--TestStage.cpp12
-rw-r--r--TestStage.h1
9 files changed, 38 insertions, 18 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 42eccd4..176b3f8 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -30,6 +30,7 @@ add_executable(
main.cpp
Oscillating.cpp
Player.cpp
+ Stats.cpp
TestStage.cpp
TitleScreen.cpp
WaveGenerator.cpp
diff --git a/Game.h b/Game.h
index b047336..702ed17 100644
--- a/Game.h
+++ b/Game.h
@@ -11,7 +11,6 @@ public:
void set(std::unique_ptr<Screen> screen);
void update(float dt);
void draw();
-
private:
std::unique_ptr<Screen> m_screen;
};
diff --git a/GameScreen.cpp b/GameScreen.cpp
index 02aab00..f813a60 100644
--- a/GameScreen.cpp
+++ b/GameScreen.cpp
@@ -9,25 +9,26 @@
GameScreen::GameScreen(std::unique_ptr<Stage> stage) :
- m_stage {std::move(stage)}
+ m_stage {std::move(stage)},
+ m_stats {std::make_shared<Stats>()}
{
+ m_stage->m_stats = m_stats;
}
void
GameScreen::update(const float dt)
{
- if (m_stage)
- m_stage->update(dt);
+ m_stage->update(dt);
}
void
GameScreen::draw()
{
- if (m_stage) {
- m_stage->draw();
- DrawText(TextFormat("%d", m_stage->total_bullets()), 5, 25, 20, DARKGRAY);
- }
+ m_stage->draw();
+ DrawText(TextFormat("%d", m_stats->total_bullets), 5, 25, 20, DARKGRAY);
+ DrawText(TextFormat("%d", m_stats->lifes), 5, 45, 20, DARKGREEN);
+ DrawText(TextFormat("%d", m_stats->points), 5, 65, 20, GOLD);
DrawFPS(5, 5);
}
diff --git a/GameScreen.h b/GameScreen.h
index 5b43512..dd0a615 100644
--- a/GameScreen.h
+++ b/GameScreen.h
@@ -6,6 +6,7 @@
#include "Screen.h"
#include "Stage.h"
+#include "Stats.h"
class GameScreen : public Screen
@@ -16,4 +17,5 @@ public:
void draw() override;
private:
std::unique_ptr<Stage> m_stage;
+ std::shared_ptr<Stats> m_stats;
};
diff --git a/Stage.h b/Stage.h
index 0a0cb46..fcb69b3 100644
--- a/Stage.h
+++ b/Stage.h
@@ -1,10 +1,14 @@
#pragma once
+#include <memory>
+
+#include "Stats.h"
+
struct Stage
{
virtual ~Stage() = default;
virtual void update(float dt) = 0;
virtual void draw() = 0;
- virtual int total_bullets() const = 0;
+ std::shared_ptr<Stats> m_stats;
};
diff --git a/Stats.cpp b/Stats.cpp
new file mode 100644
index 0000000..dd2e581
--- /dev/null
+++ b/Stats.cpp
@@ -0,0 +1,8 @@
+#include "Stats.h"
+
+
+Stats::Stats() :
+ lifes {3},
+ points {0}
+{
+}
diff --git a/Stats.h b/Stats.h
new file mode 100644
index 0000000..ea46681
--- /dev/null
+++ b/Stats.h
@@ -0,0 +1,10 @@
+#pragma once
+
+
+struct Stats
+{
+ Stats();
+ int lifes;
+ int points;
+ int total_bullets;
+};
diff --git a/TestStage.cpp b/TestStage.cpp
index fdd833d..e6ff74a 100644
--- a/TestStage.cpp
+++ b/TestStage.cpp
@@ -24,7 +24,10 @@ TestStage::update(const float dt)
enemy.update(dt);
m_const.update(dt);
bool collided = m_player.collide(m_const.m_bullets);
- (void) collided;
+ if (m_stats) {
+ m_stats->total_bullets = m_const.m_bullets.size();
+ if (collided) m_stats->lifes--;
+ }
}
@@ -36,10 +39,3 @@ TestStage::draw()
enemy.draw();
m_player.draw();
}
-
-
-int
-TestStage::total_bullets() const
-{
- return m_const.m_bullets.size();
-}
diff --git a/TestStage.h b/TestStage.h
index 0e90ab6..7ddbe06 100644
--- a/TestStage.h
+++ b/TestStage.h
@@ -14,7 +14,6 @@ public:
TestStage();
void update(float dt) override;
void draw() override;
- int total_bullets() const override;
private:
Player m_player;
ConstantVelocitySystem m_const;