2021-05-28 13:50:57 -04:00
|
|
|
#include "classicgame.h"
|
2021-07-21 14:15:56 -04:00
|
|
|
#include "classicnote.h"
|
2021-06-23 15:18:33 -04:00
|
|
|
#include "classicmapcreator.h"
|
2021-12-27 13:41:25 -05:00
|
|
|
#include "game/classicgamegraphicsmanager.h"
|
2021-10-04 11:30:21 -04:00
|
|
|
#include "holdmanager.h"
|
2021-05-28 13:50:57 -04:00
|
|
|
|
2021-12-21 12:07:19 -05:00
|
|
|
ClassicGame::ClassicGame() :
|
2021-12-27 13:41:25 -05:00
|
|
|
_graphics_manager(new ClassicGameGraphicsManager(_timeline, 1648648)),
|
2021-12-21 12:07:19 -05:00
|
|
|
_hold_manager(std::make_unique<HoldManager>())
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
2021-10-04 11:30:21 -04:00
|
|
|
_slap_buffer.loadFromFile("Tick.ogg");
|
2021-06-17 15:13:25 -04:00
|
|
|
_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-11-02 13:03:27 -04:00
|
|
|
_context.hold_manager = _hold_manager;
|
2021-10-04 11:30:21 -04:00
|
|
|
|
2021-11-02 13:03:27 -04:00
|
|
|
auto beatmap = classic::createBeatmap("aa", _context);
|
2021-12-21 10:48:39 -05:00
|
|
|
_timeline.setNotes(beatmap.notes);
|
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
|
|
|
switch (inputdata.event.type)
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
|
|
|
default:
|
2021-06-11 12:58:44 -04:00
|
|
|
return;
|
2021-07-21 14:15:56 -04:00
|
|
|
break;
|
|
|
|
|
2021-05-31 13:04:16 -04:00
|
|
|
case sf::Event::KeyPressed:
|
2021-07-21 14:15:56 -04:00
|
|
|
{
|
2021-12-08 13:00:47 -05:00
|
|
|
auto note_it = _timeline.getActiveNote(inputdata.timestamp);
|
2021-07-21 14:15:56 -04:00
|
|
|
|
2021-09-14 15:02:23 -04:00
|
|
|
if (!_timeline.isExpired(note_it))
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
2021-07-21 14:15:56 -04:00
|
|
|
auto note = (*note_it);
|
2021-09-14 15:02:23 -04:00
|
|
|
note->input(std::move(inputdata));
|
2021-07-21 14:15:56 -04:00
|
|
|
_slap.play();
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
2021-07-21 14:15:56 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::KeyReleased:
|
|
|
|
{
|
2021-10-04 11:30:21 -04:00
|
|
|
_hold_manager->checkRelease(inputdata.event.key.code);
|
2021-07-21 14:15:56 -04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-03 14:21:27 -05:00
|
|
|
void ClassicGame::update(UpdateData&& updatedata)
|
2021-05-31 13:04:16 -04:00
|
|
|
{
|
2021-12-27 13:41:25 -05:00
|
|
|
// UNCOMMENT TO TEST AUTOPLAY
|
|
|
|
/*auto note_it = _timeline.getActiveNote(updatedata.timestamp);
|
|
|
|
|
|
|
|
if (!_timeline.isExpired(note_it) && updatedata.timestamp >= (*note_it)->offset())
|
|
|
|
{
|
|
|
|
auto note = (*note_it);
|
|
|
|
note->input(PlayerInput{updatedata.timestamp, sf::Event{}});
|
|
|
|
_slap.play();
|
|
|
|
}*/
|
|
|
|
|
2021-12-03 14:21:27 -05:00
|
|
|
_timeline.update(updatedata.timestamp);
|
2021-12-23 12:33:24 -05:00
|
|
|
_graphics_manager->update(updatedata.timestamp);
|
2021-05-31 13:04:16 -04:00
|
|
|
}
|
|
|
|
|
2021-12-27 13:41:25 -05:00
|
|
|
void ClassicGame::draw(sf::RenderTarget& target, sf::RenderStates states) const
|
2021-05-28 13:50:57 -04:00
|
|
|
{
|
2021-12-27 13:41:25 -05:00
|
|
|
_graphics_manager->draw(target, states);
|
2021-05-28 13:50:57 -04:00
|
|
|
}
|