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),
|
|
|
|
_appearance_time(0)
|
2021-06-08 14:32:36 -04:00
|
|
|
{}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
bool ClassicNote::isActive(const microsec& music_offset) const
|
2021-06-08 14:32:36 -04:00
|
|
|
{
|
|
|
|
return _evaluator.isActive(music_offset);
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
static int getPt( int n1 , int n2 , float perc )
|
|
|
|
{
|
|
|
|
int diff = n2 - n1;
|
|
|
|
|
|
|
|
return n1 + ( diff * perc );
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicNote::update(const microsec& music_offset)
|
|
|
|
{
|
|
|
|
auto update_time = music_offset - _appearance_time;
|
|
|
|
auto i = update_time / _trail_path_percent / 100;
|
|
|
|
|
|
|
|
int xa = getPt( 720./2. , 1280./2. , i );
|
|
|
|
int ya = getPt( 0 , 720./2. , i );
|
|
|
|
int xb = getPt( 1280./2. , _coordinates.x , i );
|
|
|
|
int yb = getPt( 720./2. , _coordinates.y , i );
|
|
|
|
|
2021-06-11 13:39:47 -04:00
|
|
|
_sprite->update(getPt( xa , xb , i ), getPt( ya , yb , i ));
|
|
|
|
|
|
|
|
if (_state == State::DYING)
|
|
|
|
if (_sprite->isDead())
|
|
|
|
_state = State::DEAD;
|
2021-06-11 12:58:44 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
void ClassicNote::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
|
|
|
{
|
|
|
|
target.draw(*_sprite, states);
|
|
|
|
}
|
|
|
|
|
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-08 14:32:36 -04:00
|
|
|
}
|
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-11 13:39:47 -04:00
|
|
|
_state = State::DYING;
|
|
|
|
_sprite->showGrade();
|
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;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
auto ClassicNote::state() const -> State
|
|
|
|
{
|
|
|
|
return _state;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicNote::setState(State next_state)
|
|
|
|
{
|
|
|
|
_state = next_state;
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
std::shared_ptr<ClassicSprite> ClassicNote::sprite() const noexcept
|
|
|
|
{
|
|
|
|
return _sprite;
|
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
void ClassicNote::saveAppearanceTime(const microsec &offset)
|
|
|
|
{
|
|
|
|
_appearance_time = offset;
|
|
|
|
_trail_path_percent = ((_perfect_offset - _appearance_time) * 0.01);
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
void ClassicNote::setSprite(const std::shared_ptr<ClassicSprite>& sprite) noexcept
|
|
|
|
{
|
|
|
|
_sprite = sprite;
|
2021-06-09 18:47:18 -04:00
|
|
|
if (_sprite)
|
2021-06-11 12:58:44 -04:00
|
|
|
_sprite->setCoordinates(_coordinates.x, _coordinates.y, 720/2, 50);
|
2021-06-09 14:08:58 -04:00
|
|
|
}
|
|
|
|
|
2021-06-11 12:58:44 -04:00
|
|
|
const Coordinates& ClassicNote::getCoordinates() const noexcept
|
2021-06-09 14:08:58 -04:00
|
|
|
{
|
|
|
|
return _coordinates;
|
|
|
|
}
|