Esempio n. 1
0
    public List <tile> GetNeighbor(tile cur)
    {
        List <tile> p   = new List <tile>();
        Vector2     pos = cur.getPos();
        int         x   = Mathf.RoundToInt(pos.x);
        int         y   = Mathf.RoundToInt(pos.y);

        if (y + 1 <= fieldHeight)
        {
            p.Add(tileField[(y + 1) * fieldWidth + x]);
        }
        if (y - 1 >= 0)
        {
            p.Add(tileField[(y - 1) * fieldWidth + x]);
        }
        if (x + 1 <= fieldWidth)
        {
            p.Add(tileField[y * fieldWidth + (x + 1)]);
        }
        if (x - 1 >= 0)
        {
            p.Add(tileField[y * fieldWidth + (x - 1)]);
        }

        return(p);
    }