Exemplo n.º 1
0
//----------------------------------------------------------------------------
void Application::UpdateLogic() {
#ifndef MULTITHREADED
    // Update Input
    UpdateInput();

    // Update time variable

    // Run the game logic
    if (!isPaused) Update();

    // Render frame
    UpdateFrame();

    // Update physics simulation
    UpdatePhysics();

    // Update logic done after physics
    if (!isPaused) UpdateLate();

    // Update sound system
    UpdateSound();

    // Update delta time
    // Calculate FPS

    // Increment current frame variable TODO: removeme
    currentFrame++;
#ifdef _DEBUG
    // Update Debug Console
    UpdateDebug();
#endif
#endif
}
Exemplo n.º 2
0
void
Region::initSound() {
	if ( isSurface() ) {
		std::string snd = SoundBank[0][0][0];
		NosuchAssert(snd!="");
		params.sound = snd;
		UpdateSound();
	}
}
Exemplo n.º 3
0
void
Region::initSound() {
	if ( isRegion() ) {
		std::string snd = SoundBank[0][0][0];
		NosuchAssert(snd!="");
		_regionParams->sound.set(snd);
		UpdateSound();
	}
}
Exemplo n.º 4
0
/*
================
rvClientEntity::Think
================
*/
void rvClientEntity::Think( void ) {
	if ( bindMaster.IsValid() && bindMaster->IsInterpolated() ) {
		UpdateBind( true );
	} else {
		UpdateBind( false );
	}

	UpdateSound();
	Present();
}
Exemplo n.º 5
0
void Loop()
{
	while(!OpQuit() && _sys_judge_event(NULL) >= 0)
	{
		if(!Handler()->FullSpeed())
			WaitTimer();
		UpdateSound();
		UpdateKeys();
		Handler()->OnLoop();
		UpdateVideo();
	}
}
Exemplo n.º 6
0
void SoundSystemManager::Update ()
{
    SndTime = csGetTicks();

    // call it all 100 Ticks
    if (Initialised && LastUpdateTime + 100 <= SndTime)
    {
        UpdateSound();
        // make a update on sounddata to check if there are sounds to unload
        soundData->Update();
    }
}
Exemplo n.º 7
0
/*
================
rvClientEntity::StartSoundShader
================
*/
int rvClientEntity::StartSoundShader( const idSoundShader* shader, const soundChannel_t channel, int soundShaderFlags )  {
	if ( !shader ) {
		return 0;
	}

	if ( !refSound.referenceSound ) {
		refSound.referenceSound = gameSoundWorld->AllocSoundEmitter();
	}

	UpdateSound();

	return refSound.referenceSound->StartSound( shader, channel, channel, gameLocal.random.RandomFloat(), soundShaderFlags  );
}
Exemplo n.º 8
0
void CFuncVehicle::Find()
{
	m_ppath = CPathTrack::Instance(FIND_ENTITY_BY_TARGETNAME(nullptr, STRING(pev->target)));

	if (!m_ppath)
		return;

	entvars_t *pevTarget = m_ppath->pev;

	if (!FClassnameIs(pevTarget, "path_track"))
	{
		ALERT(at_error, "func_track_train must be on a path of path_track\n");
		m_ppath = nullptr;
		return;
	}

	Vector nextPos = pevTarget->origin;
	nextPos.z += m_height;

	Vector look = nextPos;
	look.z -= m_height;
	m_ppath->LookAhead(&look, m_length, 0);
	look.z += m_height;

	pev->angles = UTIL_VecToAngles(look - nextPos);
	pev->angles.y += 180;

	if (pev->spawnflags & SF_TRACKTRAIN_NOPITCH)
	{
		pev->angles.x = 0;
	}

	UTIL_SetOrigin(pev, nextPos);
	NextThink(pev->ltime + 0.1, FALSE);
	SetThink(&CFuncVehicle::Next);
	pev->speed = m_startSpeed;
	UpdateSound();
}
Exemplo n.º 9
0
SoundSystemManager::~SoundSystemManager ()
{
    Initialised = false;
    // pause all sounds and call updatesound to remove them
    for (size_t i = 0; i < soundHandles.GetSize (); i++)
    {
        soundHandles[i]->sndstream->Pause();
        soundHandles[i]->SetAutoRemove(true);
    }

    UpdateSound();

    // FIXME we must delete all SoundControls
    for (size_t i = 0; i < soundController.GetSize(); i++)
    {
        delete soundController[i];
    }
    
    soundController.DeleteAll();

    delete soundSystem;
    delete soundData;

}
Exemplo n.º 10
0
void CFuncVehicle::Next()
{
	Vector vGravityVector, forward, right, up;
	float time = 0.1f;

	vGravityVector = g_vecZero;
	UTIL_MakeVectors(pev->angles);

	forward = (gpGlobals->v_forward * -1) * (m_length * 0.5);
	right = (gpGlobals->v_right * -1) * (m_width * 0.5);
	up = gpGlobals->v_up * 16;

	m_vFrontLeft = pev->origin + forward - right + up;
	m_vFrontRight = pev->origin + forward + right + up;
	m_vFront = pev->origin + forward + up;
	m_vBackLeft = pev->origin - forward - right + up;
	m_vBackRight = pev->origin - forward + right + up;
	m_vBack = pev->origin - forward + up;
	m_vSurfaceNormal = g_vecZero;

	CheckTurning();

	if (m_flSteeringWheelDecay < gpGlobals->time)
	{
		m_flSteeringWheelDecay = gpGlobals->time + 0.1f;

		if (m_iTurnAngle < 0)
			m_iTurnAngle++;

		else if (m_iTurnAngle > 0)
			m_iTurnAngle--;
	}

	if (m_flAcceleratorDecay < gpGlobals->time)
	{
		m_flAcceleratorDecay = gpGlobals->time + 0.1f;

		if (pev->speed < 0)
		{
			pev->speed += 20;

			if (pev->speed > 0)
				pev->speed = 0;
		}
		else if (pev->speed > 0)
		{
			pev->speed -= 20;

			if (pev->speed < 0)
				pev->speed = 0;
		}
	}

	if (pev->speed == 0)
	{
		m_iTurnAngle = 0;
		pev->avelocity = g_vecZero;
		pev->velocity = g_vecZero;

		SetThink(&CFuncVehicle::Next);
		NextThink(pev->ltime + time, TRUE);
		return;
	}

	TerrainFollowing();
	CollisionDetection();

	Vector temp;
	if (m_vSurfaceNormal != g_vecZero)
	{
		Vector vTargetAngle, vAngle;

		float vx;
		real_t vy;

		m_vVehicleDirection = CrossProduct(m_vSurfaceNormal, gpGlobals->v_forward);
		m_vVehicleDirection = CrossProduct(m_vSurfaceNormal, m_vVehicleDirection);

		vTargetAngle = UTIL_VecToAngles(m_vVehicleDirection);
		vAngle = pev->angles;

		vTargetAngle.y += 180;

		if (m_iTurnAngle != 0)
		{
			vTargetAngle.y += m_iTurnAngle;
		}

		UTIL_FixupAngles(vTargetAngle);
		UTIL_FixupAngles(vAngle);

		vx = UTIL_AngleDistance(vTargetAngle.x, vAngle.x);
		vy = UTIL_AngleDistance(vTargetAngle.y, vAngle.y);

		if (vx > 10)
			vx = 10;
		else if (vx < -10)
			vx = -10;

		if (vy > 10)
			vy = 10;
		else if (vy < -10)
			vy = -10;

		pev->avelocity.y = int(vy * 10);
		pev->avelocity.x = int(vx * 10);

		m_flLaunchTime = -1;
		m_flLastNormalZ = m_vSurfaceNormal.z;
	}
	else
	{
		if (m_flLaunchTime != -1)
		{
			vGravityVector.x = 0;
			vGravityVector.y = 0;
			vGravityVector.z = (gpGlobals->time - m_flLaunchTime) * -35;

			if (vGravityVector.z < -400)
			{
				vGravityVector.z = -400;
			}
		}
		else
		{
			m_flLaunchTime = gpGlobals->time;
			vGravityVector = Vector(0, 0, 0);
			pev->velocity = pev->velocity * 1.5;
		}

		m_vVehicleDirection = gpGlobals->v_forward * -1;
	}

	UTIL_VecToAngles(m_vVehicleDirection);

	if (m_flUpdateSound < gpGlobals->time)
	{
		UpdateSound();
		m_flUpdateSound = gpGlobals->time + 1.0f;
	}

	if (m_vSurfaceNormal != g_vecZero)
	{
		pev->velocity = m_vVehicleDirection.Normalize() * pev->speed;
	}
	else
	{
		pev->velocity = pev->velocity + vGravityVector;
	}

	SetThink(&CFuncVehicle::Next);
	NextThink(pev->ltime + time, TRUE);
}
Exemplo n.º 11
0
 void Emitter::SetupSound(Sound& sound) {
     sound.GetSource().SetReferenceDistance(120.0f);
     InternalSetupSound(sound);
     UpdateSound(sound);
 }
