void World::update(sf::Time dt)
{
	// Scroll the world, reset player velocity
	mWorldView.move(0.f, mScrollSpeed * dt.asSeconds() * mScrollSpeedCompensation);	

	FOREACH(Aircraft* a, mPlayerAircrafts)
		a->setVelocity(0.f, 0.f);

	// Setup commands to destroy entities, and guide missiles
	destroyEntitiesOutsideView();
	guideMissiles();

	// Forward commands to scene graph, adapt velocity (scrolling, diagonal correction)
	while (!mCommandQueue.isEmpty())
		mSceneGraph.onCommand(mCommandQueue.pop(), dt);

	adaptPlayerVelocity();

	// Collision detection and response (may destroy entities)
	handleCollisions();

	// Remove aircrafts that were destroyed (World::removeWrecks() only destroys the entities, not the pointers in mPlayerAircraft)
	auto firstToRemove = std::remove_if(mPlayerAircrafts.begin(), mPlayerAircrafts.end(), std::mem_fn(&Aircraft::isMarkedForRemoval));
	mPlayerAircrafts.erase(firstToRemove, mPlayerAircrafts.end());

	// Remove all destroyed entities, create new ones
	mSceneGraph.removeWrecks();
	spawnEnemies();

	// Regular update step, adapt position (correct if outside view)
	mSceneGraph.update(dt, mCommandQueue);
	adaptPlayerPosition();

	updateSounds();
}
Example #2
0
void World::update(sf::Time dt)
{
	// Scroll the world, reset player velocity
	mWorldView.move(0.f, mScrollSpeed * dt.asSeconds());	
	mPlayerAircraft->setVelocity(0.f, 0.f);

	// Setup commands to destroy entities, and guide missiles
	destroyEntitiesOutsideView();
	guideMissiles();

	// Forward commands to scene graph, adapt velocity (scrolling, diagonal correction)
	while (!mCommandQueue.isEmpty())
		mSceneGraph.onCommand(mCommandQueue.pop(), dt);
	adaptPlayerVelocity();

	// Collision detection and response (may destroy entities)
	handleCollisions();

	// Remove all destroyed entities, create new ones
	mSceneGraph.removeWrecks();
	spawnEnemies();

	// Regular update step, adapt position (correct if outside view)
	mSceneGraph.update(dt, mCommandQueue);
	adaptPlayerPosition();

	updateSounds();
}
Example #3
0
void
World::update( sf::Time dt ) {
    mWorldView.move(
        0.0f,
        mScrollSpeed * dt.asSeconds() * mScrollSpeedCompensation
    );

    for ( Aircraft* a : mPlayerAircrafts ) {
        a->SetVelocity( 0.0f, 0.0f );
    }

    destroyEntitiesOutsideView();
    guideMissiles();

    while ( !mCommandQueue.isEmpty() ) {
        mSceneGraph.OnCommand( mCommandQueue.pop(), dt );
    }

    adaptPlayerVelocity();
    handleCollisions();

    // Remove aircrafts that were destroyed
    // (World::removeWrecks() only destroys the entities,
    // not the pointers in mPlayerAircrafts)
    auto firstToRemove = std::remove_if(
        mPlayerAircrafts.begin(),
        mPlayerAircrafts.end(),
        std::mem_fn( &Aircraft::IsMarkedForRemoval )
    );
    mPlayerAircrafts.erase( firstToRemove, mPlayerAircrafts.end() );

    mSceneGraph.RemoveWrecks();
    spawnEnemies();

    mSceneGraph.Update( dt, mCommandQueue );
    adaptPlayerPosition();

    updateSounds();
}
Example #4
0
void World::update(sf::Time dt)
{
    mWorldView.move(0.f, dt.asSeconds() * mScrollSpeed);
    mPlayerAircraft->setVelocity(0.f, 0.f);
    destoryEntitiesOutOfView();
    guideMissiles();
    
    updateScore();
    // onCommand
    while (!mCommandQueue.isEmpty())
        mSceneGraph.onCommand(mCommandQueue.pop(), dt);
    
    // handles the diagonal velocity
    sf::Vector2f velocity = mPlayerAircraft->getVelocity();
    if (velocity.x != 0.f && velocity.y != 0.f)
        mPlayerAircraft->setVelocity(velocity / std::sqrt(2.f));
    
    mPlayerAircraft->accelerate(0.f, mScrollSpeed);
    
    // handles the cases when aircraft reaches boundaries
    sf::FloatRect viewBounds(mWorldView.getCenter() - mWorldView.getSize() / 2.f,
                             mWorldView.getSize());
    const float borderDistance = 40.f;
    sf::Vector2f position = mPlayerAircraft->getPosition();
    position.x = std::max(position.x, viewBounds.left + borderDistance);
    position.x = std::min(position.x, viewBounds.left + viewBounds.width - borderDistance);
    position.y = std::min(position.y, viewBounds.top  + viewBounds.height - borderDistance -20.f);
    position.y = std::max(position.y, viewBounds.top +borderDistance);
    mPlayerAircraft->setPosition(position);
    
    ///////////////////
    handleCollision();
    mSceneGraph.removeWrecks();
    spawnEnemies();
    mSceneGraph.update(dt, mCommandQueue);
}