Beispiel #1
0
void Monster::update(const sf::Time & elapsed)
{
    c_LastAggroTime += elapsed;
    if(elapsed.asSeconds() < c_LostAggroTime && c_LastAggroTime.asSeconds() > c_LostAggroTime)
        c_LastAggroTime = sf::seconds(c_LostAggroTime);

    c_LastAtkTime += elapsed;
    if(elapsed.asSeconds() < c_DelayAtkTime && c_LastAtkTime.asSeconds() > c_DelayAtkTime)
        c_LastAtkTime = sf::seconds(c_DelayAtkTime);

    Living::update(elapsed);
}
Beispiel #2
0
NDistribution<sf::Time> uniform(sf::Time min, sf::Time max)
{
    assert(min <= max);

    const float floatMin = min.asSeconds();
    const float floatMax = max.asSeconds();

    return [=] () -> sf::Time
    {
        return sf::seconds(NMath::random(floatMin, floatMax));
    };
}
Beispiel #3
0
void cBkGrid::update(sf::Time dt)
{    
    mAccumulator += dt;
    if ( mAccumulator >= mTimer )
    {
        mAccumulator = sf::Time::Zero;
        adjustColor();
    }
    
    // Horizontal lines' velocity
    sf::Vector2f    dVhori { 0.0, mVelocity.y };
    dVhori *= dt.asSeconds();
    for (auto i = 0; i < gGridSize.y * 2; ++i)
    {
        mPoints[i].position += dVhori;
        
        if (mPoints[i].position.y < 0)
        {
            mPoints[i].position.y += mSize;
        }
        if (mPoints[i].position.y > mSize)
        {
            mPoints[i].position.y -= mSize;
        }
    }
    
    // Vertical lines' velocity
    sf::Vector2f    dVvert { mVelocity.x, 0.0 };
    dVvert *= dt.asSeconds();
    for (auto i = mFirstVline; i < gGridPointCount; ++i)
    {
        mPoints[i].position += dVvert;
        
        if (mPoints[i].position.x < 0)
        {
            mPoints[i].position.x += mSize;
        }
        if (mPoints[i].position.x > mSize)
        {
            mPoints[i].position.x -= mSize;
        }
    }
    
    // Now rotate
    mRot += mSpin * dt.asSeconds();
    if ( mRot < -360 ) mRot += 360;
    if ( mRot > 360 ) mRot -= 360;
    setRotation(mRot);
    
    // Adjust position
    setPosition(mHalfSize / 2.0, mHalfSize / 2.0);
}
Beispiel #4
0
void Entity::updateCurrent(sf::Time dt)
{
	if (hasFriction)
	{
		mVelocity.x *= FRICTION;
		mVelocity.y *= FRICTION;
	}
	if (hasGravity)
	{
		mVelocity.y += GRAVITY * dt.asSeconds();
	}
	move(mVelocity * dt.asSeconds());
}
Beispiel #5
0
void Player::update(const sf::Time& dt) {
	handleInput(dt);

	if (getPosition().x < 0) {
		move(m_speed * dt.asSeconds(), 0.0f);
	} else if (getPosition().x + getGlobalBounds().width > m_windowSize.x) {
		move(-m_speed * dt.asSeconds(), 0.0f);
	}

	m_spaceKey = sf::Keyboard::isKeyPressed(sf::Keyboard::Space);

	Entity::update(dt);
}
Beispiel #6
0
void SpeedupPullCamera::update(const sf::Time& frameTime)
{
	if (g_inputController->isKeyActive(Key::Up))
	{
		m_cameraTop -= CAMERA_SPEED_PER_S * frameTime.asSeconds();
		m_cameraCenter.y = m_cameraTop + (m_cameraWindowHeight / 2.f);
	}
	if (g_inputController->isKeyActive(Key::Down))
	{
		m_cameraTop += CAMERA_SPEED_PER_S * frameTime.asSeconds();
		m_cameraCenter.y = m_cameraTop + (m_cameraWindowHeight / 2.f);
	}
}
Beispiel #7
0
SoundManager::FadedMusic::FadedMusic(
    VFileMusic& music, float target, sf::Time fadeDuration):
    target(target),
    music(&music),
    increment(0)
{
    if (fadeDuration.asMicroseconds()) {
        music.setVolume(100 - target);
        increment = (target - music.getVolume()) / fadeDuration.asSeconds();
    } else {
        music.setVolume(target);
    }
}
Beispiel #8
0
void ParticleSystem::update(const sf::Time &dt) {
	if (emitRate > 0.0f) {
		emitWithRate(dt.asSeconds());
	}

	for (int i = 0; i < m_particles->countAlive; ++i) {
		m_particles->acc[i] = { 0.0f, 0.0f };
	}

	for (auto & updater : m_updaters) {
		updater->update(m_particles, dt.asSeconds());
	}
}
Beispiel #9
0
/*
 * Update
 */