Exemplo n.º 12
0
//------------------------------------------------------------------------
void CRapid::Update(float frameTime, uint32 frameId)
{
  FUNCTION_PROFILER( GetISystem(), PROFILE_GAME );

  CSingle::Update(frameTime, frameId);

	if (m_speed <= 0.0f && m_acceleration < 0.0001f)
	{
		FinishDeceleration();
		return;
	}

	m_pWeapon->RequireUpdate(eIUS_FireMode);

	m_speed = m_speed + m_acceleration*frameTime;

	if (m_speed > m_pShared->rapidparams.max_speed)
	{
		m_speed = m_pShared->rapidparams.max_speed;
		m_accelerating = false;
	}

	if ((m_speed >= m_pShared->rapidparams.min_speed) && (!m_decelerating))
	{
		float dt = 1.0f;
		if (cry_fabsf(m_speed)>0.001f && cry_fabsf(m_pShared->rapidparams.max_speed>0.001f))
			dt=m_speed/m_pShared->rapidparams.max_speed;
		m_next_shot_dt = 60.0f/(m_pShared->fireparams.rate*dt);

		bool canShoot = CanFire(false);

		if (canShoot)
		{
			if (!OutOfAmmo())
			{
				if (m_netshooting)
					Firing(true);
				else
					Firing(Shoot(true, false));

				if (m_firing && !(m_pShared->rapidparams.camshake_rotate.IsZero() && m_pShared->rapidparams.camshake_shift.IsZero()))
				{
					CActor *act = m_pWeapon->GetOwnerActor();
					if (act && act->IsClient())
					{
						IView *pView = g_pGame->GetIGameFramework()->GetIViewSystem()->GetActiveView();
						if (pView)            
							pView->SetViewShake(Ang3(m_pShared->rapidparams.camshake_rotate), m_pShared->rapidparams.camshake_shift, m_next_shot_dt/m_pShared->rapidparams.camshake_perShot, m_next_shot_dt/m_pShared->rapidparams.camshake_perShot, 0, 1);            
					}
				}
			}
			else
			{
				Firing(false);
				Accelerate(m_pShared->rapidparams.deceleration);
				if (m_pWeapon->GetOwnerActor() && m_pWeapon->GetOwnerActor()->IsPlayer())
				{
					SmokeEffect();
					m_pWeapon->Reload();
				}
			}
		}
	}
	else if (m_firing)
	{
		Firing(false);
		if (OutOfAmmo() && m_pWeapon->GetOwnerActor() && m_pWeapon->GetOwnerActor()->IsPlayer())
		{
			SmokeEffect();
			m_pWeapon->Reload();
		}
	}

	if ((m_speed < m_pShared->rapidparams.min_speed) && (m_acceleration < 0.0f) && (!m_decelerating))
		Accelerate(m_pShared->rapidparams.deceleration);

	UpdateRotation(frameTime);
	UpdateSound(frameTime);
}
Exemplo n.º 13
0
Arquivo: main.cpp Projeto: boredzo/CCX
int main(int argc, char *argv[])
{
	// Initialize the SDL library
	// This is required to avoid _main errors at runtime.
#ifdef UseSDLMixer
	if ( SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO) < 0 ) {
#else
	if ( SDL_Init(SDL_INIT_VIDEO ) < 0 ) {
#endif		
		fprintf(stderr, "Couldn't initialize SDL: %s\n",
				SDL_GetError());
		exit(1);
	}

	// Init SDL_Image - only applies above 1.2.7
	// load support for the JPG and PNG image formats
	int IMGflags=IMG_INIT_JPG|IMG_INIT_PNG;
	int initted=IMG_Init(IMGflags);
	if(initted && IMGflags != IMGflags) {
		printf("IMG_Init: Failed to init required jpg and png support!\n");
		printf("IMG_Init: %s\n", IMG_GetError());
		// handle error
	}

		
#ifdef UseSDLMixer
	// Initialize SDL mixer.
	if(Mix_OpenAudio(44100, MIX_DEFAULT_FORMAT, 2, 1024) != 0) {
		fprintf(stderr, "Unable to initialize audio: %s\n", Mix_GetError());
		exit(1);
	}
#endif
    
    // Retrieve display gamma for reference in fade in/fade out routines.
    SDL_GetGammaRamp(redGamma, greenGamma, blueGamma);
//    printf("%u", *redGamma);
	Initialize( );	

	LoadPrefs( );
	
	ReserveMonitor( );	
	ShowTitle( );
	
	ChooseMusic( 13 );
	
	while( !finished )
	{
		if( showStartMenu )
		{
			GameStartMenu( );
			showStartMenu = false;
		}
		
		if( !finished )
		{
			DoFullRepaint = NeedRefresh;
			CheckKeys( );
			HandlePlayers( );
			UpdateOpponent( );
			UpdateBalloon( );
			UpdateSound( );
			DoFullRepaint = NoPaint;
			
			if( needsRefresh )
			{
				RefreshAll();
				needsRefresh = false;
			}
			
			if( !showStartMenu && pauseKey )
			{
				FreezeGameTickCount( );
				PauseMusic( );
				MaskRect( &playerWindowRect[0] );
				MaskRect( &playerWindowRect[1] );
				WaitForRelease( );
				
				HandleDialog( kPauseDialog );
								
				WaitForRelease( );
				RefreshPlayerWindow( 0 );
				RefreshPlayerWindow( 1 );
				ResumeMusic( );
				UnfreezeGameTickCount( );
			}
		}
	}
	
	SavePrefs( );
	ReleaseMonitor( );
	
	return 0;
}

