using UnityEngine;
using System.Collections;

public abstract class Player : Character {
	
	private int lives;

	//sotto le fiamme..
	private float maxLifeLostTime;
	private bool isBurning;
	private float timeInFlame; //contenitore del tempo trascorso sotto il fuoco

	//modalità invincibile dopo essere stati colpiti
	private float invincibilityTime;
	private float timeInInvincibility; //contenitore del tempo trascorso 
	private bool invincibilityMode;

	// Use this for initialization
	void Start () {
		lives = 3;
		invincibilityMode = false;
		invincibilityTime = 1;
		maxLifeLostTime = 2;
	}
	
	// Update is called once per frame
	void Update () {
		
	}

	public void FixedUpdate () {
		// move with keyboard
		if (networkView.isMine) {
			float deltaX = Input.GetAxis ("Horizontal");
			float deltaY = -Input.GetAxis ("Vertical");
			rigidbody.AddForce(new Vector3(deltaY, 0, deltaX)*acceleration, ForceMode.Force);
		}
		//Sta bruciando?
		if (isBurning && !invincibilityMode) 
		{
			Brucia();
		}

		if(invincibilityMode)
		{
			timeInInvincibility += Time.deltaTime;
			if(timeInInvincibility >= invincibilityTime) invincibilityMode=false;
		}
	}

	public void Brucia()
	{
		isBurning = true;
		timeInFlame += Time.deltaTime;

		if (timeInFlame >= maxLifeLostTime)
		{
			LostLife();
			isBurning=false;
		}
	}

	public void LostLife()
	{
		lives--;
		invincibilityMode = true;
	}


}
