project-kyoku/note.cpp

40 lines
767 B
C++
Raw Normal View History

2021-04-04 22:43:12 +02:00
#include "note.h"
#include <cmath>
Note::Note(microsec offset, microsec death_offset, Note::Arrow type) :
_offset(offset),
_death_offset(death_offset),
_type(type)
{}
2021-04-05 16:17:57 +02:00
microsec Note::offset() const noexcept
{
return _offset;
}
2021-04-04 22:43:12 +02:00
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;
2021-04-05 16:17:57 +02:00
if (odds < 412162)
2021-04-04 22:43:12 +02:00
{
ret.score = 50;
2021-04-05 16:17:57 +02:00
ret.rating = NoteGrade::Rating::GREAT;
2021-04-04 22:43:12 +02:00
}
return ret;
}