protected void paintTerrain(MapCell[,] map, Door d)
    {
        terrain = this.gameObject.GetComponent<Terrain>();
        float[,,] splatmapData = new float[terrain.terrainData.alphamapWidth, terrain.terrainData.alphamapHeight, terrain.terrainData.alphamapLayers];

        float[] splatWallWeights = new float[terrain.terrainData.alphamapLayers];
        splatWallWeights[0] = 0f;
        splatWallWeights[1] = 1f;

        float[] splatFloorWeights = new float[terrain.terrainData.alphamapLayers];
        splatFloorWeights[0] = 1f;
        splatFloorWeights[1] = 0f;

        int indexXmap, indexYmap;
        for (int i = 0; i < splatmapData.GetLength(0); i++)
        {
            for (int j = 0; j < splatmapData.GetLength(1); j++)
            {
                indexXmap = Mathf.Clamp(i/factor, 0, map.GetLength(0) - 1);
                indexYmap = Mathf.Clamp(j/factor, 0, map.GetLength(0) - 1);
                if (map[indexXmap, indexYmap].cellKind == MapCell.CellKind.WALL || map[indexXmap, indexYmap].cellKind == MapCell.CellKind.UNUSED)
                {
                    splatmapData = setSplatWeights(i, j, splatWallWeights, splatmapData);
                }
                else
                {
                    splatmapData = setSplatWeights(i, j, splatFloorWeights, splatmapData);
                }
            }
        }
        terrain.terrainData.SetAlphamaps(0, 0, splatmapData);
        terrain.Flush();
    }
Exemplo n.º 2
0
 protected override Tuple<MapCell[, ], Dictionary<MapCell, MapCell>> GenerateMap(MapCell[,] map)
 {
     var indexX = random.Next(2, map.GetLength(0) - 3);
     var indexY = random.Next(2, map.GetLength(1) - 3);
     for(int i = 0; i < map.GetLength(0); i++)
         map[i, indexY] = MapCell.Wall;
     for(int j = 0; j < map.GetLength(1); j++)
         map[indexX, j] = MapCell.Wall;
     return base.GenerateMap(map);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Clears the map.
 /// </summary>
 public void ClearAllCells(int width, int height)
 {
     lock (Cells)
     {
         Cells = new MapCell[width, height];
         for (var x = 0; x < Cells.GetLength(0); x++)
             for (var y = 0; y < Cells.GetLength(1); y++)
                 Cells[x, y] = new MapCell(this, new Point(x,y), DefaultFloorTile);
     }
 }
Exemplo n.º 4
0
 public StringBuilder SerializeMapOnly(MapCell[,] map)
 {
     var builder = new StringBuilder();
     int xUpperBound = map.GetLength(0);
     int yUpperBound = map.GetLength(1);
     for(int y = yUpperBound - 1; y >= 0; y--)
     {
         for(int x = 0; x < xUpperBound; x++)
             builder.Append(GetCellChar(map[x, y]));
         builder.AppendLine();
     }
     return builder;
 }
    private void CreateCollectables(MapCell[,] map, int zoneIDmark)
    {
        items = 0;

        for (int i = 0; i < map.GetLength(0); i++)
        {
            for (int j = 0; j < map.GetLength(1); j++)
            {
                if (map[i, j].zoneID > zoneIDmark)
                {
                    Instantiate(collectablePrefab, new Vector3(j * factor + factor / 2, 1f, i * factor + factor / 2), Quaternion.identity);
                    items++;
                }
            }
        }
    }
 float getSuitableHeightFromMap(MapCell[,] map, int indexX, int indexY, float[,] heights)
 {
     int indexXmap = Mathf.Clamp ((int)(indexX / factor), 0, map.GetLength(0)-1);
     int indexYmap = Mathf.Clamp ((int)(indexY / factor), 0, map.GetLength(1)-1);
     if (map[indexXmap, indexYmap].cellKind == MapCell.CellKind.WALKABLE && !map[indexXmap, indexYmap].isBorder)
         return 0f;
     else
         return wallheight;
 }