Exemplo n.º 1
0
        public void GetWalkableNeighbours(int cellIndex, List <int> resultNeighbours)
        {
            resultNeighbours.Clear();
            Vector2Int cellCoords = MapUtils.IndexToCoords(cellIndex, sizeX);

            for (int i = -1; i <= 1; i++)
            {
                for (int j = -1; j <= 1; j++)
                {
                    if (i == 0 && j == 0)
                    {
                        continue;
                    }

                    int checkX = cellCoords.X + i;
                    int checkY = cellCoords.Y + j;

                    if (checkX >= 0 && checkX < sizeX && checkY >= 0 && checkY < sizeY)
                    {
                        int neighbourIndex = MapUtils.CoordsToIndex(checkX, checkY, sizeX);

                        if (isWalkable[neighbourIndex])
                        {
                            resultNeighbours.Add(neighbourIndex);
                        }
                    }
                }
            }
        }
Exemplo n.º 2
0
        public Graph GenerateGraph()
        {
            List <Graph.Node> nodes = new List <Graph.Node>();
            List <Graph.Edge> edges = new List <Graph.Edge>();

            Graph.Node[,] nodeMap = new Graph.Node[Width, Height];

            for (int y = 0; y < Height; y++)
            {
                for (int x = 0; x < Width; x++)
                {
                    Graph.Node node = new Graph.Node(new Vector3(x, y));
                    nodes.Add(node);
                    nodeMap[x, y] = node;

                    foreach (Vector2Int neighbour in _nodeNeighbours)
                    {
                        int xx = x + neighbour.x;
                        int yy = y + neighbour.y;

                        if (MapUtils.IsInsideMap(xx, yy, Width, Height))
                        {
                            edges.Add(new Graph.Edge(MapUtils.CoordsToIndex(x, y, Width), MapUtils.CoordsToIndex(xx, yy, Width)));
                        }
                    }
                }
            }

            return(new Graph(nodes.ToArray(), edges.ToArray(), new TileGraphMap(Width, Height, nodeMap)));
        }
        private void GenerateQuad(int x, int y, Vector3[] verts, Vector2[] uvs, int[] tris, int width, int bitmask)
        {
            int quadIndex = MapUtils.CoordsToIndex(x, y, width);
            int vertIndex = quadIndex * 4;
            int triIndex  = quadIndex * 6;

            int vertWidth = width * 2;

            // Generate verts
            verts[vertIndex]     = new Vector3(x, y) + Vector3.forward;
            verts[vertIndex + 1] = new Vector3(x + 1, y) + Vector3.forward;
            verts[vertIndex + 2] = new Vector3(x, y + 1) + Vector3.forward;
            verts[vertIndex + 3] = new Vector3(x + 1, y + 1) + Vector3.forward;

            // Generate UVs
            Vector2[] uv = GetUVProvider().GetUVs(bitmask);
            uvs[vertIndex]     = uv[0];
            uvs[vertIndex + 1] = uv[1];
            uvs[vertIndex + 2] = uv[2];
            uvs[vertIndex + 3] = uv[3];

            // Generate tris
            tris[triIndex + 2] = vertIndex;
            tris[triIndex + 1] = vertIndex + 1;
            tris[triIndex + 0] = vertIndex + 2;

            tris[triIndex + 5] = vertIndex + 1;
            tris[triIndex + 4] = vertIndex + 3;
            tris[triIndex + 3] = vertIndex + 2;
        }
Exemplo n.º 4
0
 private TileTypeReference[] EnflattenTiles(TileTypeReference[,] walls)
 {
     TileTypeReference[] flattened = new TileTypeReference[Width * Height];
     for (int y = 0; y < Height; y++)
     {
         for (int x = 0; x < Width; x++)
         {
             flattened[MapUtils.CoordsToIndex(x, y, Width)] = walls[x, y];
         }
     }
     return(flattened);
 }
Exemplo n.º 5
0
 public bool IsWalkable(int x, int y)
 {
     return(isWalkable[MapUtils.CoordsToIndex(x, y, sizeX)]);
 }
Exemplo n.º 6
0
 public void SetWalkable(int x, int y, bool walkable)
 {
     isWalkable[MapUtils.CoordsToIndex(x, y, sizeX)] = walkable;
 }
Exemplo n.º 7
0
 int CoordsToIndex(int x, int y)
 {
     return(MapUtils.CoordsToIndex(x, y, mapSizeX));
 }