void Player::HandleEvent(const sf::Event& event, CommandQueue& commands) { if ( m_useJoystick ) { Command_t c; c.category = Category::PlayerAircraft; if ( event.type == sf::Event::JoystickButtonPressed ) { if ( event.joystickButton.button == 2) //if ( sf::Joystick::isButtonPressed( 0, 2 ) ) { // yes: shoot! c.action = DerivedAction<Creature>( []( Creature& a, sf::Time ){ a.LaunchMissile(); } ); commands.Push( c ); } } } else { if ( event.type == sf::Event::KeyPressed ) { // Check if pressed key appears in key binding, trigger command if so auto found = m_keyBinding.find( event.key.code ); if ( found != m_keyBinding.end() && !IsRealtimeAction( found->second ) ) commands.Push( m_actionBinding[found->second] ); } } }
void Player::HandleInput(CommandQueue & commands) { for (auto pair : keyBinding_) { if (sf::Keyboard::isKeyPressed(pair.first) && isRealTimeAction(pair.second)) { commands.Push(actionBinding_[pair.second]); } } }
void Player::HandleEvent(const sf::Event & event, CommandQueue & commands) { if (event.type == sf::Event::KeyPressed) { auto found = keyBinding_.find(event.key.code); if (found != keyBinding_.end() && !isRealTimeAction(found->second)) { commands.Push(actionBinding_[found->second]); } } }
void Player::HandleRealtimeInput(CommandQueue& commands) { if ( m_useJoystick ) { float x = sf::Joystick::getAxisPosition( 0, sf::Joystick::X ); float y = sf::Joystick::getAxisPosition( 0, sf::Joystick::Y ); Command_t c; c.category = Category::PlayerAircraft; if ( x > 1.0f ) { c.action = DerivedAction<Creature>( AircraftMover( +1.0, 0 ) ); commands.Push( c ); } else if ( x < -1.0f ) { c.action = DerivedAction<Creature>( AircraftMover( -1.0, 0 ) ); commands.Push( c ); } if ( y > 1.0f ) { c.action = DerivedAction<Creature>( AircraftMover( 0.0, +1.0 ) ); commands.Push( c ); } else if ( y < -1.0f ) { c.action = DerivedAction<Creature>( AircraftMover( 0.0, -1.0 ) ); commands.Push( c ); } if ( sf::Joystick::isButtonPressed( 0, 1 ) ) { // yes: shoot! c.action = DerivedAction<Creature>( []( Creature& a, sf::Time ){ a.Fire(); } ); commands.Push( c ); } } if ( !m_useJoystick ) { // Traverse all assigned keys and check if they are pressed for ( auto pair : m_keyBinding ) { // If key is pressed, lookup action and trigger corresponding command if ( sf::Keyboard::isKeyPressed( pair.first ) && IsRealtimeAction( pair.second ) ) commands.Push( m_actionBinding[pair.second] ); } } }
void EmitterNode::UpdateCurrent( sf::Time dt, CommandQueue & commands ) { if ( pImpl->mParticleSystem ) { pImpl->EmitParticles( dt ); } else { // Find particle node with the same type as emitter node auto finder = [this] ( ParticleNode& container, sf::Time ) { if ( container.GetParticleType() == pImpl->mType ) { pImpl->mParticleSystem = &container; } }; Command command; command.category = Category::ParticleSystem; command.action = derivedAction<ParticleNode>( finder ); commands.Push( command ); } }