summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorAki <please@ignore.pl>2022-04-25 02:02:11 +0200
committerAki <please@ignore.pl>2022-04-25 02:02:11 +0200
commite51044a8872a05313fa92cad15eedf1f93f26aee (patch)
treeaeb0eb6866a1ee5de3088e5b1d47f227c321b1ea
parent858a17930e29e38f236e8b60d0199489f9df0a48 (diff)
downloadbullethell2022-e51044a8872a05313fa92cad15eedf1f93f26aee.zip
bullethell2022-e51044a8872a05313fa92cad15eedf1f93f26aee.tar.gz
bullethell2022-e51044a8872a05313fa92cad15eedf1f93f26aee.tar.bz2
Moved flash to own class and used it as transition to death screen
-rw-r--r--CMakeLists.txt1
-rw-r--r--Flash.cpp37
-rw-r--r--Flash.h15
-rw-r--r--OverScreen.cpp5
-rw-r--r--OverScreen.h2
-rw-r--r--TestStage.cpp9
-rw-r--r--TestStage.h3
7 files changed, 64 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index c3e431d..772f0d6 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -23,6 +23,7 @@ add_executable(
EnemyFactory.cpp
Falling.cpp
FallingAndOscillating.cpp
+ Flash.cpp
Game.cpp
GameScreen.cpp
Generator.cpp
diff --git a/Flash.cpp b/Flash.cpp
new file mode 100644
index 0000000..ba9f836
--- /dev/null
+++ b/Flash.cpp
@@ -0,0 +1,37 @@
+#include "Flash.h"
+
+#include <raylib.h>
+
+
+Flash::Flash() :
+ m_color {250, 190, 130, 255},
+ m_duration {0.23},
+ m_flash {0}
+{
+}
+
+
+void
+Flash::update(const float dt)
+{
+ if (m_flash > 0)
+ m_flash -= dt;
+}
+
+
+void
+Flash::draw()
+{
+ if (m_flash > 0) {
+ Color color = m_color;
+ color.a *= m_flash / m_duration;
+ DrawRectangle(0, 0, 800, 600, color);
+ }
+}
+
+
+void
+Flash::start()
+{
+ m_flash = m_duration;
+}
diff --git a/Flash.h b/Flash.h
new file mode 100644
index 0000000..58cd547
--- /dev/null
+++ b/Flash.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include <raylib.h>
+
+
+struct Flash
+{
+ Flash();
+ void update(float dt);
+ void draw();
+ void start();
+ Color m_color;
+ float m_duration;
+ float m_flash;
+};
diff --git a/OverScreen.cpp b/OverScreen.cpp
index 844a9dd..dcf5866 100644
--- a/OverScreen.cpp
+++ b/OverScreen.cpp
@@ -18,12 +18,14 @@ OverScreen::OverScreen(std::shared_ptr<Stats> stats) :
const int screen_width = GetScreenWidth();
const int died_width = MeasureText(DIED, 20);
m_died_x = (screen_width - died_width) / 2;
+ m_flash.start();
}
void
-OverScreen::update(const float)
+OverScreen::update(const float dt)
{
+ m_flash.update(dt);
if (IsKeyPressed(KEY_SPACE))
g_game.set(std::make_unique<TitleScreen>());
}
@@ -34,4 +36,5 @@ OverScreen::draw()
{
ClearBackground(BLACK);
DrawText(DIED, m_died_x, 160, 20, RED);
+ m_flash.draw();
}
diff --git a/OverScreen.h b/OverScreen.h
index 3dd7fa2..dc7ab1a 100644
--- a/OverScreen.h
+++ b/OverScreen.h
@@ -2,6 +2,7 @@
#include <memory>
+#include "Flash.h"
#include "Screen.h"
#include "Stats.h"
@@ -15,4 +16,5 @@ public:
private:
std::shared_ptr<Stats> m_stats;
int m_died_x;
+ Flash m_flash;
};
diff --git a/TestStage.cpp b/TestStage.cpp
index ccc1f35..b851b0b 100644
--- a/TestStage.cpp
+++ b/TestStage.cpp
@@ -8,7 +8,6 @@
static constexpr Color DEEPSPACE {3, 5, 22, 255};
-static constexpr float FLASH {0.23f};
TestStage::TestStage() :
@@ -38,14 +37,13 @@ TestStage::TestStage() :
void
TestStage::update(const float dt)
{
- if (m_flash > 0)
- m_flash -= dt;
+ m_flash.update(dt);
m_player.update(dt);
for (auto& enemy : m_enemies)
enemy.update(dt);
m_const.update(dt);
bool collided = m_player.collide(m_const.m_bullets);
- if (collided) m_flash = FLASH;
+ if (collided) m_flash.start();
if (m_stats) {
m_stats->total_bullets = m_const.m_bullets.size();
if (collided) m_stats->lifes--;
@@ -61,6 +59,5 @@ TestStage::draw()
for (auto& enemy : m_enemies)
enemy.draw();
m_player.draw();
- if (m_flash > 0)
- DrawRectangle(0, 0, 800, 600, Color{250, 190, 130, static_cast<std::uint8_t>(m_flash / FLASH * 250)});
+ m_flash.draw();
}
diff --git a/TestStage.h b/TestStage.h
index 3398a89..44a1967 100644
--- a/TestStage.h
+++ b/TestStage.h
@@ -4,6 +4,7 @@
#include "ConstantVelocity.h"
#include "Enemy.h"
+#include "Flash.h"
#include "Player.h"
#include "Stage.h"
@@ -17,5 +18,5 @@ public:
private:
ConstantVelocitySystem m_const;
std::vector<Enemy> m_enemies;
- float m_flash;
+ Flash m_flash;
};