2021-04-04 22:43:12 +02:00
|
|
|
#ifndef NOTE_H
|
|
|
|
#define NOTE_H
|
|
|
|
|
|
|
|
#include <SFML/System/Clock.hpp>
|
2021-04-06 19:39:29 +02:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
2021-04-15 17:03:35 +02:00
|
|
|
#include <SFML/Graphics/RectangleShape.hpp> // TEMP MOCK
|
2021-04-17 18:14:36 +02:00
|
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
2021-04-15 17:03:35 +02:00
|
|
|
|
|
|
|
#include <memory>
|
2021-04-06 19:39:29 +02:00
|
|
|
|
|
|
|
////////////////////////////////
|
2021-04-04 22:43:12 +02:00
|
|
|
|
|
|
|
using microsec = sf::Int64;
|
2021-04-06 19:39:29 +02:00
|
|
|
using coordinates = sf::Vector2i;
|
2021-04-04 22:43:12 +02:00
|
|
|
|
2021-04-17 18:14:36 +02:00
|
|
|
class Sprite : public sf::Drawable // MOCK
|
2021-04-15 17:03:35 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
Sprite(sf::RectangleShape shape) : _shape(shape), _attached(false) {};
|
|
|
|
bool isAttached() const noexcept
|
|
|
|
{ return _attached; }
|
|
|
|
|
2021-04-17 18:14:36 +02:00
|
|
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override
|
|
|
|
{
|
|
|
|
target.draw(_shape, states);
|
|
|
|
}
|
|
|
|
|
|
|
|
void setCoordinates(coordinates cords) noexcept
|
|
|
|
{ _shape.setPosition(cords.x, cords.y); }
|
|
|
|
|
2021-04-15 17:03:35 +02:00
|
|
|
void setAttachment(bool attached) noexcept
|
|
|
|
{ _attached = attached; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
sf::RectangleShape _shape;
|
|
|
|
bool _attached;
|
|
|
|
};
|
|
|
|
|
2021-04-04 22:43:12 +02:00
|
|
|
struct NoteGrade
|
|
|
|
{
|
2021-04-06 19:39:29 +02:00
|
|
|
int score;
|
2021-04-04 22:43:12 +02:00
|
|
|
enum class Rating
|
|
|
|
{
|
|
|
|
WRONG,
|
|
|
|
BAD,
|
|
|
|
GOOD,
|
|
|
|
GREAT
|
2021-04-06 19:39:29 +02:00
|
|
|
} rating;
|
|
|
|
|
|
|
|
NoteGrade(int s, Rating r) : score(s), rating(r) {}
|
2021-04-04 22:43:12 +02:00
|
|
|
};
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
////////////////////////////////
|
|
|
|
|
2021-04-17 18:14:36 +02:00
|
|
|
class Note : public sf::Drawable
|
2021-04-04 22:43:12 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum class Arrow
|
|
|
|
{
|
|
|
|
UP,
|
|
|
|
RIGHT,
|
|
|
|
DOWN,
|
2021-04-05 16:17:57 +02:00
|
|
|
LEFT,
|
|
|
|
|
|
|
|
NONE
|
2021-04-04 22:43:12 +02:00
|
|
|
};
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
Note(microsec offset, microsec life_span_offset, Note::Arrow type = Note::Arrow::UP);
|
2021-04-04 22:43:12 +02:00
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
void setPosition(coordinates position);
|
|
|
|
coordinates position() const noexcept;
|
2021-04-05 16:17:57 +02:00
|
|
|
microsec offset() const noexcept;
|
2021-04-17 18:14:36 +02:00
|
|
|
Note::Arrow type() const noexcept;
|
2021-04-06 19:39:29 +02:00
|
|
|
|
2021-04-15 17:03:35 +02:00
|
|
|
NoteGrade onTap(Arrow arrow_type, microsec tap_time_stamp);
|
2021-04-06 19:39:29 +02:00
|
|
|
bool isActive(microsec music_play_offset) const noexcept;
|
|
|
|
|
2021-04-17 18:14:36 +02:00
|
|
|
void resetSprite(const std::shared_ptr<Sprite>& sprite = nullptr) noexcept;
|
|
|
|
|
|
|
|
virtual void draw(sf::RenderTarget& target, sf::RenderStates states) const override;
|
2021-04-15 17:03:35 +02:00
|
|
|
|
2021-04-08 15:34:03 +02:00
|
|
|
static void resetPrecisionQualifier(microsec qualifier = 500000);
|
2021-04-04 22:43:12 +02:00
|
|
|
|
|
|
|
private:
|
2021-04-06 19:39:29 +02:00
|
|
|
coordinates _position;
|
2021-04-04 22:43:12 +02:00
|
|
|
microsec _offset;
|
2021-04-06 19:39:29 +02:00
|
|
|
microsec _start_handling_offset;
|
|
|
|
microsec _end_handling_offset;
|
2021-04-04 22:43:12 +02:00
|
|
|
Arrow _type = Arrow::UP;
|
|
|
|
|
2021-04-06 19:39:29 +02:00
|
|
|
static microsec _precision_qualifier;
|
2021-04-04 22:43:12 +02:00
|
|
|
NoteGrade calculatePrecision(microsec odds) const;
|
2021-04-15 17:03:35 +02:00
|
|
|
|
|
|
|
std::shared_ptr<Sprite> _sprite;
|
2021-04-04 22:43:12 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // NOTE_H
|