Esempio n. 1
0
void Aircraft::checkProjectileLaunch(sf::Time dt, CommandQueue& commands)
{
	// Enemies try to fire all the time
	if (!isAllied())
		fire();

	// Check for automatic gunfire, allow only in intervals
	if (mIsFiring && mFireCountdown <= sf::Time::Zero)
	{
		// Interval expired: We can fire a new bullet
		commands.push(mFireCommand);
		mFireCountdown += Table[mType].fireInterval / (mFireRateLevel + 1.f);
		mIsFiring = false;
	}
	else if (mFireCountdown > sf::Time::Zero)
	{
		// Interval not expired: Decrease it further
		mFireCountdown -= dt;
		mIsFiring = false;
	}

	// Check for missile launch
	if (mIsLaunchingMissile)
	{
		commands.push(mMissileCommand);
		mIsLaunchingMissile = false;
	}
}
Esempio n. 2
0
void Tile::updateCurrent(sf::Time dt, CommandQueue& commands)
{
	// Entity has been destroyed: Possibly drop pickup, mark for removal
	if (isDestroyed())
	{
		checkPickupDrop(commands);
		mExplosion.update(dt);
		// Play explosion sound only once
		if (!mExplosionBegan)
		{
			// Play sound effect
			SoundEffect::ID soundEffect = (randomInt(2) == 0) ? SoundEffect::Explosion1 : SoundEffect::Explosion2;
			playLocalSound(commands, soundEffect);

			// Emit network game action for explosions
			if (isBlock())
			{
				sf::Vector2f position = getWorldPosition();

				Command command;
				command.category = Category::Network;
				command.action = derivedAction<NetworkNode>([position] (NetworkNode& node, sf::Time)
															{
																node.notifyGameAction(GameActions::EnemyExplode, position);
															});

				commands.push(command);
				mExplosionBegan = true;
			}
		}
		return;
	}

	Entity::updateCurrent(dt, commands);
}
Esempio n. 3
0
void Player::updateInput(CommandQueue &command_queue)
{
	if (keyboard_works == true)
	for (auto &itr : key_to_action)
	{
		//If the key is pressed add to the set. If not then delete from the set.
		//If it's a new key then refresh the last_key_pressed and current_action
		if (sf::Keyboard::isKeyPressed(itr.first)) 
		{
			auto key = keys_pressed.find(itr.first);
			if (key == keys_pressed.end())
			{
				current_action = key_to_action[itr.first];
				last_key_pressed = itr.first;
			}
			keys_pressed.insert(itr.first);
		}
		else
		{
			auto key = keys_pressed.find(itr.first);
			if (key != keys_pressed.end()) keys_pressed.erase(itr.first);
		}
	}


	if(last_key_pressed != 0 && keyboard_works == true)
		command_queue.push(action_to_command[current_action]);
	//command_queue.push(action_to_command[key_to_action[last_key_pressed]]);
}
Esempio n. 4
0
void Player::handleEvent(const sf::Event& event, CommandQueue& commands)
{
    // event souris
    if (event.type == sf::Event::KeyPressed)
    {
         auto found = m_keyBinding.find(event.key.code);
            if (found != m_keyBinding.end() && !isRealtimeAction(found->second))
                commands.push(m_actionBinding[found->second]);
    }
    else if(event.type == sf::Event::MouseButtonPressed)
    {
        auto found = m_mouseBinding.find(event.mouseButton.button);
            if (found != m_mouseBinding.end() && !isRealtimeAction(found->second))
                commands.push(m_actionBinding[found->second]);
    }
}
Esempio n. 5
0
bool Dispatcher::dispatchCommand( Command& command )
{
    EQVERB << "dispatch " << command << " on " << base::className( this )
           << std::endl;

    const uint32_t which = command->command;
#ifndef NDEBUG
    if( which >= _qTable.size( ))
    {
        EQABORT( "Command " << command
                 << " higher than number of registered command handlers ("
                 << _qTable.size() << ") for object of type "
                 << base::className( this ) << std::endl );
        return false;
    }
#endif

    CommandQueue* queue = _qTable[which];
    if( queue )
    {
        command.setDispatchFunction( _fTable[which] );
        queue->push( command );
        return true;
    }
    // else

    EQCHECK( _fTable[which]( command ));
    return true;
}
Esempio n. 6
0
bool Dispatcher::dispatchCommand( ICommand& command )
{
    LBASSERT( command.isValid( ));

    LBVERB << "dispatch " << command << " on " << lunchbox::className( this )
           << std::endl;

    const uint32_t which = command.getCommand();
#ifndef NDEBUG
    if( which >= _impl->qTable.size( ))
    {
        LBABORT( "ICommand " << command
                 << " higher than number of registered command handlers ("
                 << _impl->qTable.size() << ") for object of type "
                 << lunchbox::className( this ) << std::endl );
        return false;
    }
#endif

    CommandQueue* queue = _impl->qTable[ which ];
    if( queue )
    {
        command.setDispatchFunction( _impl->fTable[ which ] );
        queue->push( command );
        return true;
    }
    // else

    LBCHECK( _impl->fTable[ which ]( command ));
    return true;
}
void Aircraft::checkPickupDrop(CommandQueue& commands)
{
	if (!isAllied() && randomInt(3) == 0 && !mSpawnedPickup)
		commands.push(mDropPickupCommand);

	mSpawnedPickup = true;
}
Esempio n. 8
0
void Entity::playLocalSound(CommandQueue &commands, Sounds::ID sound)
{
    Command command;
    command.category = Category::SoundEffect;
    command.action = derivedAction<SoundNode>(std::bind(&SoundNode::playSound, std::placeholders::_1, sound, getWorldPosition()));

    commands.push(command);
}
Esempio n. 9
0
void Player::handleRealtimeInput(CommandQueue& commands)
{
    for (auto pair : mKeyBinding)
    {
        if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second))
            commands.push(mActionBinding[pair.second]);
    }
}
Esempio n. 10
0
void Player::handleEvent(const sf::Event& event, CommandQueue& commands) {
	if (event.type == sf::Event::KeyPressed) {
		// Commands happen when the player presses a key that corresponds with a command
		auto found = mKeyBinding.find(event.key.code);
		if (found != mKeyBinding.end() && !isRealtimeAction(found->second))
			commands.push(mActionBinding[found->second]);
	}
}
Esempio n. 11
0
void Player::handleRealtimeInput(CommandQueue& commands) {
	// Checks every key for a press
	for (auto pair : mKeyBinding) {
		// if something is pressed make sure to trigger command
		if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second))
			commands.push(mActionBinding[pair.second]);
	}
}
Esempio n. 12
0
void Player::handleRealTimeInput(CommandQueue& commands)
{
    // Traverse all assigned keys and check if they are pressed
    for (auto it = m_keyBinding.begin(); it!= m_keyBinding.end(); ++it)
    {
        // If key is pressed, lookup action and trigger corresponding command
        if (sf::Keyboard::isKeyPressed((*it).first) && isRealtimeAction((*it).second))
            commands.push(m_actionBinding[(*it).second]);
    }

    // Check if mouse button are pressed
    for (auto it = m_mouseBinding.begin(); it!= m_mouseBinding.end(); ++it)
    {
        // If key is pressed, lookup action and trigger corresponding command
        if (sf::Mouse::isButtonPressed((*it).first) && isRealtimeAction((*it).second))
            commands.push(m_actionBinding[(*it).second]);
    }
}
Esempio n. 13
0
void Tile::checkPickupDrop(CommandQueue& commands)
{
	// Drop pickup, if enemy airplane, with probability 1/4, if pickup not yet dropped
	// and if not in network mode (where pickups are dropped via packets)
	if (isBlock() && randomInt(5) == 0 && !mSpawnedPickup && mPickupsEnabled){
		commands.push(mDropPickupCommand);
	}
	mSpawnedPickup = true;
}
Esempio n. 14
0
void Player::handleRealTimeInput(CommandQueue& commands)
{
  for (auto pair : mKeyBinding)
  {
    // If key is pressed, lookup action and trigger corresponding command
    if (sf::Keyboard::isKeyPressed(pair.first) && isRealTimeAction(pair.second))
      commands.push(mActionBinding[pair.second]);
  }
  
}
Esempio n. 15
0
void Aircraft::checkProjectileLaunch(sf::Time delta, CommandQueue& commands)
{
  if (!isAllied()) fire();

  if (bFiring && mFireCountdown <= sf::Time::Zero) {
    commands.push(mFireCommand);
    mFireCountdown += sf::seconds(1.f / (mFireRateLevel + 1));
    bFiring = false;

    playLocalSound(commands, isAllied() ? SoundEffects::AlliedGunfire : SoundEffects::EnemyGunfire);
  } else if (mFireCountdown > sf::Time::Zero)
    mFireCountdown -= delta;

  if (bLaunchingMissile) {
    commands.push(mMissileCommand);
    bLaunchingMissile = false;
    playLocalSound(commands, SoundEffects::LaunchMissile);
  }
}
Esempio n. 16
0
File: Player.cpp Progetto: MVPet/JA
void Player::handleEvent(const sf::Event& event, CommandQueue& commands)
{
	if (event.type == sf::Event::KeyPressed)
	{
		// Check if pressed key appears in key binding, trigger command if so
		auto found = mKeyBinding.find(event.key.code);
		if (found != mKeyBinding.end() && !isRealtimeAction(found->second))
			commands.push(mActionBinding[found->second]);
	}
}
Esempio n. 17
0
File: Player.cpp Progetto: MVPet/JA
void Player::handleRealtimeInput(CommandQueue& commands)
{
	// Traverse all assigned keys and check if they are pressed
	for (auto pair : mKeyBinding)
	{
		// If key is pressed, lookup action and trigger corresponding command
		if (sf::Keyboard::isKeyPressed(pair.first) && isRealtimeAction(pair.second))
			commands.push(mActionBinding[pair.second]);
	}
}
Esempio n. 18
0
void Player::handleEvent(const sf::Event &event, CommandQueue &commands)
{
    if(event.type == sf::Event::KeyPressed)
    {
        auto found = mKeyBinding.find(event.key.code);
        if(found != mKeyBinding.end() && !isRealtimeAction(found->second))
        {
            commands.push(mActionBinding[found->second]);
        }
    }
}
Esempio n. 19
0
void Aircraft::playLocalSound(CommandQueue& commands, SoundEffects::Id effect)
{
  sf::Vector2f worldPosition = getPosition();

  Command command;
  command.category = Category::SoundEffect;
  command.action = derivedAction<SoundNode> ([effect, worldPosition] (SoundNode& node, sf::Time)
    {
      node.playSound(effect, worldPosition);
    } );

  commands.push(command);
}
Esempio n. 20
0
void Aircraft::checkProjectileLaunch(sf::Time dt, CommandQueue &commands)
{
    fire();
    if (mIsFiring && mFireCountdown <= sf::Time::Zero)
    {
        
        commands.push(mFireCommand);
        mFireCountdown += sf::seconds(1.f / (mFireRateLevel + 1.f));
        mIsFiring = false;
    }
    else if (mFireCountdown > sf::Time::Zero)
    {
        mFireCountdown -= dt;
        mIsFiring = false;
    }
    
    if (mIsLaunchMissile)
    {
        commands.push(mMissileCommand);
        mIsLaunchMissile = false;
    }
    
}
Esempio n. 21
0
void EmitterNode::updateCurrent(sf::Time dt, CommandQueue& commands) {
    if (mParticleSystem) { emitParticles(dt); }
    else {
        // Find particle node with the same type as emitter node
        auto finder = [this] (ParticleNode& container, sf::Time) {
            if (container.getParticleType() == mType)
                mParticleSystem = &container;
        };

        Command command;
        command.category = Category::ParticleSystem;
        command.action = derivedAction<ParticleNode>(finder);

        commands.push(command);
    }
}
Esempio n. 22
0
void Ship::checkProjectileLaunch(sf::Time dt, CommandQueue& commands)
{
	// Enemies try to fire all the time

	// Check for automatic gunfire, allow only in intervals
	if (_isFiring && _fireCountdown <= sf::Time::Zero)
	{
		// Interval expired: We can fire a new bullet
		commands.push(_fireCommand);
		_fireCountdown += Table[_type].fireInterval / (2.f);
		_isFiring = false;
	}
	else if (_fireCountdown > sf::Time::Zero)
	{
		// Interval not expired: Decrease it further
		_fireCountdown -= dt;
		_isFiring = false;
	}
}
Esempio n. 23
0
void EmitterNode::updateCurrent(sf::Time dt, CommandQueue& commands)
{
	if (particle_system)
	{
		emitParticles(dt);
	}
	else
	{
		auto finder = [this](ParticleNode& container, sf::Time)
		{
			if (container.getParticleType() == type)
				particle_system = &container;
		};

		Command command;
		command.category = Category::Particle;
		command.action = derivedAction<ParticleNode>(finder);

		commands.push(command);
	}
}
Esempio n. 24
0
void Creature::updateCurrent(sf::Time dt, CommandQueue &commands)
{
    updateAnimation(dt);

    if(isDestroyed() && !hasBeenSacrificed())
    {
        if(mEmitter)
        {
            mEmitter->update(dt, commands);
            mDestroyedSince += dt;
        }
        else
        {
            // blood
            std::unique_ptr<EmitterNode> e(new EmitterNode(Particle::Default));
            e->setPosition(sf::Vector2f(0.f, -32.f));
            mEmitter = e.get();
            attachChild(std::move(e));

            // text
            if(randomInt(4) == 0)
            {
                Command command;
                command.category = Category::UILayer;
                command.action = derivedAction<SceneNode>([this] (SceneNode& node, sf::Time) {
                    std::string str = StringTable[randomInt(StringTable.size())];
                    std::unique_ptr<CombatTextNode> tn(new CombatTextNode(str, mFonts));
                    tn->setPosition(sf::Vector2f(getPosition().x, getPosition().y-getBoundingRect().height/2));
                    node.attachChild(std::move(tn));
                });
                commands.push(command);
            }
        }
    }

    mAIController.update(commands, *this);
    Entity::updateCurrent(dt, commands);
}
Esempio n. 25
0
void UniversalEmitterNode::updateCurrent(sf::Time dt, CommandQueue& commands)
{
    if(mParticleSystem)
	{
	    if(mEnabled)
		{
	        if(mTimeBound)
		    {
		        mLifetime += dt;
			
			    if(mLifetime > mTotalLife)
			    {
			        mEnabled = false;
			    	return;
			    }
		    }
	        emitParticles(dt);
		}
	}
	else
	{
	    // Find particle node with the same type as emitter node
		auto finder = [this] (ParticleNode& container, sf::Time)
		{
		    if(container.getParticleType() == mType)
			{
			    mParticleSystem = &container;
			}
		};
		
		Command command;
		command.category = Category::ParticleSystem;
		command.action = derivedAction<ParticleNode>(finder);
		
		commands.push(command);
	}
}
Esempio n. 26
0
void WaveGenerator::popKid(CommandQueue& commands, int minIntel, float speed)
{
    Command cmd;
    cmd.category = Category::EntityLayer;
    cmd.action = [&,speed](SceneNode& node, sf::Time dt) {
        std::unique_ptr<BasicKidNode> kid(new BasicKidNode(mTextures, speed));
        if(randomInt(2) == 0)
        {
            int y = randomInt(8);
            kid->setPosition(toIsoCoord(0, y));
            kid->setGridPosition(sf::Vector2i(0, y));
        }
        else
        {
            int x = randomInt(7)+1;
            kid->setPosition(toIsoCoord(x, 0));
            kid->setGridPosition(sf::Vector2i(x, 0));
        }
        node.attachChild(std::move(kid));
    };
    commands.push(cmd);

    mNbKidPoped++;
}
Esempio n. 27
0
void WaveGenerator::updateCurrent(sf::Time dt, CommandQueue &commands)
{
    mWaveTimer += dt;

    switch(mWaveState)
    {
        case WaitInitTime:
        {
            if(!mGaveTraps)
            {
                Command cmd;
                cmd.category = Category::Traplist;
                cmd.action = derivedAction<TraplistNode>([&](TraplistNode& traps, sf::Time dt) {
                    if(mCurrentWaveIndex == 0)
                        traps.generateTraps(5);
                    else if(mCurrentWaveIndex == 1)
                        traps.generateTraps(mWaves[mCurrentWaveIndex].nbTraps);
                    else
                        traps.grantTrap(mWaves[mCurrentWaveIndex].nbTraps);
                });
                commands.push(cmd);

                // New Wave sound
                playLocalSound(commands, Sounds::NextWave);

                mGaveTraps = true;
            }

            if(mWaveTimer >= mWaves[mCurrentWaveIndex].initialWaitTime)
            {
                mWaveState = PopingAdds;
                mWaveTimer = sf::Time::Zero;

                if(mWaves[mCurrentWaveIndex].kidsToKill == 0)
                    mWaveState = WaitingTheEnd;
            }
        }
            break;

        case PopingAdds:
            if(mWaveTimer >= mWaves[mCurrentWaveIndex].repopTime)
            {
                popKid(commands, mWaves[mCurrentWaveIndex].minIntel, mWaves[mCurrentWaveIndex].kidSpeed);
                mWaveTimer = sf::Time::Zero;


                if(mNbKidPoped >= mWaves[mCurrentWaveIndex].kidsToKill)
                {
                    mWaveState = WaitingTheEnd;
                    mWaveTimer = sf::Time::Zero;
                }
            }
            break;

        case WaitingTheEnd:
            if(mKidsRemaining == 0 || mWaveTimer >= mWaves[mCurrentWaveIndex].waveTotalTime)
            {
                nextWave();
            }

        default:break;
    }
}
Esempio n. 28
0
void Aircraft::checkPickupDrop(CommandQueue& commands)
{
	if (!isAllied() && randomInt(3) == 0)
		commands.push(mDropPickupCommand);
}