summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-26 11:37:44 +0200
committerAki <please@ignore.pl>2022-04-26 11:37:44 +0200
commit1811ec874d235d44a143c39307ac984b87fe3a8a (patch)
tree16ce52f47dd76f2d6515337571140aedf8fad8a3
parente51044a8872a05313fa92cad15eedf1f93f26aee (diff)
downloadbullethell2022-1811ec874d235d44a143c39307ac984b87fe3a8a.zip
bullethell2022-1811ec874d235d44a143c39307ac984b87fe3a8a.tar.gz
bullethell2022-1811ec874d235d44a143c39307ac984b87fe3a8a.tar.bz2
Implemented simple scoring system
-rw-r--r--Enemy.cpp7
-rw-r--r--Enemy.h1
-rw-r--r--GameScreen.cpp1
-rw-r--r--OverScreen.cpp22
-rw-r--r--OverScreen.h2
-rw-r--r--TestStage.cpp11
6 files changed, 43 insertions, 1 deletions
diff --git a/Enemy.cpp b/Enemy.cpp
index 083c890..2406394 100644
--- a/Enemy.cpp
+++ b/Enemy.cpp
@@ -51,3 +51,10 @@ Enemy::draw()
return;
DrawCircle(m_position->x, m_position->y, 6, DARKGRAY);
}
+
+
+bool
+Enemy::gone() const
+{
+ return m_position->y > 600;
+}
diff --git a/Enemy.h b/Enemy.h
index 4305026..97f3a8e 100644
--- a/Enemy.h
+++ b/Enemy.h
@@ -19,6 +19,7 @@ public:
std::shared_ptr<Behaviour> behaviour);
void update(float dt);
void draw();
+ bool gone() const;
private:
float m_hold;
std::shared_ptr<Vector2> m_position;
diff --git a/GameScreen.cpp b/GameScreen.cpp
index aeda96b..2c8dd06 100644
--- a/GameScreen.cpp
+++ b/GameScreen.cpp
@@ -28,6 +28,7 @@ void
GameScreen::update(const float dt)
{
m_stage->update(dt);
+ m_stats->points += 100 * dt;
if (m_stats->lifes < 0)
g_game.set(std::make_unique<OverScreen>(m_stats));
}
diff --git a/OverScreen.cpp b/OverScreen.cpp
index dcf5866..a465464 100644
--- a/OverScreen.cpp
+++ b/OverScreen.cpp
@@ -9,7 +9,11 @@
#include "TitleScreen.h"
-static constexpr const char* DIED {"The Bone is Gone"};
+static constexpr const char* DIED {"Game Over"};
+static constexpr const char* LABEL {"Your Score: "};
+
+
+static const char* points_text(std::shared_ptr<Stats> stats);
OverScreen::OverScreen(std::shared_ptr<Stats> stats) :
@@ -17,7 +21,12 @@ OverScreen::OverScreen(std::shared_ptr<Stats> stats) :
{
const int screen_width = GetScreenWidth();
const int died_width = MeasureText(DIED, 20);
+ const int label_width = MeasureText(LABEL, 20);
+ const int score_width = MeasureText(points_text(m_stats), 20);
+ const int label_and_score = label_width + score_width;
m_died_x = (screen_width - died_width) / 2;
+ m_label_x = (screen_width - label_and_score) / 2;
+ m_score_x = m_label_x + label_width;
m_flash.start();
}
@@ -36,5 +45,16 @@ OverScreen::draw()
{
ClearBackground(BLACK);
DrawText(DIED, m_died_x, 160, 20, RED);
+ DrawText(LABEL, m_label_x, 180, 20, GRAY);
+ DrawText(points_text(m_stats), m_score_x, 180, 20, GOLD);
m_flash.draw();
}
+
+
+const char*
+points_text(std::shared_ptr<Stats> stats)
+{
+ if (stats->lifes > 0)
+ return TextFormat("%d + %d", stats->points, 1000 * stats->lifes);
+ return TextFormat("%d", stats->points);
+}
diff --git a/OverScreen.h b/OverScreen.h
index dc7ab1a..a0a0130 100644
--- a/OverScreen.h
+++ b/OverScreen.h
@@ -16,5 +16,7 @@ public:
private:
std::shared_ptr<Stats> m_stats;
int m_died_x;
+ int m_label_x;
+ int m_score_x;
Flash m_flash;
};
diff --git a/TestStage.cpp b/TestStage.cpp
index b851b0b..19703d2 100644
--- a/TestStage.cpp
+++ b/TestStage.cpp
@@ -5,6 +5,8 @@
#include <raylib.h>
#include "EnemyFactory.h"
+#include "Globals.h"
+#include "OverScreen.h"
static constexpr Color DEEPSPACE {3, 5, 22, 255};
@@ -48,6 +50,15 @@ TestStage::update(const float dt)
m_stats->total_bullets = m_const.m_bullets.size();
if (collided) m_stats->lifes--;
}
+ bool all_done = true;
+ for (const auto& enemy : m_enemies) {
+ if (!enemy.gone()) {
+ all_done = false;
+ break;
+ }
+ }
+ if (all_done)
+ g_game.set(std::make_unique<OverScreen>(m_stats));
}