Esempio n. 1
0
void AccelerateAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime)
{
	// basic physics
	// v = a t
	// d = v t
	// d = 1/2 a t^2
	// delta_d = 1/2 a t^2 - 1/2 a (t-delta_t)^2    : 6 *, 2 -
	// alternate forms (thanks to wolfram alpha)
	// delta_d = -1/2 a delta_t (delta_t - 2 t)     : 4 *, 1 - (using this one)
	// delta_d = a delta_t t - (a delta_t^2)/2      : 4 *, 1 /, 1 -
	// delta_d = 1/2 a delta_t (2 t - delta_t)      : 4 *, 1 -

	elapsedTime += deltaTime;
	double delta_t = deltaTime.realSeconds();
	double t = elapsedTime.realSeconds();
	Point position = target->position();
	currentSpeed = t * yPixelsPerSecondSquared;
	if( (useMaxSpeed && (currentSpeed <= maxSpd)) || (!useMaxSpeed))
	{
		position.y() += -.5 * yPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);
	}
	else
	{
		position.y() += maxSpd *delta_t;
	}

	position.x() += -.5 * xPixelsPerSecondSquared * delta_t * (delta_t - 2 * t);

	target->setPosition(position);
}
Esempio n. 2
0
	void OpponentAI::interactWithOtherTruck(const Rectangle& truckRect, const Rectangle& opRect, const TimeDuration& deltaTime)
	{
		if (getTruckController()->isDestroyed()) {
			return;
		}
        // if we are out of armor, avoid collisions, but still shoot.
        if(getTruckController()->getTruck()->truckParams.truckArmor <= 0)
        {
            if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect))
            {
                if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds())
                {
                    setInteracted(true);
                    shoot = true;
                    getTruckController()->getShotGun().shoot();
                    getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast);
					// TODO: If we want, this is where an opponent shotgun sound would go
                }
            }
            return;
        }
        // else we have armor, so try to attack
		if (isOpponentLeft(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect))
		{
			if (truckRect.left - opRect.right < hitRange)
			{
				getTruckController()->getTruck()->setInputLeft(true);
				setInteracted(true);
				//LOGI("Hit left");
			}
		}
		else if (isOpponentRight(truckRect, opRect) && !isOpponentUpper(truckRect, opRect) && !isOpponentBelow(truckRect, opRect))
		{
			if (opRect.left - truckRect.right < hitRange)
			{
				getTruckController()->getTruck()->setInputRight(true);
				setInteracted(true);
				//LOGI("Hit right");
			}
		}
		else if (getTruckController()->getShotGun().isObjectInRange(truckRect, opRect))
		{
			if (getTruckController()->getShotGun().isReadyToShoot() && chance(rng) < deltaTime.realSeconds())
			{
				setInteracted(true);
				shoot = true;
				getTruckController()->getShotGun().shoot();
				getTruckController()->getTruck()->activateAttachedAnimation(Truck::ShotgunBlast);
				// TODO: If we want to, this is where an opponent shotgun sound would go.
			}
		}
	}
Esempio n. 3
0
	void FPSAction::apply(const DrawablePtr& target, const DateTime& thisFrameStartTime, const TimeDuration& deltaTime)
	{
		++m_framesPassed;
		m_timeElapsed += deltaTime;

		TimeDuration desiredUpdatePeriod = Time::microseconds(250000);

		if( (m_timeElapsed > desiredUpdatePeriod) && (m_framesPassed > 3) )
		{
			boost::intrusive_ptr<Label> label = boost::dynamic_pointer_cast<Label>(target);
			if( label )
			{
				float fps = m_framesPassed / m_timeElapsed.realSeconds();
				label->setText( m_prefix + String(fps).substring(0,4) );
			}
			m_timeElapsed = TimeDuration(fmod(m_timeElapsed.realSeconds(), desiredUpdatePeriod.realSeconds()));
			m_framesPassed = 0;
		}
	}