2021-05-28 19:50:57 +02:00
|
|
|
#include "classicgame.h"
|
2021-06-07 20:19:58 +02:00
|
|
|
#include "classictimeline.h"
|
2021-07-21 20:15:56 +02:00
|
|
|
#include "classicnote.h"
|
2021-06-23 21:18:33 +02:00
|
|
|
#include "classicmapcreator.h"
|
2021-08-09 20:59:40 +02:00
|
|
|
#include "classicnotemanager.h"
|
2021-08-05 20:59:48 +02:00
|
|
|
#include "tools/music.h"
|
2021-07-21 20:15:56 +02:00
|
|
|
#include <iostream>
|
2021-05-28 19:50:57 +02:00
|
|
|
|
2021-08-09 20:59:40 +02:00
|
|
|
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
|
2021-08-05 20:59:48 +02:00
|
|
|
_graphics_manager(std::move(manager)),
|
2021-08-09 20:59:40 +02:00
|
|
|
_note_manager(std::make_unique<ClassicNoteManager>(_graphics_manager)),
|
2021-08-10 21:08:45 +02:00
|
|
|
_timeline(std::make_unique<ClassicTimeline>(_note_manager)),
|
2021-08-05 20:59:48 +02:00
|
|
|
_music(std::move(music)),
|
|
|
|
_is_paused(false)
|
2021-05-31 19:04:16 +02:00
|
|
|
{
|
2021-06-17 21:13:25 +02:00
|
|
|
_slap_buffer.loadFromFile("very-final-slap.wav");
|
|
|
|
_slap.setBuffer(_slap_buffer);
|
|
|
|
_slap.setVolume(50);
|
|
|
|
|
2021-05-31 19:04:16 +02:00
|
|
|
_keys_to_buttons =
|
|
|
|
{
|
2021-06-23 21:18:33 +02: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 19:04:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_pressed_actions=
|
|
|
|
{
|
2021-06-23 21:18:33 +02:00
|
|
|
{Type::UP, Action::PRESS_UP},
|
|
|
|
{Type::RIGHT, Action::PRESS_RIGHT},
|
|
|
|
{Type::DOWN, Action::PRESS_DOWN},
|
|
|
|
{Type::LEFT, Action::PRESS_LEFT},
|
2021-05-31 19:04:16 +02:00
|
|
|
|
2021-06-23 21:18:33 +02:00
|
|
|
{Type::SLIDER_RIGHT, Action::PRESS_SLIDER_RIGHT},
|
|
|
|
{Type::SLIDER_LEFT, Action::PRESS_SLIDER_LEFT}
|
2021-05-31 19:04:16 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
_buttons_to_released_actions=
|
|
|
|
{
|
2021-06-23 21:18:33 +02:00
|
|
|
{Type::UP, Action::RELEASE_UP},
|
|
|
|
{Type::RIGHT, Action::RELEASE_RIGHT},
|
|
|
|
{Type::DOWN, Action::RELEASE_DOWN},
|
|
|
|
{Type::LEFT, Action::RELEASE_LEFT},
|
2021-05-31 19:04:16 +02:00
|
|
|
|
2021-06-23 21:18:33 +02:00
|
|
|
{Type::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
|
|
|
|
{Type::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
|
2021-05-31 19:04:16 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2021-06-09 20:08:58 +02:00
|
|
|
ClassicGame::~ClassicGame()
|
|
|
|
{}
|
|
|
|
|
2021-05-31 19:04:16 +02:00
|
|
|
void ClassicGame::run()
|
|
|
|
{
|
2021-06-23 21:18:33 +02:00
|
|
|
ClassicMapCreator creator(_graphics_manager);
|
|
|
|
auto beatmap = creator.createBeatmap("aa");
|
2021-08-05 20:59:48 +02:00
|
|
|
_music->openFromFile("METEOR.flac");
|
|
|
|
_music->setVolume(10);
|
|
|
|
_music->play();
|
2021-08-10 21:08:45 +02:00
|
|
|
_timeline->setNotes(std::move(beatmap.notes), beatmap.visibility_offset);
|
2021-05-31 19:04:16 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 21:18:33 +02:00
|
|
|
void ClassicGame::input(PlayerInput&& inputdata)
|
2021-05-31 19:04:16 +02:00
|
|
|
{
|
2021-08-05 20:59:48 +02:00
|
|
|
inputdata.timestamp = _music->fetchOffset();
|
2021-05-31 19:04:16 +02:00
|
|
|
|
2021-06-23 21:18:33 +02:00
|
|
|
switch (inputdata.event.type)
|
2021-05-31 19:04:16 +02:00
|
|
|
{
|
|
|
|
default:
|
2021-06-11 18:58:44 +02:00
|
|
|
return;
|
2021-07-21 20:15:56 +02:00
|
|
|
break;
|
|
|
|
|
2021-05-31 19:04:16 +02:00
|
|
|
case sf::Event::KeyPressed:
|
2021-07-21 20:15:56 +02:00
|
|
|
{
|
2021-08-05 20:59:48 +02:00
|
|
|
if (inputdata.event.key.code == sf::Keyboard::Space)
|
|
|
|
{
|
|
|
|
if (!_is_paused)
|
|
|
|
{
|
|
|
|
_is_paused = true;
|
|
|
|
_music->pause();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_is_paused = false;
|
|
|
|
_music->play();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-07-21 20:15:56 +02:00
|
|
|
auto note_it = _timeline->getActiveNote();
|
|
|
|
|
|
|
|
if (!_timeline->isExpired(note_it))
|
2021-05-31 19:04:16 +02:00
|
|
|
{
|
2021-07-21 20:15:56 +02:00
|
|
|
auto note = (*note_it);
|
2021-08-09 20:59:40 +02:00
|
|
|
_note_manager->input(note, std::move(inputdata));
|
2021-07-21 20:15:56 +02:00
|
|
|
_slap.play();
|
2021-06-23 21:18:33 +02:00
|
|
|
|
2021-08-09 20:59:40 +02:00
|
|
|
if (note->hold && _note_manager->allElementsPressed(note)) // also check for Type
|
2021-06-23 21:18:33 +02:00
|
|
|
{
|
2021-07-21 20:15:56 +02:00
|
|
|
_notes_on_hold.emplace_back(note);
|
|
|
|
std::cout << "HOLD initited by " << inputdata.event.key.code << '\n';
|
2021-06-23 21:18:33 +02:00
|
|
|
}
|
2021-05-31 19:04:16 +02:00
|
|
|
}
|
2021-07-21 20:15:56 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case sf::Event::KeyReleased:
|
|
|
|
{
|
2021-08-10 21:08:45 +02:00
|
|
|
const auto& note_manager = _note_manager;
|
2021-07-21 20:15:56 +02:00
|
|
|
bool key_match = std::any_of(_notes_on_hold.begin(), _notes_on_hold.end(),
|
2021-08-10 21:08:45 +02:00
|
|
|
[¬e_manager, key=inputdata.event.key.code](const auto& note)
|
2021-07-21 20:15:56 +02:00
|
|
|
{
|
2021-08-10 21:08:45 +02:00
|
|
|
return note_manager->isPressedAs(note, key);
|
2021-07-21 20:15:56 +02:00
|
|
|
});
|
|
|
|
|
|
|
|
if (key_match)
|
|
|
|
{
|
|
|
|
_notes_on_hold.clear();
|
|
|
|
std::cout << "HOLD released by " << inputdata.event.key.code << '\n';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-05-31 19:04:16 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ClassicGame::update()
|
|
|
|
{
|
2021-08-05 20:59:48 +02:00
|
|
|
_timeline->update(_music->fetchOffset());
|
2021-06-23 21:18:33 +02:00
|
|
|
_timeline->fetchVisibleNotes();
|
2021-05-31 19:04:16 +02:00
|
|
|
}
|
|
|
|
|
2021-06-23 21:18:33 +02:00
|
|
|
void ClassicGame::draw() const
|
2021-05-28 19:50:57 +02:00
|
|
|
{
|
2021-06-23 21:18:33 +02:00
|
|
|
_timeline->drawVisibleNotes();
|
2021-05-28 19:50:57 +02:00
|
|
|
}
|