2021-06-07 14:19:58 -04:00
|
|
|
#include "classicnote.h"
|
2021-06-09 14:08:58 -04:00
|
|
|
#include "classicsprite.h"
|
2021-06-23 18:43:13 -04:00
|
|
|
#include "classicgraphicsmanager.h"
|
|
|
|
#include "classicflyinganimationscenario.h"
|
|
|
|
#include "classicdyinganimationscenario.h"
|
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 18:43:13 -04:00
|
|
|
_keys({sf::Keyboard::W, sf::Keyboard::Up}),
|
2021-06-23 15:18:33 -04:00
|
|
|
_graphics_manager(manager),
|
|
|
|
_is_expired(true),
|
2021-06-23 18:43:13 -04:00
|
|
|
_type(type),
|
|
|
|
_state(State::NONE)
|
|
|
|
{
|
|
|
|
_animations[State::NONE] = nullptr;
|
|
|
|
_animations[State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
|
|
|
|
_animations[State::DYING] = std::make_shared<ClassicDyingAnimationScenario>();
|
|
|
|
}
|
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;
|
2021-06-23 18:43:13 -04:00
|
|
|
_graphics_manager->initGraphics(this);
|
|
|
|
_state = State::FLYING;
|
|
|
|
_animations[_state]->launch(_sprite, music_offset, offset());
|
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 18:43:13 -04:00
|
|
|
if (!_animations[_state])
|
|
|
|
return;
|
|
|
|
|
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)
|
|
|
|
{
|
2021-06-23 18:43:13 -04:00
|
|
|
_state = State::DYING;
|
|
|
|
_animations[_state]->launch(_sprite, music_offset, offset());
|
2021-06-16 11:16:18 -04:00
|
|
|
}
|
2021-06-23 18:43:13 -04:00
|
|
|
|
|
|
|
_animations[_state]->update(music_offset);
|
|
|
|
_is_expired = _animations[_state]->isDone();
|
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-23 18:43:13 -04:00
|
|
|
_state = State::DYING;
|
|
|
|
_animations[_state]->launch(_sprite, inputdata.timestamp, offset());
|
|
|
|
|
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);
|
|
|
|
}
|