summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVittorio Romeo <vittorio.romeo@outlook.com>2021-11-09 14:02:45 +0000
committerVittorio Romeo <vittorio.romeo@outlook.com>2021-11-09 14:02:45 +0000
commitb71c3a7d7ebec60b8d919400ac7752f9509d9b06 (patch)
tree99944bfab3718301247b2a9070a4623ddccf3b9e
parenta0ae04f2357ed3952afe58b2d9e1b56acc275af4 (diff)
Improve swap blinking
-rw-r--r--include/SSVOpenHexagon/Components/CPlayer.hpp10
-rw-r--r--src/SSVOpenHexagon/Components/CPlayer.cpp29
2 files changed, 26 insertions, 13 deletions
diff --git a/include/SSVOpenHexagon/Components/CPlayer.hpp b/include/SSVOpenHexagon/Components/CPlayer.hpp
index e021ae0d..4e008e06 100644
--- a/include/SSVOpenHexagon/Components/CPlayer.hpp
+++ b/include/SSVOpenHexagon/Components/CPlayer.hpp
@@ -114,6 +114,9 @@ public:
void updatePosition(const float radius);
+ [[nodiscard]] sf::Color getColorAdjustedForSwap(
+ const sf::Color& colorPlayer) const;
+
void draw(const unsigned int sides, const sf::Color& colorMain,
const sf::Color& colorPlayer, Utils::FastVertexVectorQuads& wallQuads,
Utils::FastVertexVectorTris& capTris,
@@ -129,10 +132,15 @@ public:
[[nodiscard]] bool getJustSwapped() const noexcept;
- [[nodiscard]] bool isReadyToSwap() const noexcept
+ [[nodiscard, gnu::always_inline]] bool isReadyToSwap() const noexcept
{
return !_swapTimer.isRunning();
}
+
+ [[nodiscard, gnu::always_inline]] bool hasChangedAngle() const noexcept
+ {
+ return _angle != _lastAngle;
+ }
};
} // namespace hg
diff --git a/src/SSVOpenHexagon/Components/CPlayer.cpp b/src/SSVOpenHexagon/Components/CPlayer.cpp
index 20b583ec..f1222e39 100644
--- a/src/SSVOpenHexagon/Components/CPlayer.cpp
+++ b/src/SSVOpenHexagon/Components/CPlayer.cpp
@@ -19,6 +19,8 @@
#include <SFML/System/Vector2.hpp>
#include <SFML/Graphics/Color.hpp>
+#include <cmath>
+
namespace hg {
inline constexpr float baseThickness{5.f};
@@ -53,6 +55,19 @@ CPlayer::CPlayer(const sf::Vector2f& pos, const float swapCooldown,
_currTiltedAngle{0}
{}
+[[nodiscard]] sf::Color CPlayer::getColorAdjustedForSwap(
+ const sf::Color& colorPlayer) const
+{
+ if(!_swapTimer.isRunning() && !_dead)
+ {
+ return Utils::getColorFromHue(
+ std::fmod(_swapBlinkTimer.getCurrent() / 12.f, 0.2f));
+ }
+
+ return !_deadEffectTimer.isRunning() ? colorPlayer
+ : Utils::getColorFromHue(_hue / 360.f);
+}
+
void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain,
const sf::Color& colorPlayer, Utils::FastVertexVectorQuads& wallQuads,
Utils::FastVertexVectorTris& capTris,
@@ -66,10 +81,6 @@ void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain,
drawDeathEffect(wallQuads);
}
- sf::Color adjustedColorMain{!_deadEffectTimer.isRunning()
- ? colorPlayer
- : Utils::getColorFromHue(_hue / 360.f)};
-
const float tiltedAngle =
_angle + (_currTiltedAngle * ssvu::toRad(24.f) * angleTiltIntensity);
@@ -79,14 +90,8 @@ void CPlayer::draw(const unsigned int sides, const sf::Color& colorMain,
const sf::Vector2f pRight = ssvs::getOrbitRad(
_pos, tiltedAngle + ssvu::toRad(100.f), _size + _triangleWidth);
- if(!_swapTimer.isRunning() && !_dead)
- {
- adjustedColorMain = Utils::getColorFromHue(
- (_swapBlinkTimer.getCurrent() * 15.f) / 360.f);
- }
-
playerTris.reserve_more(3);
- playerTris.batch_unsafe_emplace_back(adjustedColorMain,
+ playerTris.batch_unsafe_emplace_back(getColorAdjustedForSwap(colorPlayer),
ssvs::getOrbitRad(_pos, tiltedAngle, _size), pLeft, pRight);
}
@@ -441,7 +446,7 @@ void CPlayer::update(
}
}
- _swapBlinkTimer.update(ft);
+ _swapBlinkTimer.update(ft / 3.f);
if(swapEnabled && _swapTimer.update(ft))
{