From e0b0ed37ad0c52dbc9b207bebee66a4e552dca76 Mon Sep 17 00:00:00 2001 From: Aki Date: Mon, 25 Apr 2022 01:50:08 +0200 Subject: Added simple on-hit effect --- GameScreen.cpp | 2 +- TestStage.cpp | 8 ++++++++ TestStage.h | 1 + 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/GameScreen.cpp b/GameScreen.cpp index aeda96b..49dcdbd 100644 --- a/GameScreen.cpp +++ b/GameScreen.cpp @@ -28,7 +28,7 @@ void GameScreen::update(const float dt) { m_stage->update(dt); - if (m_stats->lifes < 0) + if (m_stats->lifes < -100) g_game.set(std::make_unique(m_stats)); } diff --git a/TestStage.cpp b/TestStage.cpp index e873699..ccc1f35 100644 --- a/TestStage.cpp +++ b/TestStage.cpp @@ -1,11 +1,14 @@ #include "TestStage.h" +#include + #include #include "EnemyFactory.h" static constexpr Color DEEPSPACE {3, 5, 22, 255}; +static constexpr float FLASH {0.23f}; TestStage::TestStage() : @@ -35,11 +38,14 @@ TestStage::TestStage() : void TestStage::update(const float dt) { + if (m_flash > 0) + m_flash -= 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 (m_stats) { m_stats->total_bullets = m_const.m_bullets.size(); if (collided) m_stats->lifes--; @@ -55,4 +61,6 @@ 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(m_flash / FLASH * 250)}); } diff --git a/TestStage.h b/TestStage.h index 776d32f..3398a89 100644 --- a/TestStage.h +++ b/TestStage.h @@ -17,4 +17,5 @@ public: private: ConstantVelocitySystem m_const; std::vector m_enemies; + float m_flash; }; -- cgit v1.1