Esempio n. 1
0
bool PauseState::HandleEvent(const sf::Event& event) {
    bool activeNextFrame = IsActive();
    
    if (activeNextFrame) {
        if (event.type == sf::Event::MouseButtonPressed
            && event.mouseButton.button == sf::Mouse::Left) {

            sf::Vector2i position = sf::Mouse::getPosition(*GetContext().window);            
            
            if (resumeButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackPop();
                SetActive(false);
            } else if (restartButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackClear();
                RequestStackPush(States::GAME);
                SetActive(false);
            } else if (exitButton.getGlobalBounds().contains(position.x, position.y)) {
                backwardClick->play();
                RequestStackClear();
                RequestStackPush(States::MENU);
                SetActive(false);
            }
        }
    }
    
    return activeNextFrame;
}
Esempio n. 2
0
MenuState::MenuState( StateStack & stack, Context context ) :
	State( stack, context ),
	pImpl( new Impl )
{
	pImpl->mBackgroundSprite.setTexture( context.pTextures->Get( Texture::TitleScreen ) );

	auto playButton = std::make_shared< GUI::Button >( context );
	playButton->setPosition( 100, 300 );
	playButton->SetText( "Play" );
	playButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::Loading );
	});

	auto hostPlayButton = std::make_shared<GUI::Button>( context );
	hostPlayButton->setPosition( 100, 350 );
	hostPlayButton->SetText( "Host" );
	hostPlayButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::HostGame );
	} );

	auto joinPlayButton = std::make_shared<GUI::Button>( context );
	joinPlayButton->setPosition( 100, 400 );
	joinPlayButton->SetText( "Join" );
	joinPlayButton->SetCallback( [this] ()
	{
		RequestStackPop();
		RequestStackPush( StateID::JoinGame );
	} );

	auto settingsButton = std::make_shared< GUI::Button >( context );
	settingsButton->setPosition( 100, 450 );
	settingsButton->SetText( "Settings" );
	settingsButton->SetCallback( [this] ()
	{
		RequestStackPush( StateID::Settings );
	});

	auto exitButton = std::make_shared< GUI::Button >( context );
	exitButton->setPosition( 100, 500 );
	exitButton->SetText( "Exit" );
	exitButton->SetCallback( [this] ()
	{
		RequestStackPop();
	});

	pImpl->mGUIContainer.Pack( playButton );
	pImpl->mGUIContainer.Pack( hostPlayButton );
	pImpl->mGUIContainer.Pack( joinPlayButton );
	pImpl->mGUIContainer.Pack( settingsButton );
	pImpl->mGUIContainer.Pack( exitButton );

	// Play menu theme
	//context.pMusic->Play( Music::MenuTheme );
}
Esempio n. 3
0
bool GameState::Update( sf::Time deltaTime )
{
	pImpl->mWorld.Update( deltaTime );

	if ( !pImpl->mWorld.HasAlivePlayer() )
	{
		pImpl->mPlayer.SetMissionStatus( Player::MissionStatus::Failure );
		RequestStackPush( StateID::GameOver );
	}
	else if ( pImpl->mWorld.HasPlayerReachedEnd() )
	{
		pImpl->mPlayer.SetMissionStatus( Player::MissionStatus::Success );
		RequestStackPush( StateID::MissionSuccess );
	}

	CommandQueue & commands = pImpl->mWorld.GetCommandQueue();
	pImpl->mPlayer.HandleRealtimeInput( commands );

	return true;
}
Esempio n. 4
0
bool GameState::HandleEvent( const sf::Event & event )
{
	CommandQueue & commands = pImpl->mWorld.GetCommandQueue();
	pImpl->mPlayer.HandleEvent( event, commands );

	// Escape pressed, trigger the pause screen
	if( ( event.type == sf::Event::KeyPressed && event.key.code == sf::Keyboard::Escape ) ||
		event.type == sf::Event::LostFocus )
	{
		RequestStackPush( StateID::Pause );
	}

	return true;
}
Esempio n. 5
0
bool LoadingState::Update( sf::Time deltaTime )
{
	if( pImpl->mLoadingTask.IsFinished() )
	{
		RequestStackPop();
		RequestStackPush( StateID::Game );
	}
	else
	{
		pImpl->SetCompletion( pImpl->mLoadingTask.GetCompletion() );
	}

	return true;
}