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

public class player : MonoBehaviour{
    public int maxhealth = 15;
    public int currnethealth;
    public healthbar healthbar;
    [SerializeField]
    float movementSpeed = 1;
    public gameover gameover;
    Vector2 MouseInWorld = new Vector2();
    // Start is called before the first frame update
    void Start(){
        currnethealth = maxhealth;
        healthbar.SetMaxHealth(maxhealth);
    }

    // Update is called once per frame
    void Update(){
        MouseInWorld = Camera.main.ScreenToWorldPoint(Input.mousePosition);

        transform.position = Vector3.Lerp(transform.position, MouseInWorld, movementSpeed);

    }
    private void OnTriggerEnter2D(Collider2D other){
      if (other.gameObject.CompareTag("stars")){
            Destroy(other.gameObject);
        }
        if (other.gameObject.CompareTag("enemy")){
            damagehealth(5);
        }
    }
    public void damagehealth(int damage)
    {
        currnethealth -= damage;
        healthbar.SetHeath(currnethealth);

        if (currnethealth < 1)
        {
            gameover.setup();
        }
    }

}
