2021-05-28 13:50:57 -04:00
|
|
|
#include "classicgame.h"
|
2021-06-07 14:19:58 -04:00
|
|
|
#include "classictimeline.h"
|
2021-06-23 15:18:33 -04:00
|
|
|
#include "classicmapcreator.h"
|
2021-05-28 13:50:57 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
ClassicGame::ClassicGame(std::unique_ptr<ClassicGraphicsManager>&& manager) :
|
2021-06-16 13:11:00 -04:00
|
|
|
_timeline(std::make_unique<ClassicTimeline>()),
|
2021-06-23 15:18:33 -04:00
|
|
|
_graphics_manager(std::move(manager))
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
2021-06-17 15:13:25 -04:00
|
|
|
_slap_buffer.loadFromFile("very-final-slap.wav");
|
|
|
|
_slap.setBuffer(_slap_buffer);
|
|
|
|
_slap.setVolume(50);
|
|
|
|
|
2021-05-31 13:04:16 -04:00
|
|
|
_keys_to_buttons =
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
{sf::Keyboard::Up, Type::UP}, // Load from settings
|
|
|
|
{sf::Keyboard::Right, Type::RIGHT},
|
|
|
|
{sf::Keyboard::Down, Type::DOWN},
|
|
|
|
{sf::Keyboard::Left, Type::LEFT},
|
|
|
|
|
|
|
|
{sf::Keyboard::W, Type::UP},
|
|
|
|
{sf::Keyboard::D, Type::RIGHT},
|
|
|
|
{sf::Keyboard::S, Type::DOWN},
|
|
|
|
{sf::Keyboard::A, Type::LEFT},
|
|
|
|
|
|
|
|
{sf::Keyboard::E, Type::SLIDER_RIGHT},
|
|
|
|
{sf::Keyboard::Q, Type::SLIDER_LEFT}
|
2021-05-31 13:04:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_pressed_actions=
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
{Type::UP, Action::PRESS_UP},
|
|
|
|
{Type::RIGHT, Action::PRESS_RIGHT},
|
|
|
|
{Type::DOWN, Action::PRESS_DOWN},
|
|
|
|
{Type::LEFT, Action::PRESS_LEFT},
|
2021-05-31 13:04:16 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
{Type::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT},
|
|
|
|
{Type::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT}
|
2021-05-31 13:04:16 -04:00
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_released_actions=
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
{Type::UP, Action::RELEASE_UP},
|
|
|
|
{Type::RIGHT, Action::RELEASE_RIGHT},
|
|
|
|
{Type::DOWN, Action::RELEASE_DOWN},
|
|
|
|
{Type::LEFT, Action::RELEASE_LEFT},
|
2021-05-31 13:04:16 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
{Type::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
|
|
|
|
{Type::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
|
2021-05-31 13:04:16 -04:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
ClassicGame::~ClassicGame()
|
|
|
|
{}
|
|
|
|
|
2021-05-31 13:04:16 -04:00
|
|
|
void ClassicGame::run()
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
ClassicMapCreator creator(_graphics_manager);
|
|
|
|
auto beatmap = creator.createBeatmap("aa");
|
|
|
|
_timeline->run(std::move(beatmap.notes), beatmap.visibility_offset);
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
void ClassicGame::input(PlayerInput&& inputdata)
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
inputdata.timestamp = _timeline->currentMusicOffset();
|
2021-05-31 13:04:16 -04:00
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
switch (inputdata.event.type)
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
|
|
|
default:
|
2021-06-11 12:58:44 -04:00
|
|
|
return;
|
|
|
|
break;
|
2021-05-31 13:04:16 -04:00
|
|
|
case sf::Event::KeyPressed:
|
|
|
|
case sf::Event::KeyReleased:
|
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
auto note = _timeline->getActiveNote();
|
|
|
|
|
|
|
|
if (!_timeline->isExpired(note))
|
|
|
|
{
|
|
|
|
(*note)->input(std::move(inputdata));
|
|
|
|
_slap.play();
|
|
|
|
}
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicGame::update()
|
|
|
|
{
|
2021-06-08 14:32:36 -04:00
|
|
|
_timeline->update();
|
2021-06-23 15:18:33 -04:00
|
|
|
_timeline->fetchVisibleNotes();
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
2021-06-23 15:18:33 -04:00
|
|
|
void ClassicGame::draw() const
|
2021-05-28 13:50:57 -04:00
|
|
|
{
|
2021-06-23 15:18:33 -04:00
|
|
|
_timeline->drawVisibleNotes();
|
2021-05-28 13:50:57 -04:00
|
|
|
}
|