2021-06-07 14:19:58 -04:00
|
|
|
#include "classicnote.h"
|
2021-06-09 14:08:58 -04:00
|
|
|
#include "classicsprite.h"
|
|
|
|
#include <SFML/Graphics/RenderTarget.hpp>
|
2021-06-09 18:47:18 -04:00
|
|
|
#include <iostream>
|
2021-06-07 14:19:58 -04:00
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
ClassicNote::ClassicNote(const std::vector<microsec>& intervals, microsec perfect_offset,
|
|
|
|
Action action, const Coordinates& coord) :
|
2021-06-07 14:19:58 -04:00
|
|
|
Note(perfect_offset),
|
2021-06-09 14:08:58 -04:00
|
|
|
_coordinates(coord),
|
2021-06-08 14:32:36 -04:00
|
|
|
_evaluator(intervals, _perfect_offset),
|
2021-06-11 12:58:44 -04:00
|
|
|
_action(action),
|
2021-06-17 15:13:25 -04:00
|
|
|
_appearance_time(0),
|
2021-06-21 15:10:50 -04:00
|
|
|
_current_state(ClassicNoteState::NONE)
|
2021-06-08 14:32:36 -04:00
|
|
|
{}
|
|
|
|
|
2021-06-21 15:10:50 -04:00
|
|
|
bool ClassicNote::isActive() const
|
2021-06-08 14:32:36 -04:00
|
|
|
{
|
2021-06-21 15:10:50 -04:00
|
|
|
return _states.at(_current_state)->value() == ClassicNoteState::ACTIVE;
|
|
|
|
}
|
|
|
|
|
2021-06-22 14:20:08 -04:00
|
|
|
bool ClassicNote::isActive(const microsec &music_offset) const
|
2021-06-21 15:10:50 -04:00
|
|
|
{
|
2021-06-22 14:20:08 -04:00
|
|
|
return _evaluator.isActive(music_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicNote::putToGame(const microsec &music_offset)
|
|
|
|
{
|
|
|
|
_appearance_time = music_offset; // To animation manager
|
2021-06-21 15:10:50 -04:00
|
|
|
_trail_path_percent = ((_perfect_offset - _appearance_time) * 0.01);
|
|
|
|
|
|
|
|
_current_state = ClassicNoteState::FLYING;
|
|
|
|
_states.at(_current_state)->onEntering(this);
|
|
|
|
}
|
|
|
|
|
|
|
|
bool ClassicNote::isExpired() const
|
|
|
|
{
|
|
|
|
return _states.at(_current_state)->value() == ClassicNoteState::NONE;
|
2021-06-08 14:32:36 -04:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
void ClassicNote::update(const microsec& music_offset)
|
|
|
|
{
|
2021-06-22 14:20:08 -04:00
|
|
|
auto next_state = _states.at(_current_state)->update(this, music_offset);
|
|
|
|
if (next_state != _current_state)
|
2021-06-16 11:16:18 -04:00
|
|
|
{
|
2021-06-22 14:20:08 -04:00
|
|
|
_current_state = next_state;
|
|
|
|
_states.at(_current_state)->onEntering(this);
|
2021-06-21 15:10:50 -04:00
|
|
|
|
2021-06-16 11:16:18 -04:00
|
|
|
}
|
2021-06-09 14:08:58 -04:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
auto ClassicNote::input(ClassicInputType&& input_data) -> Grade
|
|
|
|
{
|
|
|
|
auto grade = ClassicNote::Grade::BAD;
|
2021-06-09 18:47:18 -04:00
|
|
|
|
2021-06-08 14:32:36 -04:00
|
|
|
if (input_data == _action)
|
2021-06-09 18:47:18 -04:00
|
|
|
grade = _evaluator.calculatePrecision(input_data.timestamp());
|
2021-06-16 11:16:18 -04:00
|
|
|
|
2021-06-21 15:10:50 -04:00
|
|
|
_current_state = ClassicNoteState::DYING;
|
|
|
|
_states.at(_current_state)->onEntering(this);
|
2021-06-07 14:19:58 -04:00
|
|
|
|
2021-06-09 18:47:18 -04:00
|
|
|
std::cout << "User input: " << static_cast<int>(grade) << "\n";
|
2021-06-16 11:16:18 -04:00
|
|
|
|
2021-06-09 18:47:18 -04:00
|
|
|
return grade;
|
2021-06-07 14:19:58 -04:00
|
|
|
}
|
2021-06-09 14:08:58 -04:00
|
|
|
|
|
|
|
Action ClassicNote::action() const
|
|
|
|
{
|
|
|
|
return _action;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::shared_ptr<ClassicSprite> ClassicNote::sprite() const noexcept
|
|
|
|
{
|
|
|
|
return _sprite;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicNote::setSprite(const std::shared_ptr<ClassicSprite>& sprite) noexcept
|
|
|
|
{
|
|
|
|
_sprite = sprite;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
const Coordinates& ClassicNote::getCoordinates() const noexcept
|
2021-06-09 14:08:58 -04:00
|
|
|
{
|
|
|
|
return _coordinates;
|
|
|
|
}
|