2021-05-28 13:50:57 -04:00
|
|
|
#include "classicgame.h"
|
2021-05-31 13:04:16 -04:00
|
|
|
#include "classicinputtype.h"
|
2021-06-07 14:19:58 -04:00
|
|
|
#include "classictimeline.h"
|
2021-06-16 11:16:18 -04:00
|
|
|
#include "spritecontainer.h"
|
2021-06-08 14:32:36 -04:00
|
|
|
#include "classicnote.h"
|
2021-05-28 13:50:57 -04:00
|
|
|
|
2021-06-07 14:19:58 -04:00
|
|
|
ClassicGame::ClassicGame() :
|
2021-06-16 11:16:18 -04:00
|
|
|
_timeline(std::make_unique<ClassicTimeline>())
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
|
|
|
_keys_to_buttons =
|
|
|
|
{
|
|
|
|
{sf::Keyboard::Up, Button::UP}, // Load from settings
|
|
|
|
{sf::Keyboard::Right, Button::RIGHT},
|
|
|
|
{sf::Keyboard::Down, Button::DOWN},
|
|
|
|
{sf::Keyboard::Left, Button::LEFT},
|
|
|
|
|
|
|
|
{sf::Keyboard::W, Button::UP},
|
|
|
|
{sf::Keyboard::D, Button::RIGHT},
|
|
|
|
{sf::Keyboard::S, Button::DOWN},
|
|
|
|
{sf::Keyboard::A, Button::LEFT},
|
|
|
|
|
|
|
|
{sf::Keyboard::E, Button::SLIDER_RIGHT},
|
|
|
|
{sf::Keyboard::Q, Button::SLIDER_LEFT}
|
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_pressed_actions=
|
|
|
|
{
|
|
|
|
{Button::UP, Action::PRESS_UP},
|
|
|
|
{Button::RIGHT, Action::PRESS_RIGHT},
|
|
|
|
{Button::DOWN, Action::PRESS_DOWN},
|
|
|
|
{Button::LEFT, Action::PRESS_LEFT},
|
|
|
|
|
|
|
|
{Button::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT},
|
|
|
|
{Button::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT}
|
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_released_actions=
|
|
|
|
{
|
|
|
|
{Button::UP, Action::RELEASE_UP},
|
|
|
|
{Button::RIGHT, Action::RELEASE_RIGHT},
|
|
|
|
{Button::DOWN, Action::RELEASE_DOWN},
|
|
|
|
{Button::LEFT, Action::RELEASE_LEFT},
|
|
|
|
|
|
|
|
{Button::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
|
|
|
|
{Button::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
ClassicGame::~ClassicGame()
|
|
|
|
{}
|
|
|
|
|
2021-05-31 13:04:16 -04:00
|
|
|
void ClassicGame::run()
|
|
|
|
{
|
2021-06-16 11:16:18 -04:00
|
|
|
_timeline->fetchVisibleNotes(_sprite_container);
|
2021-06-11 12:58:44 -04:00
|
|
|
_timeline->run();
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicGame::input(const sf::Event& event)
|
|
|
|
{
|
|
|
|
Action new_action = Action::NONE;
|
2021-06-08 14:32:36 -04:00
|
|
|
microsec timestamp = _timeline->currentMusicOffset();
|
2021-05-31 13:04:16 -04:00
|
|
|
|
|
|
|
switch (event.type)
|
|
|
|
{
|
|
|
|
default:
|
2021-06-11 12:58:44 -04:00
|
|
|
return;
|
|
|
|
break;
|
2021-05-31 13:04:16 -04:00
|
|
|
case sf::Event::KeyPressed:
|
|
|
|
{
|
|
|
|
if (_keys_to_buttons.find(event.key.code) != _keys_to_buttons.end())
|
|
|
|
new_action = getActionKeyPressed(_keys_to_buttons[event.key.code]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case sf::Event::KeyReleased:
|
|
|
|
{
|
|
|
|
if (_keys_to_buttons.find(event.key.code) != _keys_to_buttons.end())
|
|
|
|
new_action = getActionKeyReleased(_keys_to_buttons[event.key.code]);
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
2021-06-08 14:32:36 -04:00
|
|
|
auto note = _timeline->getActiveNote();
|
|
|
|
|
2021-06-16 11:16:18 -04:00
|
|
|
if (!_timeline->isExpired(note))
|
2021-06-11 12:58:44 -04:00
|
|
|
{
|
2021-06-11 13:39:47 -04:00
|
|
|
(*note)->input(ClassicInputType(timestamp, new_action));
|
2021-06-11 12:58:44 -04:00
|
|
|
}
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
Action ClassicGame::getActionKeyPressed(Button button) const
|
|
|
|
{
|
|
|
|
return _buttons_to_pressed_actions.at(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
Action ClassicGame::getActionKeyReleased(Button button) const
|
|
|
|
{
|
|
|
|
return _buttons_to_released_actions.at(button);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicGame::update()
|
|
|
|
{
|
2021-06-08 14:32:36 -04:00
|
|
|
_timeline->update();
|
2021-06-16 11:16:18 -04:00
|
|
|
_timeline->fetchVisibleNotes(_sprite_container);
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
2021-06-09 14:08:58 -04:00
|
|
|
void ClassicGame::draw(sf::RenderWindow& window) const
|
2021-05-28 13:50:57 -04:00
|
|
|
{
|
2021-06-09 14:08:58 -04:00
|
|
|
_timeline->drawVisibleNotes(window);
|
2021-05-28 13:50:57 -04:00
|
|
|
}
|