Add Note
parent
5b1a00adeb
commit
bf8e6be88f
@ -0,0 +1,34 @@
|
||||
#include "note.h"
|
||||
#include <cmath>
|
||||
|
||||
Note::Note(microsec offset, microsec death_offset, Note::Arrow type) :
|
||||
_offset(offset),
|
||||
_death_offset(death_offset),
|
||||
_type(type)
|
||||
{}
|
||||
|
||||
microsec Note::deathOffset() const noexcept
|
||||
{
|
||||
return _death_offset;
|
||||
}
|
||||
|
||||
NoteGrade Note::onTap(Arrow arrow_type, microsec tap_time_stamp) const
|
||||
{
|
||||
if (arrow_type != _type)
|
||||
return {0, NoteGrade::Rating::WRONG};
|
||||
|
||||
microsec odds = std::abs(tap_time_stamp - _offset);
|
||||
return calculatePrecision(odds);
|
||||
}
|
||||
|
||||
NoteGrade Note::calculatePrecision(microsec odds) const
|
||||
{
|
||||
NoteGrade ret;
|
||||
if (odds < 500000)
|
||||
{
|
||||
ret.score = 50;
|
||||
ret.rating = NoteGrade::Rating::GREAT;
|
||||
}
|
||||
|
||||
return ret;
|
||||
}
|
@ -0,0 +1,45 @@
|
||||
#ifndef NOTE_H
|
||||
#define NOTE_H
|
||||
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
using microsec = sf::Int64;
|
||||
|
||||
struct NoteGrade
|
||||
{
|
||||
int score = 0;
|
||||
enum class Rating
|
||||
{
|
||||
WRONG,
|
||||
BAD,
|
||||
GOOD,
|
||||
GREAT
|
||||
} rating = Rating::BAD;
|
||||
};
|
||||
|
||||
class Note
|
||||
{
|
||||
public:
|
||||
enum class Arrow
|
||||
{
|
||||
UP,
|
||||
RIGHT,
|
||||
DOWN,
|
||||
LEFT
|
||||
};
|
||||
|
||||
Note(microsec offset, microsec death_offset, Note::Arrow type = Note::Arrow::UP);
|
||||
|
||||
NoteGrade onTap(Arrow arrow_type, microsec tap_time_stamp) const;
|
||||
microsec deathOffset() const noexcept;
|
||||
|
||||
|
||||
private:
|
||||
microsec _offset;
|
||||
microsec _death_offset;
|
||||
Arrow _type = Arrow::UP;
|
||||
|
||||
NoteGrade calculatePrecision(microsec odds) const;
|
||||
};
|
||||
|
||||
#endif // NOTE_H
|
Loading…
Reference in New Issue