forked from NaiJi/project-kyoku
Implement more precise active note detection
parent
192e371d2f
commit
ad1b31c95c
@ -1,47 +0,0 @@
|
||||
#ifndef DEBUGHELPER_H
|
||||
#define DEBUGHELPER_H
|
||||
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/RectangleShape.hpp>
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
using microsec = sf::Int64;
|
||||
|
||||
class DebugHelper : public sf::Drawable
|
||||
{
|
||||
public:
|
||||
DebugHelper(bool init = true);
|
||||
|
||||
void toggle();
|
||||
void update(const microsec& microseconds);
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
|
||||
void spawnGreenPulse();
|
||||
void spawnRedPulse();
|
||||
void spawnBluePulse();
|
||||
|
||||
private:
|
||||
bool _toggled;
|
||||
sf::Font _font;
|
||||
sf::Text _time_print;
|
||||
|
||||
class Pulse : public sf::Drawable
|
||||
{
|
||||
public:
|
||||
Pulse(sf::Vector2f position, sf::Color fill_color);
|
||||
void appear();
|
||||
void fade();
|
||||
|
||||
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
||||
|
||||
private:
|
||||
sf::RectangleShape _pulse_shape;
|
||||
};
|
||||
|
||||
Pulse _red_pulse;
|
||||
Pulse _green_pulse;
|
||||
Pulse _blue_pulse;
|
||||
};
|
||||
|
||||
#endif // DEBUGHELPER_H
|
@ -1,24 +1,53 @@
|
||||
#include "classicsprite.h"
|
||||
#include <SFML/Graphics/RenderTarget.hpp>
|
||||
|
||||
ClassicSprite::ClassicSprite(const sf::RectangleShape& shape) :
|
||||
ClassicSprite::ClassicSprite(const sf::RectangleShape& shape, const sf::Font& font) :
|
||||
_shape(shape),
|
||||
_trail(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::setTrailCoordinates(float trail_x, float trail_y) noexcept
|
||||
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;
|
||||
}
|
||||
|
@ -1,89 +0,0 @@
|
||||
#include "debughelper.h"
|
||||
|
||||
DebugHelper::DebugHelper(bool init) :
|
||||
_toggled(init),
|
||||
_red_pulse({0.f, 0.f}, sf::Color(255, 0, 0)),
|
||||
_green_pulse({460.f, 0.f}, sf::Color(0, 255, 0)),
|
||||
_blue_pulse({460.f, 360.f}, sf::Color(0, 100, 255))
|
||||
{
|
||||
_font.loadFromFile("/usr/share/qtcreator/fonts/SourceCodePro-Regular.ttf");
|
||||
|
||||
_time_print.setFont(_font);
|
||||
_time_print.setPosition(60, 60);
|
||||
_time_print.setFillColor(sf::Color(255, 255, 255));
|
||||
_time_print.setCharacterSize(25);
|
||||
}
|
||||
|
||||
void DebugHelper::toggle()
|
||||
{
|
||||
_toggled = !_toggled;
|
||||
}
|
||||
|
||||
void DebugHelper::update(const microsec µseconds)
|
||||
{
|
||||
_time_print.setString(std::to_string(microseconds));
|
||||
|
||||
_red_pulse.fade();
|
||||
_green_pulse.fade();
|
||||
_blue_pulse.fade();
|
||||
}
|
||||
|
||||
void DebugHelper::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
if (_toggled)
|
||||
{
|
||||
target.draw(_green_pulse, states);
|
||||
target.draw(_red_pulse, states);
|
||||
target.draw(_blue_pulse, states);
|
||||
target.draw(_time_print, states);
|
||||
}
|
||||
}
|
||||
|
||||
void DebugHelper::spawnGreenPulse()
|
||||
{
|
||||
_green_pulse.appear();
|
||||
}
|
||||
|
||||
void DebugHelper::spawnRedPulse()
|
||||
{
|
||||
_red_pulse.appear();
|
||||
}
|
||||
|
||||
void DebugHelper::spawnBluePulse()
|
||||
{
|
||||
_blue_pulse.appear();
|
||||
}
|
||||
|
||||
DebugHelper::Pulse::Pulse(sf::Vector2f position, sf::Color fill_color)
|
||||
{
|
||||
_pulse_shape.setSize({480, 360});
|
||||
_pulse_shape.move(position.x, position.y);
|
||||
|
||||
fill_color.a = 0;
|
||||
_pulse_shape.setFillColor(fill_color);
|
||||
}
|
||||
|
||||
void DebugHelper::Pulse::appear()
|
||||
{
|
||||
auto fill_color = _pulse_shape.getFillColor();
|
||||
fill_color.a = 255;
|
||||
_pulse_shape.setFillColor(fill_color);
|
||||
}
|
||||
|
||||
void DebugHelper::Pulse::fade()
|
||||
{
|
||||
auto fill_color = _pulse_shape.getFillColor();
|
||||
|
||||
if (fill_color.a == 0)
|
||||
return;
|
||||
|
||||
const auto new_alpha = fill_color.a - 25;
|
||||
fill_color.a = new_alpha < 0 ? 0 : new_alpha;
|
||||
|
||||
_pulse_shape.setFillColor(fill_color);
|
||||
}
|
||||
|
||||
void DebugHelper::Pulse::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
||||
{
|
||||
target.draw(_pulse_shape, states);
|
||||
}
|
Loading…
Reference in New Issue