diff options
-rw-r--r-- | CMakeLists.txt | 1 | ||||
-rw-r--r-- | Game.h | 1 | ||||
-rw-r--r-- | GameScreen.cpp | 15 | ||||
-rw-r--r-- | GameScreen.h | 2 | ||||
-rw-r--r-- | Stage.h | 6 | ||||
-rw-r--r-- | Stats.cpp | 8 | ||||
-rw-r--r-- | Stats.h | 10 | ||||
-rw-r--r-- | TestStage.cpp | 12 | ||||
-rw-r--r-- | TestStage.h | 1 |
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 @@ -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; }; @@ -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} +{ +} @@ -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; |