using Assets.Scripts.API;
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using Assets.Scripts;

public class SimpleEnnemy : MonoBehaviour
{
    private Transform _position;
    private GameObject _player;

    public float Speed = 2f;

	void Start ()
	{
	    _position = GetComponent<Transform>();
        _player = GameObject.FindWithTag("Player");
	}
	
	void Update ()
	{
	    _position.Translate(new Vector3(Speed * Time.deltaTime * -1, 0, 0));

	    if (_position.position.x < Camera.main.ScreenToWorldPoint(new Vector3(0, 0, 0)).x)
	    {
	        gameObject.SetActive(false);
	    }
	}

    void OnTriggerEnter2D(Collider2D other)
    {
        Destroy(gameObject);

        _player.GetComponent<Player>().Battery -= 8;
        _player.GetComponent<Player>().SetBlinking();
        GetScores(); // TODO: Successfully get scores from API
    }

	void GetScores() {
        Debug.Log("Getting scores...");
        Server.GetScores();
        Debug.Log("Got scores.");
	}
}
