#include "classicnote.h" #include "classicsprite.h" #include #include ClassicNote::ClassicNote(const std::vector& intervals, microsec perfect_offset, Action action, const Coordinates& coord) : Note(perfect_offset), _coordinates(coord), _evaluator(intervals, _perfect_offset), _action(action), _appearance_time(0), _current_state(ClassicNoteState::NONE) {} bool ClassicNote::isActive() const { return _states.at(_current_state)->value() == ClassicNoteState::ACTIVE; } void ClassicNote::putToGame(const microsec &offset) { _appearance_time = offset; // To animation manager _trail_path_percent = ((_perfect_offset - _appearance_time) * 0.01); _current_state = ClassicNoteState::FLYING; _states.at(_current_state)->onEntering(this); } bool ClassicNote::isExpired() const { return _states.at(_current_state)->value() == ClassicNoteState::NONE; } static int getPt( float n1 , float n2 , float perc ) { float diff = n2 - n1; return n1 + ( diff * perc ); } void ClassicNote::update(const microsec& music_offset) { _states.at(_current_state)->update(this, music_offset); /*switch (_state) // States will be objects { case State::DYING: _sprite->update(); if (_sprite->isDead()) setState(State::NONE); break; case State::FLYING: { float i; auto update_time = music_offset - _appearance_time; // This all will be inside ::update i = update_time / _trail_path_percent * 0.01; // of an animation object float xa = getPt( _coordinates.x + 20. , _coordinates.x + 90. , i ); float ya = getPt( _coordinates.y - 600. , _coordinates.y - 150. , i ); float xb = getPt( _coordinates.x + 90. , _coordinates.x , i ); float yb = getPt( _coordinates.y - 150. , _coordinates.y , i ); _sprite->update(getPt( xa , xb , i ), getPt( ya , yb , i )); if (i >= 1) { _sprite->trailFade(); } if (_evaluator.isActive(music_offset)) setState(State::ACTIVE); break; } case State::ACTIVE: { float i; auto update_time = music_offset - _appearance_time; // This all will be inside ::update i = update_time / _trail_path_percent * 0.01; // of an animation object float xa = getPt( _coordinates.x + 20. , _coordinates.x + 90. , i ); float ya = getPt( _coordinates.y - 600. , _coordinates.y - 150. , i ); float xb = getPt( _coordinates.x + 90. , _coordinates.x , i ); float yb = getPt( _coordinates.y - 150. , _coordinates.y , i ); _sprite->update(getPt( xa , xb , i ), getPt( ya , yb , i )); if (i >= 1) { _sprite->trailFade(); } if (!_evaluator.isActive(music_offset)) setState(State::DYING); break; } default: break; } */ } void ClassicNote::draw(sf::RenderTarget& target, sf::RenderStates states) const { target.draw(*_sprite, states); } auto ClassicNote::input(ClassicInputType&& input_data) -> Grade { auto grade = ClassicNote::Grade::BAD; if (input_data == _action) grade = _evaluator.calculatePrecision(input_data.timestamp()); _current_state = ClassicNoteState::DYING; _states.at(_current_state)->onEntering(this); std::cout << "User input: " << static_cast(grade) << "\n"; return grade; } Action ClassicNote::action() const { return _action; } /*void ClassicNote::setState(State next_state) { switch (next_state) // States will be objects { case State::DYING: _sprite->pulse(); break; case State::FLYING: _sprite->setCoordinates(_coordinates.x, _coordinates.y, _coordinates.x + 20, _coordinates.y - 600); break; case State::NONE: _sprite->reset(); break; default: break; } _state = next_state; } */ std::shared_ptr ClassicNote::sprite() const noexcept { return _sprite; } void ClassicNote::setSprite(const std::shared_ptr& sprite) noexcept { _sprite = sprite; } const Coordinates& ClassicNote::getCoordinates() const noexcept { return _coordinates; }