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,
|
2021-06-23 15:18:33 -04:00
|
|
|
Type type, const Coordinates& coord, const std::unique_ptr<ClassicGraphicsManager> &manager) :
|
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-23 15:18:33 -04:00
|
|
|
_graphics_manager(manager),
|
|
|
|
_is_expired(true),
|
|
|
|
_type(type)
|
2021-06-08 14:32:36 -04:00
|
|
|
{}
|
|
|
|
|
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)
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
_is_expired = false;
|
|
|
|
_graphics_manager->initSprite(this); (void) music_offset;
|
|
|
|
//_appearance_time = music_offset; // To animation manager
|
|
|
|
//_trail_path_percent = ((_perfect_offset - _appearance_time) * 0.01);
|
2021-06-21 15:10:50 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
bool ClassicNote::isExpired() const
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
return _is_expired;
|
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-23 15:18:33 -04:00
|
|
|
bool is_not_active_anymore = (!_is_expired && !isActive(music_offset));
|
2021-06-21 15:10:50 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
if (is_not_active_anymore)
|
|
|
|
{
|
|
|
|
_graphics_manager->resetSprite(this);
|
|
|
|
_is_expired = true;
|
2021-06-16 11:16:18 -04:00
|
|
|
}
|
2021-06-09 14:08:58 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
void ClassicNote::input(PlayerInput&& inputdata)
|
2021-06-11 12:58:44 -04:00
|
|
|
{
|
|
|
|
auto grade = ClassicNote::Grade::BAD;
|
2021-06-09 18:47:18 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
if (std::find(_keys.begin(), _keys.end(), inputdata.event.key.code) != _keys.end())
|
|
|
|
grade = _evaluator.calculatePrecision(inputdata.timestamp);
|
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-09 14:08:58 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
2021-06-23 15:18:33 -04:00
|
|
|
|
|
|
|
Type ClassicNote::type() const noexcept
|
|
|
|
{
|
|
|
|
return _type;
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicNote::draw() const
|
|
|
|
{
|
|
|
|
_graphics_manager->draw(this);
|
|
|
|
}
|