You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
999 B
C++
50 lines
999 B
C++
2 years ago
|
#include "application/gamestate.h"
|
||
|
#include "widgets/button.h"
|
||
|
#include "widgets/group.h"
|
||
|
|
||
|
#include "core/game.h"
|
||
|
|
||
|
GameState::GameState(const std::shared_ptr<kku::Game>& game, Callbacks&& callbacks) :
|
||
|
_game(game),
|
||
|
_onLeaveGameCallback(callbacks.onLeaveGame)
|
||
|
{}
|
||
|
|
||
|
void GameState::input(const kku::SystemEvent& event)
|
||
|
{
|
||
|
switch (event.type)
|
||
|
{
|
||
|
default:
|
||
|
break;
|
||
|
|
||
|
case kku::SystemEvent::Type::KeyRelease:
|
||
|
if (std::get<kku::SystemEvent::Key>(event.data).view == ' ')
|
||
|
_music->isPlaying() ? _music->pause() : _music->play();
|
||
|
}
|
||
|
|
||
|
_game->input(kku::GameEvent{_music->fetchOffset(), event});
|
||
|
}
|
||
|
|
||
|
void GameState::update(const kku::microsec& dt)
|
||
|
{
|
||
|
_game->update(kku::UpdateData{_music->fetchOffset(), dt});
|
||
|
}
|
||
|
|
||
|
void GameState::display() const
|
||
|
{
|
||
|
_game->display();
|
||
|
}
|
||
|
|
||
|
void GameState::enter()
|
||
|
{
|
||
|
_game->run();
|
||
|
|
||
|
_music->open("METEOR.flac");
|
||
|
_music->setVolume(10);
|
||
|
_music->play();
|
||
|
}
|
||
|
|
||
|
void GameState::leave()
|
||
|
{
|
||
|
_onLeaveGameCallback();
|
||
|
}
|