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

public class PlayerController : MonoBehaviour
{

    public float speed = 10.0f;
    public int points = 0;
    public bool silenced = false;
    public float silenceTime = 10.0f;
    
    void Update()
    {
        if (Input.GetKey(KeyCode.DownArrow))
        {
            this.transform.position -= new Vector3 (0,80,0) * speed * Time.deltaTime;
            
        }
        if (Input.GetKey(KeyCode.UpArrow))
        {
            this.transform.position += new Vector3(0, 80, 0) * speed * Time.deltaTime;
        }
        if (Input.GetKey(KeyCode.RightArrow))
        {
           
            transform.position += Vector3.right * speed*20 * Time.deltaTime;

        }
        else if (Input.GetKey(KeyCode.LeftArrow))
        {
            
            transform.position += Vector3.left * speed*20 * Time.deltaTime;

        }

        if (silenced)
        {
            silenceTime -= Time.deltaTime;
            if (silenceTime < 0)
            {
                silenced = false;
                silenceTime = 10f;
            }
        }
    }

    void OnTriggerEnter2D(Collider2D other)
    {

        GameObject.Find("Score").GetComponent<Scorekeeper>().Score(other.gameObject.GetComponent<PickUp>().value);
        points += other.gameObject.GetComponent<PickUp>().value;
        if(other.gameObject.GetComponent<PickUp>().special)
        {
            //silence for x seconds
            silenced = true;
        }
        Debug.Log("destroyed on player");
        GameObject.Find("PickupSpawner").GetComponent<PickupController>().ResetSpawnPoint(int.Parse(other.gameObject.name));
        
        Destroy(other.gameObject);
    }
}
