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

public class BoardEntity : MonoBehaviour
{
    public Vector2Int BoardPosition = Vector2Int.zero;
    public bool m_Talkable = false;
    protected SpriteRenderer m_SpriteRenderer;
    protected bool m_Remove = false;
    private void Awake()
    {
        m_SpriteRenderer = GetComponent<SpriteRenderer>();

        OnAwake();
    }

    protected virtual void OnAwake()
    {

    }

    public bool Move(Vector2Int moveDir)
    {
        print("Move");
        Vector2Int target = BoardPosition + moveDir;
        m_SpriteRenderer.sortingOrder = 1024 - BoardPosition.y;
        if (BoardManager.CheckCollision(target)){
            BoardPosition = target;
            return true;
        }
        return false;
    }

    //BoardUpdate is called by the BoardManager
    public bool BoardUpdate()
    {
        transform.position = (Vector2)BoardPosition;
        return m_Remove;
    }

    public void SetPosition( Vector2Int newPos){
        BoardPosition = newPos;
        m_SpriteRenderer.sortingOrder = 1024 - BoardPosition.y;
    }
}
