Tile.cs 787 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33
using UnityEngine;
using System.Collections;
using System;

public class Tile : MonoBehaviour, IComparable<Tile>
{
    public bool walkable = false;
    public int weight = 1;  // The cost for moving through this tile
                            // Set negative for unwalkable

    public int x;
    public int y;

    public Tile(bool walkable = true, int weight = 1)
    {
        this.walkable = walkable;
        this.weight = weight;
    }

    public int CompareTo(Tile other)
    {
        if (other == null)
            return 1;
        return (x + y) - (other.x - other.y);    // Same coordinate. Should be the same tiles
    }

    public String toString()
    {
        String str = "";
        str += "(" + x + ", " + y + ") " + " " + weight;
        return str;
    }
}