using UnityEngine;
using System.Collections;
public class CameraBehavior : MonoBehaviour
{
	public void startDamageCameraShake ()
	{
		StartCoroutine(shake(0.2f, 0.2f));
	}
	public void startRevolverFireCameraShake ()
	{
		StartCoroutine(shake(0.1f, 0.1f));
	}
	public void startShotgunFireCameraShake ()
	{
		StartCoroutine(shake(0.1f, 0.2f));
	}
	public void startDeathCameraShake ()
	{
		StartCoroutine(shake(.64f, 5.0f));
	}
	private IEnumerator shake (float duration, float magnitude)
	{
		float elapsed = 0.0f;
		Vector3 originalCamPos = this.gameObject.transform.position;
		while (elapsed < duration)	// Would be better as a for loop!
		{
			elapsed += Time.deltaTime;
			float percentComplete = elapsed / duration;         
			float damper = 1.0f - Mathf.Clamp(4.0f * percentComplete - 3.0f, 0.0f, 1.0f);
			float x = Random.value * 2.0f - 1.0f;
			float y = Random.value * 2.0f - 1.0f;
			x *= magnitude * damper / 10.0f;
			y *= magnitude * damper / 10.0f;
			x += originalCamPos.x;
			y += originalCamPos.z;
			this.gameObject.transform.position = new Vector3(x, originalCamPos.y, y);
			yield return null;		// Eh...
		}
		this.gameObject.transform.position = originalCamPos;
	}
}