You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
project-kyoku/src/classicgame/classicsprite.cpp

54 lines
1.2 KiB
C++

#include "classicsprite.h"
#include <SFML/Graphics/RenderTarget.hpp>
ClassicSprite::ClassicSprite(const sf::RectangleShape& shape, const sf::Font& font) :
_shape(shape),
_trail(shape),
_font(font)
{
_grade_text.setFont(_font);
}
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::setCoordinates(float x, float y, float trail_x, float trail_y) noexcept
{
_shape.setPosition(x, y);
_trail.setPosition(trail_x, trail_y);
_grade_text.setPosition(x + _shape.getSize().x/2, y + 10);
}
void ClassicSprite::update(float trail_x, float trail_y) noexcept
{
_trail.setPosition(trail_x, trail_y);
fade();
}
void ClassicSprite::showGrade()
{
_grade_text.setFillColor(sf::Color(255, 255, 255, 255));
}
void ClassicSprite::fade()
{
auto fill_color = _grade_text.getFillColor();
if (fill_color.a == 0)
return;
const auto new_alpha = fill_color.a - 55;
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
_grade_text.setFillColor(fill_color);
}
bool ClassicSprite::isDead() const
{
return _grade_text.getFillColor().a == 0;
}