#pragma strict
private var pain_timer : float;
private var faceInterval : float;
var faceIntervalRate : float = 1.0;
var pain_interval : float = 1.0;
var okFace : GameObject;
var painFace : GameObject;
var leftOKFace : GameObject;
var rightOKFace : GameObject;
var leftPanicFace : GameObject;
var rightPanicFace : GameObject;
var panicFace : GameObject;
var finishFace : GameObject;

private var statusOKLeft : boolean;
private var statusOKRight : boolean;
private var statusPanicLeft : boolean;
private var statusPanicRight : boolean;
private var statusPain : boolean;
private var statusFinishFace : boolean;

function Start () {
	//ShowOKFace();
	statusOKLeft = false;
	statusOKRight = false;
	statusPanicLeft = false;
	statusPanicRight = false;
	statusPain = false;
	faceInterval = faceIntervalRate;
	//pain_timer = 0.0;
	// pain timer = 0
}


function Update() {
	faceInterval -= Time.deltaTime;
	if (faceInterval <= 0)
	{
		CheckFace();
		faceInterval = faceIntervalRate;
	}
}
function CheckFace () {

	// assess threat level
	// crashed
	if (statusFinishFace)
	{
		ShowFinishFace();
	}
	else if (statusPain)
	{
		ShowPainFace();
		//pain_timer -= Time.deltaTime;
		//if (pain_timer <= 0.0)
		//{
			//statusPain = false;
		//}	
	}
	// panic
	else if (statusPanicLeft)
	{
		if (statusPanicRight)
		{
			ShowPanicFace();
		}
		else
		{
			ShowLeftPanicFace();
		}
	}
	else if (statusPanicRight)
	{
		ShowRightPanicFace();
	}

	// warning
	else if (statusOKLeft)
	{
		if (statusOKRight)
		{
			ShowOKFace();
		}
		else
		{
			ShowLeftOKFace();
		}
	}
	else if (statusOKRight)
	{
		ShowRightOKFace();
	}
	
	// ok

	else
	{
		ShowOKFace();
	} 
	// won
	// upkeep
	statusOKLeft = false;
	statusOKRight = false;
	statusPanicLeft = false;
	statusPanicRight = false;
	statusPain = false;
}

function ShowPainFace()
{
	// show pain face
	painFace.SetActive(true);
	// hide other faces
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	rightPanicFace.SetActive(false);
	finishFace.SetActive(false);
	panicFace.SetActive(false);
}

function ShowOKFace()
{
	// show ok face
	okFace.SetActive(true);
	// hide other faces
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
	finishFace.SetActive(false);
}

function ShowFinishFace()
{
	finishFace.SetActive(true);	
	// hide other faces
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
}

function OnTriggerEnter(collision : Collider)
{
	//if (collision.gameObject.name != 'Terrain')
	
	//Debug.Log(collision);
	statusPain = true;
	//pain_timer = pain_interval;
}

function ShowLeftOKFace()
{
	// show left ok face
	leftOKFace.SetActive(true);
	// hide other faces
	okFace.SetActive(false);	
	rightOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
	finishFace.SetActive(false);
}

function ShowRightOKFace()
{
	// show right ok face
	rightOKFace.SetActive(true);
	// hide other faces
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
	finishFace.SetActive(false);
}

function ShowPanicFace()
{
	// show panic face
	panicFace.SetActive(true);
	// hide other faces
	leftPanicFace.SetActive(false);
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	finishFace.SetActive(false);
}

function ShowLeftPanicFace()
{
	// show left panic face
	leftPanicFace.SetActive(true);
	// hide other faces
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	rightPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
	finishFace.SetActive(false);
}

function ShowRightPanicFace()
{
	// show right panic face
	rightPanicFace.SetActive(true);
	// hide other faces
	okFace.SetActive(false);
	leftOKFace.SetActive(false);
	rightOKFace.SetActive(false);
	leftPanicFace.SetActive(false);
	painFace.SetActive(false);
	panicFace.SetActive(false);
	finishFace.SetActive(false);
}

function ActivateOKLeft()
{
	statusOKLeft = true;
}

function DeactivateOKLeft()
{
	statusOKLeft = false;
}

function ActivateOKRight()
{
	statusOKRight = true;
}

function DeactivateOKRight()
{
	statusOKRight = false;
}

function ActivatePanicLeft()
{
	statusPanicLeft = true;
}

function DeactivatePanicLeft()
{
	statusPanicLeft = false;
}

function ActivatePanicRight()
{
	statusPanicRight = true;
}

function DeactivatePanicRight()
{
	statusPanicRight = false;
}

function ActivateFinshFace()
{
	statusFinishFace = true;
}