project-kyoku/modes/classicmode/game/classicgame.cpp

130 lines
3.1 KiB
C++
Raw Normal View History

#include "classicgame.h"
2021-07-21 14:15:56 -04:00
#include "classicnote.h"
#include "classicmapcreator.h"
2021-10-04 11:30:21 -04:00
#include "holdmanager.h"
#include "context.h"
#include "tools/music.h"
ClassicGame::ClassicGame(std::shared_ptr<ClassicGraphicsManager>&& manager, std::unique_ptr<Music>&& music) :
_graphics_manager(std::move(manager)),
2021-10-04 11:30:21 -04:00
_hold_manager(std::make_shared<HoldManager>(_graphics_manager)),
_music(std::move(music)),
_is_paused(false)
2021-05-31 13:04:16 -04:00
{
2021-10-04 11:30:21 -04:00
_slap_buffer.loadFromFile("Tick.ogg");
_slap.setBuffer(_slap_buffer);
_slap.setVolume(50);
2021-05-31 13:04:16 -04:00
_keys_to_buttons =
{
{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=
{
{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
{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=
{
{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
{Type::SLIDER_RIGHT, Action::RELEASE_SLIDER_RIGHT},
{Type::SLIDER_LEFT, Action::RELEASE_SLIDER_LEFT}
2021-05-31 13:04:16 -04:00
};
}
ClassicGame::~ClassicGame()
{}
2021-05-31 13:04:16 -04:00
void ClassicGame::run()
{
2021-10-04 11:30:21 -04:00
const auto context = std::make_shared<Context>(Context{_graphics_manager, _hold_manager});
ClassicMapCreator creator(context);
auto beatmap = creator.createBeatmap("aa");
_music->openFromFile("METEOR.flac");
_music->setVolume(10);
_music->play();
_timeline.setNotes(beatmap.notes, beatmap.visibility_offset);
2021-05-31 13:04:16 -04:00
}
void ClassicGame::input(PlayerInput&& inputdata)
2021-05-31 13:04:16 -04:00
{
inputdata.timestamp = _music->fetchOffset();
2021-05-31 13:04:16 -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
{
if (inputdata.event.key.code == sf::Keyboard::Space)
{
if (!_is_paused)
{
_is_paused = true;
_music->pause();
return;
}
else
{
_is_paused = false;
_music->play();
return;
}
}
auto note_it = _timeline.getActiveNote();
2021-07-21 14:15:56 -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);
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
}
}
void ClassicGame::update()
{
_timeline.update(_music->fetchOffset());
_timeline.fetchVisibleNotes();
2021-05-31 13:04:16 -04:00
}
void ClassicGame::draw() const
{
_timeline.drawVisibleNotes();
}