#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) {} bool ClassicNote::isActive(const microsec& music_offset) const { return _evaluator.isActive(music_offset); } static int getPt( int n1 , int n2 , float perc ) { int diff = n2 - n1; return n1 + ( diff * perc ); } void ClassicNote::update(const microsec& music_offset) { auto update_time = music_offset - _appearance_time; auto i = update_time / _trail_path_percent / 100; int xa = getPt( 720./2. , 1280./2. , i ); int ya = getPt( 0 , 720./2. , i ); int xb = getPt( 1280./2. , _coordinates.x , i ); int yb = getPt( 720./2. , _coordinates.y , i ); _sprite->setTrailCoordinates(getPt( xa , xb , i ), getPt( ya , yb , i )); } 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()); } std::cout << "User input: " << static_cast(grade) << "\n"; _state = State::DEAD; return grade; } Action ClassicNote::action() const { return _action; } auto ClassicNote::state() const -> State { return _state; } void ClassicNote::setState(State next_state) { _state = next_state; } std::shared_ptr ClassicNote::sprite() const noexcept { return _sprite; } void ClassicNote::saveAppearanceTime(const microsec &offset) { _appearance_time = offset; _trail_path_percent = ((_perfect_offset - _appearance_time) * 0.01); } void ClassicNote::setSprite(const std::shared_ptr& sprite) noexcept { _sprite = sprite; if (_sprite) _sprite->setCoordinates(_coordinates.x, _coordinates.y, 720/2, 50); } const Coordinates& ClassicNote::getCoordinates() const noexcept { return _coordinates; }