project-kyoku/note.h

86 lines
1.7 KiB
C
Raw Normal View History

2021-04-04 16:43:12 -04:00
#ifndef NOTE_H
#define NOTE_H
#include <SFML/System/Clock.hpp>
#include <SFML/System/Vector2.hpp>
2021-04-15 11:03:35 -04:00
#include <SFML/Graphics/RectangleShape.hpp> // TEMP MOCK
#include <memory>
////////////////////////////////
2021-04-04 16:43:12 -04:00
using microsec = sf::Int64;
using coordinates = sf::Vector2i;
2021-04-04 16:43:12 -04:00
2021-04-15 11:03:35 -04:00
class Sprite // MOCK
{
public:
Sprite(sf::RectangleShape shape) : _shape(shape), _attached(false) {};
bool isAttached() const noexcept
{ return _attached; }
void setAttachment(bool attached) noexcept
{ _attached = attached; }
private:
sf::RectangleShape _shape;
bool _attached;
};
2021-04-04 16:43:12 -04:00
struct NoteGrade
{
int score;
2021-04-04 16:43:12 -04:00
enum class Rating
{
WRONG,
BAD,
GOOD,
GREAT
} rating;
NoteGrade(int s, Rating r) : score(s), rating(r) {}
2021-04-04 16:43:12 -04:00
};
////////////////////////////////
2021-04-04 16:43:12 -04:00
class Note
{
public:
enum class Arrow
{
UP,
RIGHT,
DOWN,
2021-04-05 10:17:57 -04:00
LEFT,
NONE
2021-04-04 16:43:12 -04:00
};
Note(microsec offset, microsec life_span_offset, Note::Arrow type = Note::Arrow::UP);
2021-04-04 16:43:12 -04:00
void setPosition(coordinates position);
coordinates position() const noexcept;
2021-04-05 10:17:57 -04:00
microsec offset() const noexcept;
2021-04-15 11:03:35 -04:00
NoteGrade onTap(Arrow arrow_type, microsec tap_time_stamp);
bool isActive(microsec music_play_offset) const noexcept;
2021-04-15 11:03:35 -04:00
void resetSprite(const std::shared_ptr<Sprite>& sprite) noexcept;
static void resetPrecisionQualifier(microsec qualifier = 500000);
2021-04-04 16:43:12 -04:00
private:
coordinates _position;
2021-04-04 16:43:12 -04:00
microsec _offset;
microsec _start_handling_offset;
microsec _end_handling_offset;
2021-04-04 16:43:12 -04:00
Arrow _type = Arrow::UP;
static microsec _precision_qualifier;
2021-04-04 16:43:12 -04:00
NoteGrade calculatePrecision(microsec odds) const;
2021-04-15 11:03:35 -04:00
std::shared_ptr<Sprite> _sprite;
2021-04-04 16:43:12 -04:00
};
#endif // NOTE_H