// Integrate forces into positions using RK4 step
int LinearBody::RK4Step()
{
	
	// Recalculate all forces
	double realTimestep = timestep;
	timestep /= 2;
	UpdateForces();

	// Check if dead
	if (DeathCheck())
		return 1;

	// Apply RK4 Step using new forces
	for (ALLNODES_i) {
		
	}
	
	return 0;
}
// Integrate forces into positions using a simple euler step.
// You should really keep the timestep <0.01 for this type of integration.
int LinearBody::EulerStep()
{
	// Recalculate all forces
	UpdateForces();

	// Check if we're dead. Return with error if already dead.
	if (DeathCheck())
		return 1;

	// Apply simple euler step using new forces
	for (ALLNODES_i) {
		// update velocity    a = F / m
		nodes[i].v.x += (nodes[i].a.x)*timestep;
		nodes[i].v.y += (nodes[i].a.y)*timestep;
		// update posiiton
		nodes[i].p.x += (nodes[i].v.x)*timestep;
		nodes[i].p.y += (nodes[i].v.y)*timestep;
	}

	return 0;
}
Exemple #3
0
/*
This function handles gaining / losing HP.
It handles various different scenarios, and should be able to handle every possible one.
*/
bool CMobs::ChangeHP(unsigned long ByWhat, bool Decrease, bool ThisIsChecked)
{
	// Handle if we have a negative number.
	if ( Decrease )
	{
		// If we have enough HP left to take away.
		if (HP >= ByWhat)
		{
			HP -= ByWhat;
		}

		// Else if we don't, just set the HP to 0.
		else if (HP < ByWhat)
		{
			// If this is not a check of some sort, kill the player (Like if this is monster damage).
			if (!ThisIsChecked)
			{
				HP = 0;
			}

			// If this is a check, just return false so we know the player doesn't have enough
			// HP to perform the operation they are trying to do (like use a skill).
			else if (ThisIsChecked)
			{
				return false;
			}
		}

		// This would mean the monster has died recently.
		if (Dead == false && HP == 0)
		{
			Player.ChangeEXP(EXPGiven, false);
			CItems *NewItem = new CItems(9001, 10, this->GetRect());
			Items.push_back( NewItem );
		}

		// If the player has 0 HP, they are dead. Set this value accordingly.
		if (HP == 0)
		{
			Dead = true;
		}
	}

	// Handle if we have a positive number.
	else if ( !Decrease )
	{
		// If we are trying to gain more hp than the max.
		if ( (HP + ByWhat) > MaxHP )
		{
			// Just heal to full.
			HP = MaxHP;
		}

		// Otherwise, we're just trying a regular heal, so just increase HP normally.
		else
		{
			HP += ByWhat;
		}

		// If the player has the dead flag set, we just healed HP meaning they can't have 0 anymore. Set this value accordingly.
		// This function might be called with a value of 0 for whatever reason, and since in this case we don't want a major exploit where
		// you could be alive with 0 HP, we will always check if they are dead AND have greater than 0 hp before setting them to alive.
		if (Dead == true && HP > 0)
		{
			Dead = false;
		}
	}

	DeathCheck();

	return true;
}