Example #1
0
File: ui.c Project: Nuos/crawler
void ui_tick(float dt)
{
	if (console_enabled)
		console_fade = m_clamp(console_fade + dt*1.5f, 0, 1.f);
	else
		console_fade = m_clamp(console_fade - dt*1.5f, 0, 1.f);
}
Example #2
0
File: player.c Project: krig/roam
void player_tick(float dt)
{
	// update script vars
	pv.accel = script_get("player.accel");
	pv.friction = script_get("player.friction");
	pv.gravity = script_get("player.gravity");
	pv.flyspeed = script_get("player.flyspeed");
	pv.flyfriction = script_get("player.flyfriction");
	pv.height = script_get("player.height");
	pv.crouchheight = script_get("player.crouchheight");
	pv.camoffset = script_get("player.camoffset");
	pv.crouchcamoffset = script_get("player.crouchcamoffset");
	pv.jumpspeed = script_get("player.jumpspeed");

	struct player *p = &game.player;
	// update animations
	p->crouch_fade = m_clamp(p->crouch_fade + (p->crouching?dt:-dt)*5.f, 0.f, 1.f);
	++game.player.bobcount;
	if (game.player.bobcount > 200)
		game.player.bobcount = 0;


	if (game.camera.mode == CAMERA_FLIGHT) {
		flight_move(p, dt);
		return;
	} else if (game.camera.mode == CAMERA_FPS) {
		fps_move(p, dt);
	}

	p->prev_chunk = p->chunk;
	p->prev_block = p->block;
	p->prev_pos = p->pos;
	p->prev_vel = p->vel;
}
Example #3
0
File: player.c Project: krig/roam
static
void player_look(float dt)
{
	struct inputstate *in = &game.input;
	struct camera *cam = &game.camera;
	const float xsens = 1.f / ML_TWO_PI;
	const float ysens = 1.f / ML_TWO_PI;
	float dyaw = in->mouse_xrel * dt * xsens;
	float dpitch = in->mouse_yrel * dt * ysens;
	cam->yaw = m_wrap(cam->yaw - dyaw, 0.f, ML_TWO_PI);
	cam->pitch = m_clamp(cam->pitch - dpitch, -ML_PI_2, ML_PI_2);
	in->mouse_xrel = 0;
	in->mouse_yrel = 0;
}
Example #4
0
void Turret::updateMove (PlayerMove *move, float interval)
{
   if (data->isSustained == false) {
	   if (getControlClient() && state != EXTENDED)
	   	{
	   		if (!isGhost())
	   			extend (interval);
	   	}

		if (state != EXTENDED)
			move = NULL;

	   float oTR = turretRotation;
	   float oTE = turretElevation;

	   if (move && (!animThread || animThread->getPriority() != -1 ||
	   		animThread->getPosition() >= 1.0))
	   	{
#if 0
	   		float maxSpeed = data->speed * data->speedModifier * interval;
	   		float moveFrac = interval * 32;
#else
	   		float maxSpeed = data->speed * data->speedModifier;
	   		float moveFrac = interval * 16;
#endif
	   		float pitch = m_clamp(move->pitch,-maxSpeed,maxSpeed);
	   		float turn = m_clamp(move->turnRot,-maxSpeed,maxSpeed);
	   		turretElevation += pitch * moveFrac;
	   		turretRotation += turn * moveFrac;

	   		wrapElevation ();
	   		if (maxElevation != minElevation)
	   			{
	   				if (turretElevation > maxElevation)
	   					turretElevation = maxElevation;
	   			
	   				if (turretElevation < minElevation)
	   					turretElevation = minElevation;
	   			}
	
	   		wrapRotation ();
	   		if (maxRotation != minRotation)
	   			{
	   				if (turretRotation > maxRotation)
	   					turretRotation = maxRotation;
	   			
	   				if (turretRotation < minRotation)
	   					turretRotation = minRotation;
	   			}
	   	
	   		if (move->trigger)
	   			{
	   				if (!isGhost ())
	   					shoot (true);
	   			}
	   	
	   		if (move->jumpAction && !isGhost())
            {
               const char *fn = scriptName("jump");
               if(fn)
                  Console->executef(2, fn, scriptThis());
            }
	   	}

	   if (elevationThread && maxElevation != minElevation)
	   	elevationThread->SetPosition ((turretElevation - minElevation) / (maxElevation - minElevation));
	   	
	   if (rotationThread)
	   	{
	   		if (!isEqual (maxRotation, minRotation))
	   			rotationThread->SetPosition ((turretRotation - minRotation) / (maxRotation - minRotation));
	   		else
	   			rotationThread->SetPosition (turretRotation / M_2PI);
	   	}

	   // this is for the firing anim...
	   if (animThread && state == EXTENDED)
	   	animThread->AdvanceTime (interval);

	   // this is for the power anim...
	   if (animThread && isGhost())
	   	{
	   		if (state == EXTENDING)
	   			extend (interval);
	   		else
	   			if (state == RETRACTING)
	   				retract (interval);
	   	}

	   if (!isGhost ())
	   	{
	   		// Need to animate on the server to get the
	   		// node transforms.
	   		image.shape->animate ();

	   		if (oTE != turretElevation)
	   			setMaskBits (ElevationMask);
	   		if (oTR != turretRotation)
	   			setMaskBits (TRotationMask);
	   	}

	} else {
	   if (getControlClient() && state != EXTENDED) {
	      if (!isGhost())
	         extend (interval);
	   }

		if (state != EXTENDED)
			move = NULL;

	   float oTR = turretRotation;
	   float oTE = turretElevation;

	   if (move && (!animThread || animThread->getPriority() != -1 ||
	   		animThread->getPosition() >= 1.0))
	   {
	   	float maxSpeed = data->speed * interval;
	   	float pitch = m_clamp(move->pitch,-maxSpeed,maxSpeed);
	   	float turn = m_clamp(move->turnRot,-maxSpeed,maxSpeed);
	   	float moveFrac = interval * 32;
	   	turretElevation += pitch * moveFrac;
	   	turretRotation += turn * moveFrac;

	   	wrapElevation ();
	   	if (maxElevation != minElevation) {
	   		if (turretElevation > maxElevation)
	   			turretElevation = maxElevation;
	   	
	   		if (turretElevation < minElevation)
	   			turretElevation = minElevation;
	   	}
	
	   	wrapRotation ();
	   	if (maxRotation != minRotation) {
	   		if (turretRotation > maxRotation)
	   			turretRotation = maxRotation;
	   	
	   		if (turretRotation < minRotation)
	   			turretRotation = minRotation;
	   	}
	
	   	if (move->trigger && m_fireState == Waiting) {
	   		if (!isGhost ())
	   			shoot(true, NULL);
	   	} else if (!move->trigger && m_fireState == Firing) {
	   		if (!isGhost())
	   			unshoot();
         }
	
	   	if (move->jumpAction && !isGhost()) {
            if (m_fireState == Firing)
               unshoot();

            const char *fn = scriptName("jump");
            if(fn)
               Console->executef(2, fn, scriptThis());
         }
	   }

	   if (elevationThread && maxElevation != minElevation)
	   	elevationThread->SetPosition ((turretElevation - minElevation) / (maxElevation - minElevation));
	   	
	   if (rotationThread) {
	   	if (!isEqual (maxRotation, minRotation))
	   		rotationThread->SetPosition ((turretRotation - minRotation) / (maxRotation - minRotation));
	   	else
	   		rotationThread->SetPosition (turretRotation / M_2PI);
	   }

	   // this is for the firing anim...
	   if (animThread && state == EXTENDED)
	   	animThread->AdvanceTime (interval);

	   // this is for the power anim...
	   if (animThread && isGhost()) {
	   	if (state == EXTENDING)
	   		extend (interval);
	   	else if (state == RETRACTING)
	   	   retract (interval);
	   }

	   if (!isGhost ()) {
	   	// Need to animate on the server to get the
	   	// node transforms.
	   	image.shape->animate ();

	   	if (oTE != turretElevation)
	   		setMaskBits (ElevationMask);
	   	if (oTR != turretRotation)
	   		setMaskBits (TRotationMask);
	   }
   }
}