Ejemplo n.º 1
0
void 
Curupira::update(SDL_Rect target)
{
	//loop("[Curupira] Updating.");
	updatePosition(target);

	switch (m_state)
	{
		case UNDERGROUND:
			underground();
		break;
		case STANDING:
			standing();
		break;
		case ATTACKING:
			attacking();
		break;
		case MOVING:
			moving();
		break;
	}

	if(!m_hunt || !m_rose)
	{
		m_state = UNDERGROUND;
	}
	else if (m_damaging)
	{
		m_state = ATTACKING;
	}
	else
	{

		m_state = MOVING;
		if(isOnLeftDirection())
		{
			//condition("[Curupira] Moving Backward.");
			m_looking = BACKWARD;
		}
		else if(isOnRightDirection())
		{
			//condition("[Curupira] Moving Forward.");
			m_looking = FORWARD;
		}	
	}
}
Ejemplo n.º 2
0
Archivo: libsim.c Proyecto: psas/libsim
static void integrate(state y0, state *yp, double *xp, double x1, double x2, int *steps)
{
	int i;
	int stepnum = 0;   // Track number of steps the integrator has run

	double x = x1;     // Current time, begin at x1
	state s;           // Current state

	// Integrator memory, each position in an array is a DOF of the system
	double y[n];       // array of integrator outputs, y = integral(y' dx)
	double dydx[n];    // array of RHS, dy/dx
	double yscale[n];  // array of yscale factors (integraion error tolorence)
	double h;          // timestep
	double hdid;       // stores actual timestep taken by RK45
	double hnext;      // guess for next timestep

	// stop the integrator
	double time_to_stop = x2;

	// First guess for timestep
	h = x2 - x1;

	// Inital conditions
	y[0] = y0.x.v.i;
	y[1] = y0.v.v.i;
	y[2] = y0.x.v.j;
	y[3] = y0.v.v.j;
	y[4] = y0.x.v.k;
	y[5] = y0.v.v.k;
	dydx[1] = y0.a.v.i;
	dydx[3] = y0.a.v.j;
	dydx[5] = y0.a.v.k;
	y[6] = y0.m;

	while (stepnum <= MAXSTEPS)
	{
		// First RHS call
		deriv(y, dydx, x);
		s = rk2state(y, dydx);

		// Store current state
		xp[stepnum] = x;
		yp[stepnum] = s;

		// Y-scaling. Holds down fractional errors
		for (i=0;i<n;i++) {
			yscale[i] = 0.000000001;//dydx[i]+TINY;
		}

		// Check for stepsize overshoot
		if ((x + h) > time_to_stop)
			h = time_to_stop - x;

		// One quality controled integrator step
		rkqc(y, dydx, &x, h, eps, yscale, &hdid, &hnext, n, deriv);
		s = rk2state(y, dydx);

		// Are we finished?
		// hit ground
		if (underground(s))
		{
			deriv(y, dydx, x);
			s = rk2state(y, dydx);
			xp[stepnum] = x;
			yp[stepnum] = s;
			stepnum++;
			break;
		}

		// Passed requested integration time
		if ( (time_to_stop - x) <= 0.0001 )
		{
			deriv(y, dydx, x);
			s = rk2state(y, dydx);
			xp[stepnum] = x;
			yp[stepnum] = s;
			stepnum++;
			break;
		}

		// set timestep for next go around
		h = hnext;

		// Incement step counter
		stepnum++;
	}

	(*steps) = stepnum;
	return;
}