project-kyoku/src/classicgame/classicnote.cpp

79 lines
1.9 KiB
C++
Raw Normal View History

2021-06-07 14:19:58 -04:00
#include "classicnote.h"
#include "classicsprite.h"
#include <SFML/Graphics/RenderTarget.hpp>
#include <iostream>
2021-06-07 14:19:58 -04:00
ClassicNote::ClassicNote(const std::vector<microsec>& intervals, microsec perfect_offset,
Type type, const Coordinates& coord, const std::unique_ptr<ClassicGraphicsManager> &manager) :
2021-06-07 14:19:58 -04:00
Note(perfect_offset),
_coordinates(coord),
2021-06-08 14:32:36 -04:00
_evaluator(intervals, _perfect_offset),
_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-22 14:20:08 -04:00
return _evaluator.isActive(music_offset);
}
void ClassicNote::putToGame(const microsec &music_offset)
{
_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);
}
bool ClassicNote::isExpired() const
{
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)
{
bool is_not_active_anymore = (!_is_expired && !isActive(music_offset));
if (is_not_active_anymore)
{
_graphics_manager->resetSprite(this);
_is_expired = true;
}
}
void ClassicNote::input(PlayerInput&& inputdata)
2021-06-11 12:58:44 -04:00
{
auto grade = ClassicNote::Grade::BAD;
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
std::cout << "User input: " << static_cast<int>(grade) << "\n";
}
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
{
return _coordinates;
}
Type ClassicNote::type() const noexcept
{
return _type;
}
void ClassicNote::draw() const
{
_graphics_manager->draw(this);
}