void Bee::update(sf::Time dt)
{
	action(dt);
	move(dt);
	if(moveState_ == MoveState::REST){
		energy_ -= getConfig()["energy"]["consumption rates"]
		["idle"].toDouble()*dt.asSeconds();
	}else if(moveState_ == MoveState::TARGET ||
			 moveState_ == MoveState::RAND){
		energy_ -= getConfig()["energy"]["consumption rates"]
		["moving"].toDouble()*dt.asSeconds();
	}	
	if(energy_ <= 0){ throw energy_; }
}
void NotificationManager::update(sf::Time dt)
{
	if(notifications.size() == 0)
		return;

	sf::Text tmpText;
	tmpText.setCharacterSize(50);
	tmpText.setFont(NotificationFont);

	auto factor = (static_cast<float>(RenderWindow.getView().getSize().y) / RenderWindow.getSize().y);

	if(notifications[0].time > 0)
		notifications[0].time -= dt.asSeconds();					//Count down notification time
	else if(notifications[0].alpha - dt.asSeconds() * 150.f > 0)
		notifications[0].alpha -= dt.asSeconds() * 150.f;			//Hide notification
	else
		notifications.erase(this->notifications.begin());			//Delete notification

	for(auto i = 0u; i < notifications.size() && i < 5; i++)
	{
		/* Apply alpha to text and notification */
		tmpText.setFillColor
		({
			notificationTextColor.r,
			notificationTextColor.g,
			notificationTextColor.b,
			static_cast<sf::Uint8>(sfm::mapValue(notifications[i].alpha, 0.f, static_cast<float>(notificationBacgroundColor.a), 0.f, static_cast<float>(notificationTextColor.a)))
		 });
		notifications[i].background.setFillColor
		({
			notificationBacgroundColor.r,
			notificationBacgroundColor.g,
			notificationBacgroundColor.b,
			static_cast<sf::Uint8>(notifications[i].alpha)
		 });

		/* Set notification's background position */
		notifications[i].background.setScale(factor, factor);
		notifications[i].background.setPosition(RenderWindow.mapPixelToCoords({static_cast<int>(RenderWindow.getSize().x - 410), static_cast<int>(10 + i * 50)}));

		/* Set text parameters */
		tmpText.setScale(factor, factor);
		tmpText.setString(notifications[i].text);
		tmpText.setPosition(RenderWindow.mapPixelToCoords({static_cast<int>(RenderWindow.getSize().x - 410 + 10), static_cast<int>(10 + i * 50 - 15)}));

		/* Draw notification */
		RenderWindow.draw(notifications[i].background);
		RenderWindow.draw(tmpText);
	}
}
Beispiel #11
0
void Asteroid::Update(sf::Time Time)
{
	m_Position.y += 200.0f * Time.asSeconds();
	m_CollisionRect.top = static_cast<int> (m_Position.y);

	m_AsteroidAnimPhase += 10.0f * Time.asSeconds();

	if (m_AsteroidAnimPhase >= 20.0f)
		m_AsteroidAnimPhase -= 20.0f;

	if (m_Position.y > 600.0f)
		m_Alive = false;

}
Beispiel #12
0
void EnemyActor::update(const sf::Time& delta_t)
{
	Actor::update(delta_t);
	
	if(delta_t.asSeconds() == 0.0)
		return;
		
	if (getState() == EnemyActor::Patrol || getState() == EnemyActor::Follow)
		patrolTimer -= delta_t.asSeconds();
	if (getState() == EnemyActor::Patrol && patrolTimer <= 0.0) {
		setNeedSeek(true);
		patrolTimer = patrolTimerMin;
	}
}
void MonsterEntity::update(sf::Time delta) {
	timer += delta.asSeconds();
	if (timer > .5) {
		swapAppearance();
		timer = 0;
	}
	if (type == monster_flyer) {
		move(velocity * delta.asSeconds());
	} else if (type == monster_crawler) {
		velocity.y += (gravity.y * delta.asSeconds());
		velocity.x -= (gravity.y * delta.asSeconds());
		move(velocity * delta.asSeconds());
	}
}
Beispiel #14
0
void Car::update(const sf::Time & _time) {
    
    // keep location as last valid
    if (!this->mDriftedOffTrack) {
        this->mCurrentPassedDistance += length(this->mCurrentLocation - this->mLastLocation);
        this->mLastLocation = this->mCurrentLocation;
        
       // std::cout << "Passed Distance: " << this->mCurrentPassedDistance << std::endl;
    }
    
    // compute cars offset to the track segment and adjust it
    sf::Vector2f proj = project(this->mCurrentLocation, this->mTrack[this->mSegmentStart], this->mTrack[this->mSegmentEnd]);
    sf::Vector2f positionAdjust = proj - this->mCurrentLocation;
   
    // apply drag friction
    if (this->mVelocity > 0.0f) {
       // this->mForce -= abs(Car::FRICTION_FORCE * (this->mVelocity) * (this->mDriftedOffTrack ? Car::DRAG_FRICTION_OFF_TRACK : Car::DRAG_FRICTION_ON_TRACK));
        this->mForce -= abs(Car::FRICTION_FORCE * (this->mVelocity));
        this->mForce -= abs(this->mIsAccelerating ? 0.0f : Car::BREAK_FRICTION * this->mVelocity);
        this->mForce -= abs(!this->mDriftedOffTrack ? 0.0f : Car::DRAG_FRICTION_OFF_TRACK * this->mVelocity);
        
        this->mIsAccelerating = false;
    }
    
    // compute acceleration A = F / M
    float acceleration = this->mForce / Car::DEFAULT_MASS;
    
    // compute velocity
    this->mVelocity += acceleration * _time.asSeconds();
    this->mVelocity = fmax(fmin(this->mVelocity, Car::MAX_VELOCITY), 0.0f);
    //std::cout << "Velocity: " << this->mVelocity << std::endl;
        
    // compute new position
    this->mCurrentLocation += this->mCurrentDirection * (this->mVelocity * _time.asSeconds());
    this->mCurrentLocation += positionAdjust;
    
    this->keepOnTrack();
    this->updateGhosts();
    
    // compute rotation
    float angle = heading(this->mCurrentDirection);
    
    this->mCarDrawable.setRotation(RAD_TO_DEG(angle));
    this->mCarDrawable.setPosition(this->mCurrentLocation);
    
    // debug stuff
    this->mLocationPoint.setPosition(this->mCurrentLocation);
    this->mDirectionShape.setPosition(this->mCurrentLocation);
}
void GameStateGame::Update(const sf::Time& time)
{
    SharedContext* context = m_stateMgr->GetContext();
    EntityBase   * player  = context->entityManager->Find("Player");
    if (!player)
    {
        std::cout << "Respawning player..." << std::endl;
        context->entityManager->Add(EntityType::Player, "Player");
        player = context->entityManager->Find("Player");
        player->SetPosition(m_gameMap->GetPlayerStart());
        std::cout << "Player respawned..." << std::endl;
    }
    else
    {
        m_view.setCenter(player->GetPosition());
        context->window->GetRenderWindow()->setView(m_view);
    }

    sf::FloatRect viewSpace = context->window->GetViewSpace();

    if (viewSpace.left <= 0)
    {
        m_view.setCenter(viewSpace.width / 2.0f, m_view.getCenter().y);
        context->window->GetRenderWindow()->setView(m_view);
    }
    else if (viewSpace.left + viewSpace.width > (m_gameMap->GetMapSize().x) * TILE_SIZE)
    {
        m_view.setCenter(((m_gameMap->GetMapSize().x) * TILE_SIZE) - (viewSpace.width / 2.0f),
                         m_view.getCenter().y);
        context->window->GetRenderWindow()->setView(m_view);
    }

    if (viewSpace.top <= 0)
    {
        m_view.setCenter(m_view.getCenter().x, viewSpace.height / 2.0f);
        context->window->GetRenderWindow()->setView(m_view);
    }
    else if (viewSpace.top + viewSpace.height >
             (m_gameMap->GetMapSize().y) * TILE_SIZE)
    {
        m_view.setCenter(m_view.getCenter().x,
                         ((m_gameMap->GetMapSize().y) *
                          TILE_SIZE) - (viewSpace.height / 2.0f));
        context->window->GetRenderWindow()->setView(m_view);
    }

    m_gameMap->Update(time.asSeconds());
    m_stateMgr->GetContext()->entityManager->Update(time.asSeconds());
}
Beispiel #16
0
void Link::update(sf::Time dt)
{
    if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerLeft->toBinding().Key))
        move(-64*dt.asSeconds(), 0);
    if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerRight->toBinding().Key))
        move(+64*dt.asSeconds(), 0);
    if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerUp->toBinding().Key))
        move(0, -64*dt.asSeconds());
    if (sEngineRef().inputManager().keyboard().isKeyDown(imp_playerDown->toBinding().Key))
        move(0, +64*dt.asSeconds());

    Player::update(dt);
    m_currentSprite->setPosition(m_pos);
    m_currentSprite->update(dt);
}
Beispiel #17
0
void Spit_projectile::Update(sf::Time DeltaTime){

	grav += gravity * DeltaTime.asSeconds();

	m_Sprite.move(direction.x * speed * DeltaTime.asSeconds(), direction.y * speed * DeltaTime.asSeconds() + grav*DeltaTime.asSeconds() - distGY*DeltaTime.asSeconds());


	if(this->checkCollisionPointInRadie(m_Sprite.getPosition(), player)){
		player->takeDamage();
		deleteMe = true;
	}

	spitAnim.update();

}
Beispiel #18
0
void Paddle::update(sf::Time& dt){
	atEdge();
	
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::Right) && !(_atRight)){
		_atLeft = false;
		float delta = dt.asSeconds() * _xVel;
		_paddle.move(delta, 0);
	}
	
	if(sf::Keyboard::isKeyPressed(sf::Keyboard::Left) && !(_atLeft)){
		_atRight = false;
		float delta = dt.asSeconds() * _xVel;
		_paddle.move(-delta, 0);
	}
}
Beispiel #19
0
void GameObject::updatePosition(sf::Time elapsedTime)
{
    sf::Vector2f acceleration(resultantForce.x / mass, resultantForce.y / mass);

    //calculate velocity
    sf::Vector2f newVelocity = velocity + acceleration*elapsedTime.asSeconds();
    float newVelocityLen = ezo::vecLength(newVelocity.x, newVelocity.y);
    if(newVelocityLen > maxVelocity)
        velocity = {newVelocity.x/newVelocityLen*maxVelocity, newVelocity.y/newVelocityLen*maxVelocity};
    else
        velocity = newVelocity;

    oldPosition = representation.getPosition();
    representation.setPosition(representation.getPosition() + velocity*elapsedTime.asSeconds());
}
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();
}
void WaveController::update(sf::Time const& elapsedTime) {
	mTimeSinceWave += elapsedTime.asSeconds();

	if (!mWaveQueue.empty() && isTimeToSpawnWave()) {
		spawnWave();
	}
}
Beispiel #22
0
AppLayer::Status Battle::tick(std::vector<sf::Event> &e, const sf::Time &t, sf::Vector2f m)
{
    //Process events
    for (unsigned i = 0; i < e.size(); i++) {
        //Keyboard events
        if (e[i].type == sf::Event::KeyPressed) {
            bool esc = controller.pressing(GameController::K_ESCAPE, e[i].key.code);

            if (esc) {
                Layer::pauseBattle();
                return AppLayer::HALT;
            }
        }
    }

    //Adjust mouse position relative to map (camera)
    sf::Vector2f hsize = sf::Vector2f(camera.getSize().x/2, camera.getSize().y/2);
    m += camera.getCenter() - hsize;

    //Direct level transition
    if (m_transitioning) {
        m_transitionDuration -= t.asSeconds();
        if (m_transitionDuration <= 0) {
            endLevelTransition();
        }
        else {
            float alpha = 1.f - m_transitionDuration / 1.5f; 
            alpha *= alpha*10*alpha;
            gAgent->setTransition(alpha);
            hAgent->setTransition(alpha);
        }
    }

    //Progress components
    mAgent->updateState(t, m);
    gAgent->updateState(mAgent->getBattleState());
    hAgent->updateState(mAgent->getBattleState());
    
    //Update camera
    sf::Vector2f map = mAgent->getBattleState().map;
    sf::Vector2f pos = mAgent->getBattleState().player->getPos();
    if (pos.x < hsize.x) pos.x = hsize.x;
    else if (pos.x > map.x - hsize.x) pos.x = map.x - hsize.x;
    if (pos.y < hsize.y) pos.y = hsize.y;
    else if (pos.y > map.y - hsize.y) pos.y = map.y - hsize.y;
    camera.setCenter(pos);

    //Check for end conditions
    if (mAgent->isPlayerDead()) {
        Layer::back();
    }
    else if (!m_scoring && mAgent->isLevelDone()) {
        m_scoring = true;
        mAgent->saveLevelStats();
        mAgent->clearEnemyProjectiles();
        Layer::goToScoreScreen();
    }
    
    return AppLayer::HALT;
}
Beispiel #23
0
void Projectile::moveProjectile(sf::Time dt)
{
	sf::Vector2f pos = getPosition();

	if (bHasTarget) {

		if (!reachedTarget) {
		
			fDistance = sqrt(pow(targetPos.x - pos.x,2) + pow(targetPos.y - pos.y,2));

			//Calculate new velocity
			velocity.x = getSpeed() * (targetPos.x - pos.x) / fDistance;
			velocity.y = getSpeed() * (targetPos.y - pos.y) / fDistance; 

			if (fDistance > -1 && fDistance < 1)
			{
				reachedTarget = true;
				resetVelocity();
			}
		
		}
	}

	//Rotate to face the target
	float dx = targetPos.x - pos.x;
	float dy = targetPos.y - pos.y;
	const float Pi = 3.141;

	setRotation(atan2(dy,dx) * (180 / Pi) + 90); //Calculates rotation


	move(getVelocity() * dt.asSeconds());
}
Beispiel #24
0
void World::update(sf::Time dt)
{
    mWorldView.move(0.f, mScrollSpeed * dt.asSeconds());
    mPlayerAircraft->setVelocity(0.f, 0.f);
    
    // Forward commands to the scene graph
    while (!mCommandQueue.isEmpty())
        mSceneGraph.onCommand(mCommandQueue.pop(), dt);

    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);

    // Regular update step
    mSceneGraph.update(dt);

    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::max(position.y, viewBounds.top + borderDistance);
    position.y = std::min(position.y, viewBounds.top + viewBounds.height - borderDistance);
    mPlayerAircraft->setPosition(position);
}
Beispiel #25
0
void updateView(sf::View& view, sf::Time& deltaTime) {
	float dx = 0;
	float dy = 0;

	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Left) || sf::Keyboard::isKeyPressed(sf::Keyboard::A)) {
		dx -= 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Right) || sf::Keyboard::isKeyPressed(sf::Keyboard::D)) {
		dx += 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Up) || sf::Keyboard::isKeyPressed(sf::Keyboard::W)) {
		dy -= 1;
	}
	if (sf::Keyboard::isKeyPressed(sf::Keyboard::Down) || sf::Keyboard::isKeyPressed(sf::Keyboard::S)) {
		dy += 1;
	}

	float moveSpeed = 1000;
	float timeSeconds = deltaTime.asSeconds();

	float dd = dx * dx + dy * dy;
	if (dd != 0) {
		dd = sqrt(dd);
		dx /= dd;
		dy /= dd;
	}

	dx *= moveSpeed;
	dy *= moveSpeed;

	view.move(dx * timeSeconds, dy * timeSeconds);
}
Beispiel #26
0
string formattedDuration(sf::Time time, unsigned int nb_dec)
{
    float secondsF = time.asSeconds();

    int s = (int) secondsF;
    int tot_s = s;

    int d = s/86400;
    s -= d*86400;
    int h = s/3600;
    s -= h*3600;
    int m = s/60;
    s -= m*60;

    string str = "";
    if (d>0)
        str += to_string(d) + "j ";
    if (h>0 || d>0)
        str += to_string(h, 2) + "h ";
    if (m>0 || h>0 || d>0)
        str += to_string(m, 2) + "m ";
    str += to_string(s, 2);

    if (nb_dec > 0)
    {
        int subsec = secondsF * pow(10.0, (double) nb_dec) - tot_s * pow(10.0, (double) nb_dec);
        str += "." + to_string(subsec, nb_dec);
    }
    str += "s";

    return str;
}
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();
}
void Player::Animate(sf::Time &deltaTime)
{
    if(m_isMovingRight || m_isMovingLeft)
    {
        frameCounter += frameSpeed * deltaTime.asMilliseconds() * 0.001;
        if(frameCounter >= switchFrame)
        {
            frameCounter = 0;
            source.x++;
            if(source.x * 32 >= 32*3)
                source.x = 0;
        }
    }

    if(m_isMovingRight)
        source.y = 2; //source corresponds with .png
    else if(m_isMovingLeft)
        source.y = 1;
    else if(m_onGround)
    {
        source.y = 0;
        source.x = 1;
    }
    else if(!m_onGround)
    {
        //source.y = 3; Take out the looking back while falling: Quality of life change for CHRIS ZITNIK - WHAT A GUY
        source.y = 0;
        source.x = 1;
    }

    m_sprite.setTextureRect(sf::IntRect(source.x * 32, source.y * 32, 32, 32)); //make sure that texture is 32!!
}
Beispiel #29
0
	void HUD::update(float p_fDeltaTime, sf::Time p_xTimer)
	{
		if (m_xPlayerObject->getCurWep() == 1)
		{
			m_xRightLargeCircleItem = m_xRightLargeCircleBaton;
		}
		else if (m_xPlayerObject->getCurWep() == 2)
		{
			m_xRightLargeCircleItem = m_xRightLargeCircleGun;
		}
		else if (m_xPlayerObject->getCurWep() == 0)
		{
			m_xRightLargeCircleItem = m_xRightLargeCircleGarotte;
		}

		sf::Vector2f screensize(1920, 1080);

		m_xLeftSmallCircle->setPosition(m_xView->getCenter() + sf::Vector2f(3, 675) - screensize / 2.f);
		m_xLeftSmallCircleItem->setPosition(m_xView->getCenter() + sf::Vector2f(50, 732) - screensize / 2.f);

		m_xRightLargeCircle->setPosition(m_xView->getCenter() + sf::Vector2f(1690, 847) - screensize / 2.f);
		m_xRightLargeCircleItem->setPosition(m_xView->getCenter() + sf::Vector2f(1690, 847) - screensize / 2.f);

		m_xLeftLargeCircle->setPosition(m_xView->getCenter() + sf::Vector2f(3, 847) - screensize / 2.f);
		m_xLeftLargeCircleItem->setPosition(m_xView->getCenter() + sf::Vector2f(3, 847) - screensize / 2.f);

		std::stringstream sstream;

		sstream << (int)p_xTimer.asSeconds();

		m_xText->setString(sstream.str());
		m_xText->setPosition(m_xView->getCenter() + sf::Vector2f(1920/2 - 20, 50) - screensize / 2.f);
	}
void MovableGameObject::calculateNextPosition(const sf::Time& frameTime, sf::Vector2f& nextPos) const {
	sf::Vector2f position = getPosition();
	sf::Vector2f nextVel;
	calculateNextVelocity(frameTime, nextVel);
	nextPos.x = position.x + (nextVel.x + m_relativeVelocity.x) * frameTime.asSeconds();
	nextPos.y = position.y + (nextVel.y + m_relativeVelocity.y) * frameTime.asSeconds();
}