2021-06-09 14:08:58 -04:00
|
|
|
#include "classicsprite.h"
|
|
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
|
|
|
|
2021-06-11 13:39:47 -04:00
|
|
|
ClassicSprite::ClassicSprite(const sf::RectangleShape& shape, const sf::Font& font) :
|
2021-06-16 13:11:00 -04:00
|
|
|
_prototype(shape),
|
2021-06-11 12:58:44 -04:00
|
|
|
_shape(shape),
|
2021-06-11 13:39:47 -04:00
|
|
|
_trail(shape),
|
|
|
|
_font(font)
|
|
|
|
{
|
|
|
|
_grade_text.setFont(_font);
|
|
|
|
}
|
2021-06-09 14:08:58 -04:00
|
|
|
|
|
|
|
void ClassicSprite::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
|
|
{
|
|
|
|
target.draw(_shape, states);
|
2021-06-11 12:58:44 -04:00
|
|
|
target.draw(_trail, states);
|
2021-06-11 13:39:47 -04:00
|
|
|
target.draw(_grade_text, states);
|
2021-06-09 14:08:58 -04:00
|
|
|
}
|
|
|
|
|
2021-06-16 11:16:18 -04:00
|
|
|
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));
|
2021-06-16 13:11:00 -04:00
|
|
|
|
|
|
|
_shape = _prototype;
|
|
|
|
_trail = _prototype;
|
2021-06-17 15:13:25 -04:00
|
|
|
_trail_fade = false;
|
2021-06-16 11:16:18 -04:00
|
|
|
}
|
|
|
|
|
2021-06-24 14:04:09 -04:00
|
|
|
void ClassicSprite::setCoordinates(const Coordinates& coordinates, float trail_x, float trail_y) noexcept
|
2021-06-09 14:08:58 -04:00
|
|
|
{
|
2021-06-24 14:04:09 -04:00
|
|
|
_shape.setPosition(coordinates.x, coordinates.y);
|
2021-06-11 12:58:44 -04:00
|
|
|
_trail.setPosition(trail_x, trail_y);
|
2021-06-24 14:04:09 -04:00
|
|
|
_grade_text.setPosition(coordinates.x + _shape.getSize().x/2, coordinates.y + 10);
|
2021-06-11 12:58:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-24 14:04:09 -04:00
|
|
|
Coordinates ClassicSprite::coordinates() const
|
2021-06-23 18:43:13 -04:00
|
|
|
{
|
2021-06-24 14:04:09 -04:00
|
|
|
return {_shape.getPosition().x, _shape.getPosition().y};
|
2021-06-23 18:43:13 -04:00
|
|
|
}
|
|
|
|
|
2021-07-14 22:45:52 -04:00
|
|
|
Coordinates ClassicSprite::trailCoordinates() const
|
|
|
|
{
|
|
|
|
return {_trail.getPosition().x, _trail.getPosition().y};
|
|
|
|
}
|
|
|
|
|
2021-06-11 13:39:47 -04:00
|
|
|
void ClassicSprite::update(float trail_x, float trail_y) noexcept
|
2021-06-11 12:58:44 -04:00
|
|
|
{
|
|
|
|
_trail.setPosition(trail_x, trail_y);
|
2021-06-17 15:13:25 -04:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
2021-06-16 11:16:18 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicSprite::update() noexcept
|
|
|
|
{
|
2021-06-11 13:39:47 -04:00
|
|
|
fade();
|
|
|
|
}
|
|
|
|
|
2021-06-16 11:16:18 -04:00
|
|
|
void ClassicSprite::pulse()
|
2021-06-11 13:39:47 -04:00
|
|
|
{
|
|
|
|
_grade_text.setFillColor(sf::Color(255, 255, 255, 255));
|
2021-06-16 11:16:18 -04:00
|
|
|
_shape.setFillColor(sf::Color(140, 140, 140));
|
2021-06-16 13:11:00 -04:00
|
|
|
_trail.setPosition(0, 0);
|
|
|
|
_trail.setFillColor(sf::Color(0, 0, 0, 0));
|
2021-06-11 13:39:47 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicSprite::fade()
|
|
|
|
{
|
|
|
|
auto fill_color = _grade_text.getFillColor();
|
|
|
|
|
2021-06-24 14:04:09 -04:00
|
|
|
if (fill_color.a <= 15)
|
|
|
|
{
|
|
|
|
fill_color.a = 0;
|
|
|
|
_grade_text.setFillColor(fill_color);
|
2021-06-11 13:39:47 -04:00
|
|
|
return;
|
2021-06-24 14:04:09 -04:00
|
|
|
}
|
2021-06-11 13:39:47 -04:00
|
|
|
|
2021-06-16 13:11:00 -04:00
|
|
|
auto new_alpha = fill_color.a - 15;
|
2021-06-11 13:39:47 -04:00
|
|
|
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
|
|
|
|
|
|
|
|
_grade_text.setFillColor(fill_color);
|
2021-06-16 11:16:18 -04:00
|
|
|
|
|
|
|
fill_color = _shape.getFillColor();
|
|
|
|
|
|
|
|
if (fill_color.a == 0)
|
2021-06-24 14:04:09 -04:00
|
|
|
{
|
|
|
|
fill_color.a = 0;
|
|
|
|
_shape.setFillColor(fill_color);
|
2021-06-16 11:16:18 -04:00
|
|
|
return;
|
2021-06-24 14:04:09 -04:00
|
|
|
}
|
2021-06-16 11:16:18 -04:00
|
|
|
|
2021-06-16 13:11:00 -04:00
|
|
|
new_alpha = fill_color.a - 15;
|
2021-06-16 11:16:18 -04:00
|
|
|
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
|
|
|
|
|
|
|
|
_shape.setFillColor(fill_color);
|
2021-06-11 13:39:47 -04:00
|
|
|
}
|
|
|
|
|
2021-06-17 15:13:25 -04:00
|
|
|
void ClassicSprite::trailFade()
|
|
|
|
{
|
|
|
|
_trail_fade = true;
|
|
|
|
}
|
|
|
|
|
2021-06-11 13:39:47 -04:00
|
|
|
bool ClassicSprite::isDead() const
|
|
|
|
{
|
2021-06-16 11:16:18 -04:00
|
|
|
return _grade_text.getFillColor().a == 0
|
|
|
|
|| _shape.getFillColor().a == 0;
|
2021-06-09 14:08:58 -04:00
|
|
|
}
|