Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Scripts / NPC / Pathfinding / Node.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using MyCollections.Generic;

public class Node : IheapItem<Node>
{
    public Node parent;
    public bool walkable;
    public Vector2 worldPos;
    public int movementPenalty;

    public int gridX, gridY;

    public int gCost;
    public int hCost; //heuristic cost

    private int heapIndex;

    public int FCost => gCost + hCost;

    public int HeapIndex 
    {
        get => heapIndex;

        set => heapIndex = value;
    }

    public int CompareTo(Node nodeToCompare)
    {
        int compare = FCost.CompareTo(nodeToCompare.FCost);
        if (compare == 0)
        {
            compare = hCost.CompareTo(nodeToCompare.hCost);
        }

        return -compare;
    }

    public Node(bool walkable, Vector2 worldPos, int gridX, int gridY, int movementPenalty)
    {
        this.walkable = walkable;
        this.worldPos = worldPos;
        this.gridX = gridX;
        this.gridY = gridY;
        this.movementPenalty = movementPenalty;
    }
}