private void InitializeTerrainMap() { terrainMap = new MapSquareInfo[100, 100]; for (int xMap = 0; xMap < TerrainSize; xMap++) { for (int yMap = 0; yMap < TerrainSize; yMap++) { GameObject newTerrainTile = (GameObject)Instantiate(terrainTile); //newTerrainTile.transform.position = new Vector2( // xMap - (TerrainSize / 2), // yMap - (TerrainSize / 2)); newTerrainTile.transform.position = new Vector3( ((xMap - (TerrainSize / 2)) * 4), 0f, ((yMap - (TerrainSize / 2)) * 4)); newTerrainTile.transform.parent = this.gameObject.transform; newTerrainTile.name = "Terrain Tile [" + xMap + ", " + yMap + "]"; terrainMap[xMap, yMap] = new MapSquareInfo(); terrainMap[xMap, yMap].tile = newTerrainTile; terrainMap[xMap, yMap].mapPoint = new TerrainMapPoint() { x = xMap, y = yMap }; } } }
public bool TrySetPointForBiome(TerrainMapPoint point, Biome biome, out MapSquareInfo squareInfo) { if (GetTerrainType(point) != TerrainType.None) { squareInfo = null; return(false); } else { terrainMap[point.x, point.y].biomeid = biome.BiomeID; terrainMap[point.x, point.y].type = biome.TerrainType; squareInfo = terrainMap[point.x, point.y]; return(true); } }
public bool TryGetSquareInfo(TerrainMapPoint point, Direction dir, out MapSquareInfo squareInfo) { squareInfo = null; var newMapPoint = new TerrainMapPoint() { x = point.x, y = point.y }; switch (dir) { case Direction.Up: ++newMapPoint.x; break; case Direction.Down: --newMapPoint.x; break; case Direction.Left: --newMapPoint.y; break; case Direction.Right: ++newMapPoint.y; break; } if (IsValid(newMapPoint)) { squareInfo = terrainMap[newMapPoint.x, newMapPoint.y]; } return(squareInfo != null); }