using UnityEngine;
using UnityEngine.InputSystem;

public class BirdBehavoir : MonoBehaviour
{
    [SerializeField] private float flapSpeed = 1.5f;
    [SerializeField] private float rotationSpeed = 10f;
    
    private Rigidbody2D _rigidbody2D;
    
    void Start()
    {
        _rigidbody2D = GetComponent<Rigidbody2D>();
    }

    void Update()
    {
        if(Keyboard.current.spaceKey.wasPressedThisFrame || Mouse.current.leftButton.wasPressedThisFrame){
            _rigidbody2D.linearVelocity = Vector2.up * flapSpeed;
        }
    }
    
    void FixedUpdate(){
        transform.rotation = Quaternion.Euler(0, 0, _rigidbody2D.linearVelocity.y * rotationSpeed);
    }

    void OnCollisionEnter2D(Collision2D collision)
    {
        GameManager.instance.GameOver();
    }
    
}
