2021-11-23 13:35:13 -05:00
|
|
|
#include "mockclassicnote.h"
|
2021-11-24 13:21:30 -05:00
|
|
|
#include "graphics/classicgraphicsmanager.h"
|
|
|
|
|
|
|
|
// Replace with interface by dependency injection
|
|
|
|
#include "graphics/classicflyinganimationscenario.h"
|
|
|
|
#include "graphics/classicdyinganimationscenario.h"
|
|
|
|
//
|
|
|
|
|
|
|
|
// A LOT OF CODE DUPLICATES game/arrowclassicnote, DO SOMETHING D:<
|
2021-11-23 13:35:13 -05:00
|
|
|
|
|
|
|
MockClassicNote::MockClassicNote(MockArrowNoteInitializer&& init) :
|
2021-11-24 13:21:30 -05:00
|
|
|
Note(init.initializer.perfect_offset),
|
|
|
|
_state(State::NONE),
|
|
|
|
_context(init.initializer.context)
|
|
|
|
{
|
|
|
|
_elements.resize(init.elements.size());
|
|
|
|
|
|
|
|
for (std::size_t i = 0; i < _elements.size(); ++i)
|
|
|
|
{
|
|
|
|
_elements[i].coordinates = init.elements[i].coordinates;
|
|
|
|
_elements[i].type = init.elements[i].type;
|
|
|
|
|
|
|
|
// Animations will be injected into note.
|
|
|
|
_elements[i].animations[State::NONE] = nullptr;
|
|
|
|
_elements[i].animations[State::FLYING] = std::make_shared<ClassicFlyingAnimationScenario>();
|
|
|
|
_elements[i].animations[State::DYING] = std::make_shared<ClassicDyingAnimationScenario>();
|
|
|
|
_elements[i].animations[State::DEAD] = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MockClassicNote::isActive() const
|
|
|
|
{
|
|
|
|
return _state != State::DEAD
|
|
|
|
&& _state != State::NONE;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MockClassicNote::isInGame() const
|
|
|
|
{
|
|
|
|
return _state == State::FLYING
|
|
|
|
|| _state == State::DYING;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool MockClassicNote::shouldRemove() const
|
|
|
|
{
|
|
|
|
return _state == State::DEAD;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockClassicNote::putToGame(const microsec &music_offset)
|
|
|
|
{
|
|
|
|
_state = State::FLYING;
|
|
|
|
|
|
|
|
for (auto& element : _elements)
|
|
|
|
{
|
|
|
|
element.sprite = _context->graphics_manager->getSprite(element.type);
|
|
|
|
element.sprite->setCoordinates(element.coordinates);
|
|
|
|
element.sprite->setTrailCoordinates(Coordinates(0.f, 9.f));
|
|
|
|
element.animations[_state]->launch(element.sprite, music_offset, offset());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockClassicNote::update(const microsec &music_offset)
|
|
|
|
{
|
|
|
|
switch (_state)
|
|
|
|
{
|
|
|
|
default: return;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::FLYING:
|
|
|
|
if (music_offset > offset())
|
|
|
|
_state = State::DYING;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case State::DYING:
|
|
|
|
if (_elements[0].animations[_state]->isDone())
|
|
|
|
_state = State::DEAD;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
for (auto& element : _elements)
|
|
|
|
if (element.animations[_state])
|
|
|
|
element.animations[_state]->update(music_offset);
|
|
|
|
}
|
|
|
|
|
|
|
|
void MockClassicNote::draw() const
|
2021-11-23 13:35:13 -05:00
|
|
|
{
|
2021-11-24 13:21:30 -05:00
|
|
|
for (std::size_t i = 0; i < _elements.size(); ++i)
|
|
|
|
{
|
|
|
|
if (i >= 1)
|
|
|
|
_context->graphics_manager->drawLine(_elements[i-1].sprite->trailCoordinates(), _elements[i].sprite->trailCoordinates());
|
2021-11-23 13:35:13 -05:00
|
|
|
|
2021-11-24 13:21:30 -05:00
|
|
|
_context->graphics_manager->draw(_elements[i].sprite);
|
|
|
|
}
|
2021-11-23 13:35:13 -05:00
|
|
|
}
|