using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;

public class PlayerScript : MonoBehaviour {
    public float speed = 0.5F;
	public int nbPoint = 0;
	public bool focus;
	static private bool[,] collection= new bool[3,3];
	private bool[] collTemp = new bool[3];
	public List<AudioSource> sounds;
    Rigidbody2D character;
	// Use this for initialization
	void Start () {
		character = GetComponent<Rigidbody2D>();
		sounds [1].Play ();
    }
	public void addBonus(bool sound){
		if(sound)
			sounds[0].Play ();
		int i = 0;
		while(i<3 && collTemp[i])
			i++;
		if(i<3)
			collTemp[i]=true;
	}
	public void debugBonus(){
		int i2 = -1;
		Scene s = SceneManager.GetActiveScene ();
		switch (s.name) {
			case "Level1":
				i2 = 0;
				break;
			case "level3":
				i2 = 1;
				break;
			case "Level2":
				i2 = 2;
				break;
		}
		Debug.Log (s.name+" "+i2);
		for (int i = 0; i < 3; i++) {
			collection [i2, i] = collTemp [i];
		}
		for(int i=0;i<3;i++){
			for(i2=0;i2<3;i2++){
				Debug.Log("Level "+i+" Collectable "+i2+ " : "+collection[i,i2]);
			}
		}
	}
    private void FixedUpdate()
    {
		if(focus){
			float moveH = Input.GetAxis("Horizontal");
        	float moveV = Input.GetAxis("Vertical");
       		Vector2 movement = new Vector2(moveH, moveV);
        	movement *= speed;
        	character.AddForce(movement);
			if (moveH == 0 && moveV == 1) {
				this.transform.rotation = Quaternion.AngleAxis (90,Vector3.forward);
			}
			else if (moveH == 1 && moveV == 0) {
				this.transform.rotation = Quaternion.AngleAxis (0,Vector3.forward);
			}
			else if (moveH == 1 && moveV == 1) {
				this.transform.rotation = Quaternion.AngleAxis (45,Vector3.forward);
			}
			if (moveH == 0 && moveV == -1) {
				this.transform.rotation = Quaternion.AngleAxis (270,Vector3.forward);
			}
			else if (moveH == -1 && moveV == 0) {
				this.transform.rotation = Quaternion.AngleAxis (180,Vector3.forward);
			}
			else if (moveH == -1 && moveV == -1) {
				this.transform.rotation = Quaternion.AngleAxis (225,Vector3.forward);
			}
			else if (moveH == 1 && moveV == -1) {
				this.transform.rotation = Quaternion.AngleAxis (315,Vector3.forward);
			}
			else if (moveH == -1 && moveV == 1) {
				this.transform.rotation = Quaternion.AngleAxis (135,Vector3.forward);
			}
		}
    }
	public bool[,] getCollectable(){
		return collection;
	}
}
