using UnityEngine;
using System.Collections;
using UnityStandardAssets.CrossPlatformInput;


public class Player : Character {
	
	void Start () {
		m_health = getMaxHealth ();
		m_isPlayer = true;
	}
	
	void FixedUpdate () {
		Vector3 tmp = Camera.main.transform.position;
		tmp.x = (m_damageTime > 0f) ? (float) HelperFunctions.getScaledRandom(-0.3f,0.3f) : 0f;
		Camera.main.transform.position = tmp;
		Vector2 mov = new Vector2(CrossPlatformInputManager.GetAxis ("Horizontal"), 
		                          0);
		m_blocking = Input.GetKey (KeyCode.S);
		if (Input.GetMouseButton (0)) {
			Vector3 target =  (Camera.main.ScreenToWorldPoint(Input.mousePosition));
			attack(new Vector2(target.x, target.y), 0);
		} if (Input.GetMouseButton (1)) {
			Vector3 target =  (Camera.main.ScreenToWorldPoint(Input.mousePosition));
			attack(new Vector2(target.x, target.y), 1);
		}
		commonUpdate (mov, Input.GetKey(KeyCode.Space));
		if (m_win) {
			winCallback();
			m_win = false;
		}
	}
	new public void OnGUI() {
		base.OnGUI ();
		if (m_damageTime > 0) {
			GUI.DrawTexture(new Rect(0f, 0f, Screen.width, Screen.height), m_otherTextures[2]);
		}
	}

	public void winCallback() {
		GameController cont = GameObject.FindWithTag("gamecontroller").GetComponent<GameController>();
		cont.queueEnemy();
	}
}
