using UnityEngine;
using System.Collections.Generic;

public class Player : MonoBehaviour {

	public List<Human> humans;
	public int playerNum;
	int selectedHumanIdx = 0;
	Human selectedHuman { get { return humans[selectedHumanIdx]; } }
	public Color selectedColor;

	// player 1 = I, O, P
	// player 2 = F, G, H
	public KeyCode keyA;
	public KeyCode keyB;
	public KeyCode keyC;


	public void SelectNext () {
		SelectHumanIdx((selectedHumanIdx + 1) % humans.Count);
	}

	void Start () {
		selectedHuman.Selected = true;

		foreach (Human human in humans)
			human.selectedArrow.GetComponent<SpriteRenderer>().color = selectedColor;
	}

	void SelectHumanIdx (int idx) {
		selectedHuman.Selected = false;
		selectedHumanIdx = idx;
		selectedHuman.Selected = true;
	}

	void Update () {
		float h = Input.GetAxis("Horizontal" + playerNum);
		float v = Input.GetAxis("Vertical" + playerNum);
		selectedHuman.Move(new Vector2(h, v));

		bool[] keys = { Input.GetKey(keyA), Input.GetKey(keyB), Input.GetKey(keyC) };

//		if (keys [0]) MAL, GETKEYDOWN EN VEZ DE GETKEY
//			SelectNext();

		for (int i = 0; i < humans.Count; i++) {
			if (keys[i]) {
				SelectHumanIdx(i);
				break;
			}
		}
	}

}
