public void AddTile(Coordinates tileCoords) { try { if (mapData.cellMap[tileCoords.X, tileCoords.Y] == 1 || chunkTiles[tileCoords.X, tileCoords.Y] != null) { return; } } catch (System.Exception e) { Debug.LogError(e); } mapData.cellMap[tileCoords.X, tileCoords.Y] = 1; mapData.groundMap = CellularAutomata.GenerateGroundMap(mapData.cellMap); mapData.airMap = CellularAutomata.GenerateCaveMap(mapData.cellMap); chunkTiles[tileCoords.X, tileCoords.Y] = CreateTile(tileCoords); if (gizmo) { debugGameObject.GetComponent <MeshRenderer>().material.mainTexture = TextureGenerator.GenerateTexture(mapData.cellMap, mapData.groundMap, mapData.airMap, mapData.waterMap); } Collider2D tempCollider = chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <EdgeCollider2D>(); if (tempCollider != null) { chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <EdgeCollider2D>().enabled = true; chunkTiles[tileCoords.X, tileCoords.Y].GetComponent <PlatformEffector2D>().enabled = true; } IterateTileToUpdate(tileCoords); }
public void RemoveTile(Tile tile) { Coordinates tileCoords = tile.Coords; chunkTiles[tileCoords.X, tileCoords.Y] = null; mapData.cellMap[tileCoords.X, tileCoords.Y] = 0; mapData.groundMap = CellularAutomata.GenerateGroundMap(mapData.cellMap); mapData.airMap = CellularAutomata.GenerateCaveMap(mapData.cellMap); if (gizmo) { debugGameObject.GetComponent <MeshRenderer>().material.mainTexture = TextureGenerator.GenerateTexture(mapData.cellMap, mapData.groundMap, mapData.airMap, mapData.waterMap); } chunkColliders.Remove(tile.gameObject.GetComponent <EdgeCollider2D>()); GameObject.Destroy(tile.gameObject); IterateTileToUpdate(tileCoords); }
public static int [,] GenerateWaterMap(int [,] cellMap) { int [,] waterMap = new int [cellMap.GetLength(0), cellMap.GetLength(1)]; int [,] flatMap = CellularAutomata.GenerateGroundMap(cellMap); for (int i = 0; i < cellMap.GetLength(0); i++) { for (int j = 0; j < cellMap.GetLength(1); j++) { //waterMap [i, j] = (cellularAutomata [i, j]==1)?0:1; } } for (int i = 0; i < 5; i++) { } return(waterMap); }
public MapData GenerateMapData(Coordinates mapCoordinates) { int[,] cellMap = CellularAutomata.GenerateCellularAutomata(seed, mapCoordinates, mapSize, mapSize, fillPercentage, bxsy); return(new MapData(cellMap, CellularAutomata.GenerateGroundMap(cellMap), CellularAutomata.GenerateCaveMap(cellMap), WaterAutomata.GenerateWaterMap(cellMap))); }