void NoPaint( void )
{
}

void MaskRect( MRect *r )
{
	SDL_Rect sdlRect;
	SDLU_MRectToSDLRect( r, &sdlRect );
	SDLU_BlitFrontSurface( backdropSurface, &sdlRect, &sdlRect );
}
Exemplo n.º 14
0
			void ALSound::Update(){
				UpdateSound();
			}
Exemplo n.º 15
0
void CTank :: TankDeath ( void )
{
	bTankDead = 1;
	pev->sequence = 2;/*LookupSequence( "die" );*/
	ResetSequenceInfo ();

	m_pPlayer->TakeDamage ( pev,pev,(float)999, DMG_CRUSH );	// mouru

	pev->velocity = pev->avelocity = m_pTankBSP->pev->velocity = m_pTankBSP->pev->avelocity =Vector (0,0,0);
	m_pTankBSP->pev->origin = pev->origin;
	m_pTankBSP->pev->angles = pev->angles;

	m_pCam->pev->velocity = m_pCam->pev->avelocity = Vector (0,0,0);

	UpdateSound ();

	SetThink ( DeadThink );
	pev->nextthink = gpGlobals->time + 29 / 21.0;

	// maman, c'est quoi qu'a fait boum ?

	EMIT_SOUND(ENT(pev), CHAN_AUTO, TANK_EXPLO_SOUND1, 1, ATTN_NORM);	
	EMIT_SOUND(ENT(pev), CHAN_WEAPON, TANK_EXPLO_SOUND2, 1, ATTN_NORM);	


	// sprites de feu - explosion

	for ( int i=0; i<20; i++ )
	{
		CSprite *pSpr = CSprite::SpriteCreate ( SPRITE_FEU, Vector(pev->origin.x,pev->origin.y,pev->origin.z + 50), TRUE );
		pSpr->SetScale ( SPRITE_FEU_SCALE*2 );
		pSpr->AnimateAndDie ( RANDOM_FLOAT(20,22) );
		pSpr->SetTransparency ( kRenderTransAdd, 255, 255, 255, 120, kRenderFxNone );

		pSpr->pev->velocity = Vector ( RANDOM_FLOAT(-150,150),RANDOM_FLOAT(-150,150),100/*RANDOM_FLOAT(130,150)*/ );
	}
	// sprites de feu en colonne

	for ( i=0; i<6; i++ )
	{
		CSprite *pSpr = CSprite::SpriteCreate ( SPRITE_FEU, Vector(pev->origin.x,pev->origin.y,pev->origin.z + 100), TRUE );
		pSpr->SetScale ( SPRITE_FEU_SCALE );
		pSpr->AnimateAndDie ( RANDOM_FLOAT(20,25) );
		pSpr->SetTransparency ( kRenderTransAdd, 255, 255, 255, 120, kRenderFxNone );

		pSpr->pev->velocity = Vector ( RANDOM_FLOAT(-50,50),RANDOM_FLOAT(-50,50),140/*RANDOM_FLOAT(130,150)*/ );
	}

	for ( i=0; i<10; i++ )
	{
		CSprite *pSpr = CSprite::SpriteCreate ( SPRITE_SMOKEBALL, Vector(pev->origin.x,pev->origin.y,pev->origin.z + 100), TRUE );
		pSpr->SetScale ( SPRITE_SMOKEBALL_SCALE );
		pSpr->AnimateAndDie ( RANDOM_FLOAT(2,3) );
		pSpr->SetTransparency ( kRenderTransAlpha, 255, 255, 255, 255, kRenderFxNone );
		pSpr->pev->velocity = Vector ( RANDOM_FLOAT(-50,50),RANDOM_FLOAT(-50,50),RANDOM_FLOAT(50,50) );
	}


	// gibs

	for ( i = 0; i<20; i++ )
	{
		CGib *pGib = GetClassPtr( (CGib *)NULL );
		pGib->Spawn( "models/mechgibs.mdl" );
		pGib->m_bloodColor = DONT_BLEED;
		pGib->pev->body = RANDOM_LONG (1,5);

		pGib->pev->origin = pev->origin + Vector ( 0, 0, 250 );
		pGib->pev->velocity = Vector ( RANDOM_FLOAT(-200,200),RANDOM_FLOAT(-200,200),RANDOM_FLOAT(0,400));
		pGib->pev->avelocity = Vector ( RANDOM_FLOAT(-1000,1000), RANDOM_FLOAT(-1000,1000), RANDOM_FLOAT(-1000,1000) );

		pGib->pev->solid = SOLID_NOT;
		pGib->SetThink(SUB_Remove);
		pGib->pev->nextthink = gpGlobals->time + 1;
	}

	// étincelles

	for ( i = 0; i < 10; i++ )
	{
		Create( "spark_shower", pev->origin, Vector (0,0,1), NULL );
	}



}
Exemplo n.º 16
0
void CTank :: IdleThink ( void )
{
	UpdateSound ();
	pev->nextthink = gpGlobals->time + 0.1;
}
Exemplo n.º 17
0
void CTank :: DriveThink ( void )
{
	pev->nextthink = gpGlobals->time + NEXTTHINK_TIME;
	StudioFrameAdvance ( );

	if ( pev->sequence == 1 )
		pev->sequence = 0;

//	ALERT ( at_console, "playerdrivetank : %s\n", m_pPlayer->m_iDrivingTank == TRUE ? "TRUE" : "FALSE" ); 

	// apres le changement de niveau, reinitialisation de la vue

	if ( bSetView == 1 )
	{
		// actualisation de la vie du bsp

		m_pTankBSP->pev->health = m_flTempHealth;

		// réglages camera & hud

		m_pCam->SetPlayerTankView ( TRUE );
		bSetView = 0;
	}

	//quitte le tank

	if (m_pPlayer->pev->button & IN_USE)
	{
		pev->velocity = pev->avelocity = m_pTankBSP->pev->velocity = m_pTankBSP->pev->avelocity =Vector (0,0,0);
		m_pTankBSP->pev->origin = pev->origin;
		m_pTankBSP->pev->angles = pev->angles;

		m_pCam->pev->velocity = ( vecCamOrigin() - m_pCam->pev->origin ) /2;
		UpdateCamAngle ( m_pCam->pev->origin, 2 );

		UpdateSound ();

		SetThink( StopThink );
		pev->nextthink = gpGlobals->time + 2;
		return;
	}


	float flNextVAngleY = pev->v_angle.y;
	float flNextVAngleX = pev->v_angle.x;
	float flNewAVelocity;
	Vector vecNewVelocity;

	//---------------------------------------------_-_-_ _  _
	//modifications de la direction de la tourelle
			
	if ( bTankOn == 0 )
	{
		bTankOn = 1;
		m_PlayerAngles.x = m_pPlayer->pev->angles.x ;
		m_PlayerAngles.y = m_pPlayer->pev->angles.y ;
	}

	if ( m_pPlayer->pev->angles.y != m_PlayerAngles.y )
	{
		int iSens;
		int iDist = ModifAngles ( m_pPlayer->pev->angles.y ) - ModifAngles ( m_PlayerAngles.y );

		if ( fabs(iDist) > 180 )
		{
			if ( iDist > 0 )
				iDist = iDist - 360;
			else
				iDist = iDist + 360;
		}

		iSens = iDist == fabs(iDist) ? 1 : -1 ;
		iDist = fabs(iDist);


		if ( iDist < TANK_TOURELLE_ROT_SPEED )
			flNextVAngleY += iDist * iSens;

		else
			flNextVAngleY += TANK_TOURELLE_ROT_SPEED * iSens;

		if ( flNextVAngleY > TOURELLE_MAX_ROT_Y )
			flNextVAngleY = TOURELLE_MAX_ROT_Y;

		if ( flNextVAngleY < -TOURELLE_MAX_ROT_Y )
			flNextVAngleY = -TOURELLE_MAX_ROT_Y;

	}

	if ( m_pPlayer->pev->angles.x != m_PlayerAngles.x )
	{
		int iSens;
		int iDist = ModifAngles ( m_pPlayer->pev->angles.x ) - ModifAngles ( m_PlayerAngles.x );

		if ( fabs(iDist) > 180 )
		{
			if ( iDist > 0 )
				iDist = iDist - 360;
			else
				iDist = iDist + 360;
		}

		iSens = iDist == fabs(iDist) ? 1 : -1 ;
		iDist = fabs(iDist);

		if ( iDist < TANK_TOURELLE_ROT_SPEED )
			flNextVAngleX += iDist * iSens;

		else
			flNextVAngleX += TANK_TOURELLE_ROT_SPEED * iSens;

		if ( flNextVAngleX > TOURELLE_MAX_ROT_X )
			flNextVAngleX = TOURELLE_MAX_ROT_X;

		if ( flNextVAngleX < TOURELLE_MAX_ROT_X2 )
			flNextVAngleX = TOURELLE_MAX_ROT_X2;

	}

	m_PlayerAngles.y = m_pPlayer->pev->angles.y;
	m_PlayerAngles.x = m_pPlayer->pev->angles.x;


	//---------------------------------
	// sons d'acceleration du tank

	float flSpeed = pev->velocity.Length();

	if ( m_flNextSound < gpGlobals->time)
	{
		if  ( (m_pPlayer->pev->button & IN_FORWARD) && ((flSpeed==0) || (m_iTankmove & MOVE_BACKWARD)) )
		{
			EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, ACCELERE_SOUND1, 1 , ATTN_NONE, 0, 100 );
			m_flNextSound = gpGlobals->time + 2.5;
		}
		else if  ( (m_pPlayer->pev->button & IN_BACK) && (m_iTankmove & MOVE_FORWARD) )
		{
			EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, DECCELERE_SOUND, 1 , ATTN_NONE, 0, 100 );
			m_flNextSound = gpGlobals->time + 2.5;
		}
		else if  ( (m_pPlayer->pev->button & IN_FORWARD) && (m_iTankmove & MOVE_FORWARD) && !(m_iTankmove & PUSH_FORWARD))
		{
			if ( RANDOM_LONG ( 0,1 ) )
				EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, ACCELERE_SOUND2, 1 , ATTN_NONE, 0, 100 );
			else
				EMIT_SOUND_DYN(ENT(pev), CHAN_ITEM, ACCELERE_SOUND3, 1 , ATTN_NONE, 0, 100 );
			m_flNextSound = gpGlobals->time + 2.5;
		}
	}


	//-------------------------------
	//modification de la vitesse du tank


	UTIL_MakeVectors( pev->angles );

	int iSens = UTIL_AngleDiff( UTIL_VecToAngles ( pev->velocity ).y,  UTIL_VecToAngles	( gpGlobals->v_forward ).y );

	if ( flSpeed == 0 )
		iSens = 0;
	else if ( iSens < -45 || iSens > 45 )
		iSens = -1;
	else 
		iSens = 1;

	if ( m_pPlayer->pev->button & IN_FORWARD)
	{
		m_iTankmove |= PUSH_FORWARD;
		m_iTankmove &= ~PUSH_BACKWARD;		

		if ( iSens == -1 )
		{
			if ( flSpeed > TANK_DECCELERATION * 2 )
				vecNewVelocity = gpGlobals->v_forward * - ( flSpeed - TANK_DECCELERATION );
			else
				vecNewVelocity = Vector ( 0,0,0 );
		}

		else if ( flSpeed < 250 )
			vecNewVelocity = gpGlobals->v_forward * ( flSpeed + TANK_ACCELERATION );

		else
			vecNewVelocity = gpGlobals->v_forward * 250;
	}


	else if ( m_pPlayer->pev->button & IN_BACK)
	{

		m_iTankmove |= PUSH_BACKWARD;
		m_iTankmove &= ~PUSH_FORWARD;		

		if ( iSens == 1 )
		{
			if ( flSpeed > TANK_DECCELERATION * 2 )
				vecNewVelocity = gpGlobals->v_forward * ( flSpeed - TANK_DECCELERATION );
			else
				vecNewVelocity = Vector ( 0,0,0 );
		}

		else if ( flSpeed < 150 )
			vecNewVelocity = gpGlobals->v_forward * - ( flSpeed + TANK_ACCELERATION );
		else
			vecNewVelocity = gpGlobals->v_forward * -150;
	}

	
	else
	{
		if ( flSpeed > 5 )
			vecNewVelocity = gpGlobals->v_forward * ( flSpeed - 1 ) * iSens;
		else
			vecNewVelocity = gpGlobals->v_forward * flSpeed * iSens;


		m_iTankmove &= ~PUSH_BACKWARD;
		m_iTankmove &= ~PUSH_FORWARD;
	}


	if ( iSens == 1)
	{
		m_iTankmove |= MOVE_FORWARD;
		m_iTankmove &= ~MOVE_BACKWARD;
	}
	else
	{
		m_iTankmove |= MOVE_BACKWARD;
		m_iTankmove &= ~MOVE_FORWARD;
	}



	//modification de la direction du tank

	if ( m_pPlayer->pev->button & IN_MOVELEFT )
		flNewAVelocity = TANK_ROT_SPEED;

	else if ( m_pPlayer->pev->button & IN_MOVERIGHT )
		flNewAVelocity = -TANK_ROT_SPEED;

	else
		flNewAVelocity = 0;


	// test de la position envisagée

	UTIL_MakeVectors ( pev->angles + Vector ( 0, flNewAVelocity / 10 , 0) );

	TraceResult	tr [4]/*1,tr2,tr3,tr4*/;
	Vector vecFrontLeft, vecFrontRight, vecBackLeft, vecBackRight;

	vecFrontLeft =	NEW_ORIGIN + gpGlobals->v_forward * DIST_FRONT_UP + gpGlobals->v_right * -DIST_SIDE + gpGlobals->v_up * DIST_TOP;
	vecFrontRight = NEW_ORIGIN + gpGlobals->v_forward * DIST_FRONT_UP + gpGlobals->v_right * DIST_SIDE + gpGlobals->v_up * DIST_TOP;
	vecBackLeft =	NEW_ORIGIN + gpGlobals->v_forward * DIST_BACK_UP + gpGlobals->v_right * -DIST_SIDE + gpGlobals->v_up * DIST_TOP;
	vecBackRight =	NEW_ORIGIN + gpGlobals->v_forward * DIST_BACK_UP + gpGlobals->v_right * DIST_SIDE + gpGlobals->v_up * DIST_TOP;
					
	UTIL_TraceLine (vecFrontLeft, vecFrontRight,ignore_monsters, ENT(m_pTankBSP->pev), &tr[0]);
	UTIL_TraceLine (vecFrontRight, vecBackRight,ignore_monsters, ENT(m_pTankBSP->pev), &tr[1]);
	UTIL_TraceLine (vecBackRight, vecBackLeft,	ignore_monsters, ENT(m_pTankBSP->pev), &tr[2]);
	UTIL_TraceLine (vecBackLeft, vecFrontLeft,	ignore_monsters, ENT(m_pTankBSP->pev), &tr[3]);


	//pas de collision - application de la nouvelle position

	if ( tr[0].vecEndPos == vecFrontRight && tr[1].vecEndPos == vecBackRight && tr[2].vecEndPos == vecBackLeft && tr[3].vecEndPos == vecFrontLeft )
	{
		StudioFrameAdvance ( 0.1 );

		pev->velocity = vecNewVelocity;
		pev->avelocity = Vector ( 0, flNewAVelocity, 0 );

		m_pCam->m_vecTourelleAngle = pev->v_angle;
		m_pCam->m_flNextFrameTime = pev->nextthink;

		pev->v_angle.y = flNextVAngleY;
		pev->v_angle.x = flNextVAngleX;


		m_pTankBSP->pev->velocity = (( pev->origin + vecNewVelocity * 10 ) - m_pTankBSP->pev-> origin ) / 10 ;
		m_pTankBSP->pev->avelocity = (( pev->angles + Vector ( 0, flNewAVelocity * 10, 0 ) - m_pTankBSP->pev->angles )) / 10;
		// pour combler la différence de vitesse entre le bsp et le mdl

	}

	//collision - arret du tank

	else
	{
		pev->velocity = pev->avelocity = Vector (0,0,0);
		m_pTankBSP->pev->velocity = ( pev->origin - m_pTankBSP->pev-> origin ) / 10 ;
		m_pTankBSP->pev->avelocity = ( pev->angles - m_pTankBSP->pev->angles ) / 10;

		if ( flSpeed > 50 )	// choc violent
		{
			EMIT_SOUND_DYN(ENT(pev), CHAN_VOICE, CHOC_SOUND, 0.9, ATTN_NORM, 0, 60 );

		}
	}


	// application des dommages

	vecFrontLeft = vecFrontLeft + Vector ( 0, 0, 10 - DIST_TOP );
	vecFrontRight = vecFrontRight + Vector ( 0, 0, 10 - DIST_TOP );
	vecBackRight = vecBackRight + Vector ( 0, 0, 10 - DIST_TOP );
	vecBackLeft = vecBackLeft + Vector ( 0, 0, 10 - DIST_TOP );

	UTIL_TraceLine (vecFrontLeft, vecFrontRight,dont_ignore_monsters, ENT(m_pTankBSP->pev), &tr[0]);
	UTIL_TraceLine (vecFrontRight, vecBackRight,dont_ignore_monsters, ENT(m_pTankBSP->pev), &tr[1]);
	UTIL_TraceLine (vecBackRight, vecBackLeft,	dont_ignore_monsters, ENT(m_pTankBSP->pev), &tr[2]);
	UTIL_TraceLine (vecBackLeft, vecFrontLeft,	dont_ignore_monsters, ENT(m_pTankBSP->pev), &tr[3]);

	CBaseEntity *pEntity = NULL;

	for ( int i = 0 ; i < 4 ; i ++ )
	{
		if ( tr [ i ].pHit != NULL )
		{
			pEntity =  CBaseEntity :: Instance ( tr [ i ].pHit );

			if ( pEntity != NULL && pEntity->pev->takedamage  )
			{
				float fDamage;

				if ( FClassnameIs ( tr[i].pHit, "func_breakable" ) )
				{
					fDamage =  pEntity->pev->health;
				}
				else
				{
					fDamage = pev->velocity.Length() * 1.5 + 20;
				}

				pEntity->TakeDamage ( pev, pev , fDamage , DMG_CRUSH );
			}
		}
	}

	//rectification de la position de la camera

	vecCamAim = UpdateCam();

	if ( m_pCam->pev->origin != vecCamAim )
		m_pCam->pev->velocity = ( vecCamAim - m_pCam->pev->origin ) * 10;

	UpdateCamAngle ( vecCamAim, NEXTTHINK_TIME );



	//tir de la tourelle

	if ( ( m_pPlayer->pev->button & IN_ATTACK ) && ( gpGlobals->time > m_flLastAttack1 + TANK_REFIRE_DELAY ) )
	{
		Fire ( bCanon );
		bCanon = bCanon == TRUE ? FALSE : TRUE;

		EMIT_SOUND(ENT(pev), CHAN_AUTO, TIR_SOUND, 1, ATTN_NORM);
		m_flLastAttack1 = gpGlobals->time;

		m_pCam->pev->avelocity.x -= 45;

	}

	//tir de la mitrailleuse

	if ( m_pPlayer->pev->button & IN_ATTACK2 )
	{
		Vector posGun, dirGun;
		GetAttachment( 3, posGun, Vector ( 0, 0, 0 ) );
		UTIL_MakeVectorsPrivate( TourelleAngle(), dirGun, NULL, NULL );
		FireBullets( 1, posGun, dirGun, VECTOR_CONE_5DEGREES, 8192, BULLET_MONSTER_12MM );

		EMIT_SOUND(ENT(pev), CHAN_WEAPON, MITRAILLEUSE_SOUND, 1, ATTN_NORM);

		if ( !FStrEq(STRING(gpGlobals->mapname), "l3m10") && !FStrEq(STRING(gpGlobals->mapname), "l3m12")  && !FStrEq(STRING(gpGlobals->mapname), "l3m14")  )
		{			
			CSprite *pSprite = CSprite::SpriteCreate( SPRITE_MUZ, posGun, TRUE );
			pSprite->AnimateAndDie( 15 );
			pSprite->SetTransparency( kRenderTransAdd, 255, 255, 255, 255, kRenderFxNoDissipation );
			pSprite->SetAttachment( edict(), 4 );
			pSprite->SetScale( SPRITE_MUZ_SCALE );
		}


	}



	//sond du tank

	UpdateSound ();

	CSoundEnt::InsertSound ( bits_SOUND_DANGER, pev->origin + pev->velocity * 2.5, 150, NEXTTHINK_TIME );
	CSoundEnt::InsertSound ( bits_SOUND_PLAYER, pev->origin, 2000, 0.5 );



}