diff --git a/modes/classicmode/game/classicarrownote.cpp b/modes/classicmode/game/classicarrownote.cpp index ad43eb2..e884960 100644 --- a/modes/classicmode/game/classicarrownote.cpp +++ b/modes/classicmode/game/classicarrownote.cpp @@ -34,7 +34,8 @@ void ClassicArrowNote::putToGame(const microsec &music_offset) for (auto& element : _elements) { element.sprite = _context->graphics_manager->getSprite(element.type); - element.sprite->setCoordinates(element.coordinates, 0., 9.); + element.sprite->setCoordinates(element.coordinates); + element.sprite->setTrailCoordinates({0., 9.}); element.animations[_state]->launch(element.sprite, music_offset, offset()); } } diff --git a/modes/classicmode/game/classicdyinganimationscenario.cpp b/modes/classicmode/game/classicdyinganimationscenario.cpp index 926611c..df20f32 100644 --- a/modes/classicmode/game/classicdyinganimationscenario.cpp +++ b/modes/classicmode/game/classicdyinganimationscenario.cpp @@ -7,16 +7,31 @@ void ClassicDyingAnimationScenario::launch(const std::shared_ptr _time_begin = time_begin; _time_end = time_end; - _sprite->pulse(); + _sprite->setColor(sf::Color(140, 140, 140)); + _sprite->setTrailColor(sf::Color(0, 0, 0, 0)); + _sprite->setTrailCoordinates({0, 0}); } void ClassicDyingAnimationScenario::update(const microsec& music_offset) { (void) music_offset; - _sprite->update(); + + auto fill_color = _sprite->color(); + + if (fill_color.a == 0) + { + fill_color.a = 0; + _sprite->setColor(fill_color); + return; + } + + auto new_alpha = fill_color.a - 15; + fill_color.a = new_alpha < 0 ? 0 : new_alpha; + + _sprite->setColor(fill_color); } bool ClassicDyingAnimationScenario::isDone() const { - return _sprite->isDead(); + return _sprite->color().a == 0; } diff --git a/modes/classicmode/game/classicdyinganimationscenario.h b/modes/classicmode/game/classicdyinganimationscenario.h index 41050f4..f8ebf97 100644 --- a/modes/classicmode/game/classicdyinganimationscenario.h +++ b/modes/classicmode/game/classicdyinganimationscenario.h @@ -1,5 +1,4 @@ -#ifndef CLASSICDYINGANIMATIONSCENARIO_H -#define CLASSICDYINGANIMATIONSCENARIO_H +#pragma once #include "classicanimationscenario.h" @@ -10,5 +9,3 @@ public: virtual void update(const microsec& music_offset) override; virtual bool isDone() const override; }; - -#endif // CLASSICDYINGANIMATIONSCENARIO_H diff --git a/modes/classicmode/game/classicflyinganimationscenario.cpp b/modes/classicmode/game/classicflyinganimationscenario.cpp index afdb17c..9a97e48 100644 --- a/modes/classicmode/game/classicflyinganimationscenario.cpp +++ b/modes/classicmode/game/classicflyinganimationscenario.cpp @@ -10,7 +10,7 @@ void ClassicFlyingAnimationScenario::launch(const std::shared_ptr _percentage = ((_time_end - _time_begin) * 0.01); } -int ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const +float ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) const { float diff = n2 - n1; @@ -19,24 +19,37 @@ int ClassicFlyingAnimationScenario::getPoint(float n1, float n2, float perc) con void ClassicFlyingAnimationScenario::update(const microsec& music_offset) { - float i; const auto crd = _sprite->coordinates(); auto update_time = music_offset - _time_begin; - i = update_time / _percentage * 0.01; + float i = update_time / _percentage * 0.01; float xa = getPoint( crd.x + 20. , crd.x + 90. , i ); float ya = getPoint( crd.y - 600. , crd.y - 150. , i ); float xb = getPoint( crd.x + 90. , crd.x , i ); float yb = getPoint( crd.y - 150. , crd.y , i ); - _sprite->update(getPoint( xa , xb , i ), getPoint( ya , yb , i )); - if (i >= 1) - { - _sprite->trailFade(); - } + _sprite->setTrailCoordinates({getPoint( xa , xb , i ), getPoint( ya , yb , i )}); + + bool pastPerfectScore = (i >= 1); + + if (pastPerfectScore) + fadeTrailSprite(); } bool ClassicFlyingAnimationScenario::isDone() const { return false; } + +void ClassicFlyingAnimationScenario::fadeTrailSprite() const +{ + auto fill_color = _sprite->trailColor(); + + if (fill_color.a == 0) + return; + + auto new_alpha = fill_color.a - 35; + fill_color.a = new_alpha < 0 ? 0 : new_alpha; + + _sprite->setTrailColor(fill_color); +} diff --git a/modes/classicmode/game/classicflyinganimationscenario.h b/modes/classicmode/game/classicflyinganimationscenario.h index 7f5d79c..2438306 100644 --- a/modes/classicmode/game/classicflyinganimationscenario.h +++ b/modes/classicmode/game/classicflyinganimationscenario.h @@ -1,5 +1,4 @@ -#ifndef CLASSICFLYINGANIMATIONSCENARIO_H -#define CLASSICFLYINGANIMATIONSCENARIO_H +#pragma once #include "classicanimationscenario.h" @@ -11,9 +10,8 @@ public: virtual bool isDone() const override; private: - int getPoint(float n1, float n2, float perc) const; + float getPoint(float n1, float n2, float perc) const; + void fadeTrailSprite() const; float _percentage; }; - -#endif // CLASSICFLYINGANIMATIONSCENARIO_H diff --git a/modes/classicmode/game/classicgraphicsmanager.cpp b/modes/classicmode/game/classicgraphicsmanager.cpp index fe5e883..7b21388 100644 --- a/modes/classicmode/game/classicgraphicsmanager.cpp +++ b/modes/classicmode/game/classicgraphicsmanager.cpp @@ -4,7 +4,7 @@ ClassicGraphicsManager::ClassicGraphicsManager(sf::RenderTarget& target) : _sprite_container({Type::UP, Type::DOWN, Type::LEFT, Type::RIGHT}, - std::make_unique("VeraMono.ttf")), + std::make_unique()), _render_target(target) {} diff --git a/modes/classicmode/game/classicsprite.cpp b/modes/classicmode/game/classicsprite.cpp index 8a010da..c361bc3 100644 --- a/modes/classicmode/game/classicsprite.cpp +++ b/modes/classicmode/game/classicsprite.cpp @@ -1,39 +1,35 @@ #include "classicsprite.h" #include -ClassicSprite::ClassicSprite(const sf::RectangleShape& shape, const sf::Font& font) : +ClassicSprite::ClassicSprite(const sf::RectangleShape& shape) : _prototype(shape), _shape(shape), - _trail(shape), - _font(font) -{ - _grade_text.setFont(_font); -} + _trail(shape) +{} void ClassicSprite::draw(sf::RenderTarget& target, sf::RenderStates states) const { target.draw(_shape, states); target.draw(_trail, states); - target.draw(_grade_text, states); } void ClassicSprite::reset() { _shape.setPosition(0, 0); _trail.setPosition(0, 0); - _grade_text.setPosition(0, 0); - _grade_text.setFillColor(sf::Color(255, 255, 255, 0)); _shape = _prototype; _trail = _prototype; - _trail_fade = false; } -void ClassicSprite::setCoordinates(const Coordinates& coordinates, float trail_x, float trail_y) noexcept +void ClassicSprite::setCoordinates(const Coordinates& coordinates) { _shape.setPosition(coordinates.x, coordinates.y); - _trail.setPosition(trail_x, trail_y); - _grade_text.setPosition(coordinates.x + _shape.getSize().x/2, coordinates.y + 10); +} + +void ClassicSprite::setTrailCoordinates(const Coordinates &coordinates) +{ + _trail.setPosition(coordinates.x, coordinates.y); } Coordinates ClassicSprite::coordinates() const @@ -46,75 +42,22 @@ Coordinates ClassicSprite::trailCoordinates() const return {_trail.getPosition().x, _trail.getPosition().y}; } -void ClassicSprite::update(float trail_x, float trail_y) noexcept +void ClassicSprite::setColor(const sf::Color& color) { - _trail.setPosition(trail_x, trail_y); - - if (_trail_fade) - { - auto fill_color = _trail.getFillColor(); - - if (fill_color.a == 0) - return; - - auto new_alpha = fill_color.a - 35; - fill_color.a = new_alpha < 0 ? 0 : new_alpha; - - _trail.setFillColor(fill_color); - } + _shape.setFillColor(color); } -void ClassicSprite::update() noexcept +void ClassicSprite::setTrailColor(const sf::Color& color) { - fade(); + _trail.setFillColor(color); } -void ClassicSprite::pulse() +sf::Color ClassicSprite::color() const { - _grade_text.setFillColor(sf::Color(255, 255, 255, 255)); - _shape.setFillColor(sf::Color(140, 140, 140)); - _trail.setPosition(0, 0); - _trail.setFillColor(sf::Color(0, 0, 0, 0)); + return _shape.getFillColor(); } -void ClassicSprite::fade() +sf::Color ClassicSprite::trailColor() const { - auto fill_color = _grade_text.getFillColor(); - - if (fill_color.a <= 15) - { - fill_color.a = 0; - _grade_text.setFillColor(fill_color); - return; - } - - auto new_alpha = fill_color.a - 15; - fill_color.a = new_alpha < 0 ? 0 : new_alpha; - - _grade_text.setFillColor(fill_color); - - fill_color = _shape.getFillColor(); - - if (fill_color.a == 0) - { - fill_color.a = 0; - _shape.setFillColor(fill_color); - return; - } - - new_alpha = fill_color.a - 15; - fill_color.a = new_alpha < 0 ? 0 : new_alpha; - - _shape.setFillColor(fill_color); -} - -void ClassicSprite::trailFade() -{ - _trail_fade = true; -} - -bool ClassicSprite::isDead() const -{ - return _grade_text.getFillColor().a == 0 - || _shape.getFillColor().a == 0; + return _trail.getFillColor(); } diff --git a/modes/classicmode/game/classicsprite.h b/modes/classicmode/game/classicsprite.h index b79b2bb..3b99385 100644 --- a/modes/classicmode/game/classicsprite.h +++ b/modes/classicmode/game/classicsprite.h @@ -3,33 +3,27 @@ #include "tools/mathutils.h" #include "sprite.h" #include -#include class ClassicSprite : public Sprite, public sf::Drawable { public: - ClassicSprite(const sf::RectangleShape& shape, const sf::Font &font); + explicit ClassicSprite(const sf::RectangleShape& shape); virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override; virtual void reset() override; - void setCoordinates(const Coordinates &coordinates, float trail_x, float trail_y) noexcept; + void setCoordinates(const Coordinates &coordinates); + void setTrailCoordinates(const Coordinates &coordinates); Coordinates coordinates() const; Coordinates trailCoordinates() const; - void update(float trail_x, float trail_y) noexcept; - void update() noexcept; - void pulse(); - void fade(); - void trailFade(); - bool isDead() const; + void setColor(const sf::Color& color); + void setTrailColor(const sf::Color& color); + sf::Color color() const; + sf::Color trailColor() const; private: sf::RectangleShape _prototype; sf::RectangleShape _shape; sf::RectangleShape _trail; - sf::Text _grade_text; - sf::Font _font; - - bool _trail_fade = false; }; diff --git a/modes/classicmode/game/classicspritefactory.h b/modes/classicmode/game/classicspritefactory.h index 21ae7ba..78819e5 100644 --- a/modes/classicmode/game/classicspritefactory.h +++ b/modes/classicmode/game/classicspritefactory.h @@ -7,11 +7,6 @@ class ClassicSpriteFactory { public: - inline ClassicSpriteFactory(const std::string& font_filename) - { - _font.loadFromFile(font_filename); - } - inline std::shared_ptr create(Type type) { sf::RectangleShape sprite; @@ -38,10 +33,7 @@ public: sprite.setFillColor(sf::Color(255, 239, 0)); } - return std::make_shared(sprite, _font); + return std::make_shared(sprite); } - -private: - sf::Font _font; };