Beispiel #1
0
void World::update(int ticks)
{
    removeDeadObjects(mRenderables);
    removeDeadObjects(mCollideables);

    mPlayer->update();
    if (!mPlayer->isAlive())
    {
        mPlayer->respawn(mSpawnPoint);
        mCollideables.push_back(mPlayer);
    }

    for (auto& obj : mCollideables)
    {
        obj->update();
        if (!obj->isStatic())
            obj->setVelocity(obj->getVelocity() + mGravity*(UPDATE_STEP.asSeconds()));
        if (obj->getPhysicsPosition().y > SCREEN_HEIGHT)
            obj->kill();
    }

    for (auto& obj : mRenderables)
    {
        if (obj->isParallaxable())
        {
            obj->setRenderPosition(obj->getRenderPosition() + sf::Vector2f(0.25f, 0.f));
            if (obj->getRenderPosition().x > SCREEN_WIDTH)
                obj->setRenderPosition(sf::Vector2f(-obj->getSpriteInfo().mHitBox.width, obj->getRenderPosition().y));
        }
    }

    // check collisions
    for (std::size_t x = 0; x < mCollideables.size(); x++)
    {
        for (std::size_t y = x+1; y < mCollideables.size(); y++)
        {
            auto dynamic = mCollideables[x];
            auto _static = mCollideables[y];

            if (!mCollideables[x]->isStatic())
                dynamic = mCollideables[x];
            else if (!mCollideables[y]->isStatic())
                dynamic = mCollideables[y];

            if (mCollideables[x]->isStatic())
                _static = mCollideables[x];
            else if (mCollideables[y]->isStatic())
                _static = mCollideables[y];

            if (dynamic != _static)
            {
                if (checkCollision(dynamic, _static) && dynamic->isCollisionActive() && _static->isCollisionActive())
                    resolveCollision(dynamic, _static);
            }
        }
    }

    mCamera.follow(sf::Vector2f(mPlayer->getRenderPosition().x, SCREEN_HEIGHT/2.f));
}
void ObjectStateUpdateSystem::update( GameData& mGameData, TimeData& time )
{
	removeDeadObjects(mGameData);
	
	updateShooting(mGameData);

	//spawn waves
	mWaveManager.update(mGameData, time.currentTime);

	//spawn from spawners
	//mGameData.spawnEnemiesInCurrentLevel(time.currentTime);


	updateObjectWithTTL(mGameData, time);
}