public void PutLac(HexagonalGrid grid) { if (!doLake) { return; } TileProperties tile = grid.GetTile(source); if (!tile) { return; } TileProperties neigh = tile.GetNeighbor(counterClockwise ? direction.Previous().Previous() : direction.Next().Next()); if (!neigh) { return; } if (state == 0) { neigh.asLake = true; state = 1; } else { TileProperties lakePos = neigh.GetNeighbor(counterClockwise ? direction.Previous() : direction.Next()); lakePos.asLake = true; state = 0; } }
public void ExtendRiver(HexagonalGrid grid) { TileProperties tile = grid.GetTile(source); if (!tile) { return; } TileProperties neigh = tile.GetNeighbor(counterClockwise ? direction.Previous().Previous() : direction.Next().Next()); if (!neigh) { return; } if (state == 0) { force--; neigh.SetRiver(direction, this); state = 1; } else { force--; neigh.SetRiver(counterClockwise ? direction.Previous() : direction.Next(), this); source = neigh.Coordinates; state = 0; } }
public Map FromHeightmap(Texture2D _heightmap, TileSet tileSet, float heightScaling = 1) { var width = _heightmap.width; var height = _heightmap.height; var dimensions = new Vector2(); dimensions.x = CELL_HEIGHT / Mathf.Sqrt(3) * 2; dimensions.y = CELL_HEIGHT; var grid = new HexagonalGrid(width, height, dimensions); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var color = _heightmap.GetPixel(x, y); var grayValue = color.grayscale; GameObject tile = Instantiate(GetTileFromColor(color, tileSet).gameObject); grid.AddCell(tile, x, y); grid.SetHeightOfCell(grayValue * heightScaling, x, y); } } //TODO Set up neighbouring relations on grid addition //As the hex grid is static, neighbouring relations are only defined by row. Hence they can be known prior to fully filling in the grid. // The moment a new gameobject is added, all neighbours can be updated, and add the new cell to their list. //Make sure to add existing ones to the list of the new cell too. for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { var tile = grid.GetTile(x, y); var neighbouringGameObjects = grid.FindNeighboursOfTile(x, y); Tile component = tile.GetComponent <Tile>(); //Damn fancy LINQ stuff, VS refactor FTW List <Tile> neighbours = (from item in neighbouringGameObjects.Keys select item.GetComponent <Tile>()).ToList(); foreach (var item in neighbouringGameObjects) { var obj = item.Key; if (component.Type == obj.GetComponent <Tile>().Type) { component.Edges.DisableEdge(item.Value); } } component.NeighbouringTiles = neighbours; } } return(grid); }
private void MainMenuFileNew_Click(object sender, EventArgs e) { var newGridWindow = new NewFileWindow(); newGridWindow.ShowDialog(this); if (newGridWindow.GridSize > 0) { EditingGrid = new HexagonalGrid(newGridWindow.GridSize); MainEditorPanel.Refresh(); } }
public void PointyPropertiesTest(HexagonalGridType type) { var grid = new HexagonalGrid(type, InscribedRadius); Assert.AreEqual(grid.InscribedRadius, InscribedRadius); Assert.AreEqual(grid.DescribedRadius, DescribedRadius); Assert.AreEqual(grid.InscribedDiameter, InscribedRadius * 2); Assert.AreEqual(grid.DescribedDiameter, DescribedRadius * 2); Assert.AreEqual(grid.HorizontalOffset, InscribedRadius * 2.0f); Assert.AreEqual(grid.VerticalOffset, DescribedRadius * 1.5f); Assert.AreEqual(grid.Side, DescribedRadius); Assert.AreEqual(grid.AngleToFirstNeighbor, 0.0f); }
void Start() { cam = this.GetComponent <Camera>(); grid = HexagonalGrid.Instance; AkSoundEngine.SetRTPCValue("AMBIANCE_VOLUME_DESERT", 0); AkSoundEngine.SetRTPCValue("AMBIANCE_VOLUME_PRAIRIE", 0); AkSoundEngine.SetRTPCValue("AMBIANCE_VOLUME_WATER", 0); AkSoundEngine.SetRTPCValue("AMBIANCE_VOLUME_WETLANDS", 0); AkSoundEngine.PostEvent("Play_DESERT_Pl", this.gameObject); AkSoundEngine.PostEvent("Play_PRAIRIE_Pl", this.gameObject); AkSoundEngine.PostEvent("Play_WATER_Pl", this.gameObject); AkSoundEngine.PostEvent("Play_WETLAND_Pl", this.gameObject); }
public void CoordinateConversionTest( [Values] HexagonalGridType type, [Values(-13, -8, 0, 15, 22)] int offsetX, [Values(-13, -8, 0, 15, 22)] int offsetY) { var grid = new HexagonalGrid(type, InscribedRadius); var offset = new Offset(offsetX, offsetY); var axial = grid.ToAxial(offset); var cubic = grid.ToCubic(offset); Assert.IsTrue(cubic.IsValid(), $"Invalid cubic coordinate: {cubic.X}-{cubic.Y}-{cubic.Z}"); Assert.AreEqual(offset, grid.ToOffset(axial)); Assert.AreEqual(offset, grid.ToOffset(cubic)); Assert.AreEqual(axial, grid.ToAxial(offset)); Assert.AreEqual(axial, grid.ToAxial(cubic)); Assert.AreEqual(cubic, grid.ToCubic(offset)); Assert.AreEqual(cubic, grid.ToCubic(axial)); }
public void Vector3ConversionTest( [Values] HexagonalGridType type, [Values(-13, -8, 0, 15, 22)] int offsetX, [Values(-13, -8, 0, 15, 22)] int offsetY) { var grid = new HexagonalGrid(type, InscribedRadius); var offset = new Offset(offsetX, offsetY); var axial = grid.ToAxial(offset); var cubic = grid.ToCubic(offset); var fromOffset = grid.ToVector3(offset); var fromAxial = grid.ToVector3(axial); var fromCubic = grid.ToVector3(cubic); Assert.IsTrue(fromOffset.SimilarTo(fromAxial), $"Expected: {fromAxial}; Actual: {fromOffset}"); Assert.IsTrue(fromOffset.SimilarTo(fromCubic), $"Expected: {fromCubic}; Actual: {fromOffset}"); Assert.AreEqual(offset, grid.ToOffset(fromOffset)); Assert.AreEqual(axial, grid.ToAxial(fromAxial)); Assert.AreEqual(cubic, grid.ToCubic(fromCubic)); }
public MainWindow() { InitializeComponent(); //Setting double buffering SetDoubleBuffered(MainEditorPanel); //Setting grid EditingGrid = new HexagonalGrid(); //Setting variables for map dragging shiftVector = new Point(MainEditorPanel.Width / 2, MainEditorPanel.Height / 2); dragVector = new Point(0, 0); //Setting variables for edditing currentTileBrush = null; brushCovering = new List <HexagonCell>(); //Detting variables for cells selecting selectedCells = new List <HexagonCell>(); }
public void IsNeighborTest( [Values] HexagonalGridType type, [Values(-13, -8, 0, 15, 22)] int offsetX, [Values(-13, -8, 0, 15, 22)] int offsetY, [Values(-1, 0, 1, 2, 3, 4, 5, 6)] int neighborIndex) { var grid = new HexagonalGrid(type, InscribedRadius); var offset = new Offset(offsetX, offsetY); var axial = grid.ToAxial(offset); var cubic = grid.ToCubic(offset); Assert.IsTrue(cubic.IsValid(), $"Invalid cubic coordinate: {cubic.X}-{cubic.Y}-{cubic.Z}"); var oNeighbor = grid.GetNeighbor(offset, neighborIndex); var aNeighbor = grid.GetNeighbor(axial, neighborIndex); var cNeighbor = grid.GetNeighbor(cubic, neighborIndex); Assert.IsTrue(cNeighbor.IsValid(), $"Invalid cubic coordinate: {cNeighbor.X}-{cNeighbor.Y}-{cNeighbor.Z}"); Assert.IsTrue(grid.IsNeighbors(offset, oNeighbor), $"Neighbor1={offset}; Neighbor2={oNeighbor}; Index={neighborIndex};"); Assert.IsTrue(grid.IsNeighbors(axial, aNeighbor), $"Neighbor1={axial}; Neighbor2={aNeighbor}; Index={neighborIndex};"); Assert.IsTrue(grid.IsNeighbors(cubic, cNeighbor), $"Neighbor1={cubic}; Neighbor2={cNeighbor}; Index={neighborIndex};"); }
public void NeighborsOrderTest( [Values] HexagonalGridType type, [Values(-13, -8, 0, 15, 22)] int offsetX, [Values(-13, -8, 0, 15, 22)] int offsetY, [Values(-1, 0, 1, 2, 3, 4, 5, 6)] int neighborIndex) { var grid = new HexagonalGrid(type, InscribedRadius); var offset = new Offset(offsetX, offsetY); var axial = grid.ToAxial(offset); var cubic = grid.ToCubic(offset); var oNeighbor = grid.GetNeighbor(offset, neighborIndex); var aNeighbor = grid.GetNeighbor(axial, neighborIndex); var cNeighbor = grid.GetNeighbor(cubic, neighborIndex); Assert.IsTrue(cNeighbor.IsValid(), $"Invalid cubic coordinate: {cNeighbor.X}-{cNeighbor.Y}-{cNeighbor.Z}"); var fromAxial = grid.ToOffset(aNeighbor); var fromCubic = grid.ToOffset(cNeighbor); Assert.AreEqual(oNeighbor, fromAxial, $"Center=({offset} - {axial}); Current=({oNeighbor} - {aNeighbor}); Index={neighborIndex};"); Assert.AreEqual(oNeighbor, fromCubic, $"Center=({offset} - {cubic}); Current=({oNeighbor} - {cNeighbor}); Index={neighborIndex};"); }
private void Awake() { grid = GetComponent <HexagonalGrid>(); }
static void hexagonalGrid() { Console.WriteLine("Hexagonal Grid"); Console.WriteLine(HexagonalGrid.hexagonalGrid("110", "110")); }
public void setController(HexagonalGrid controller) { _controller = controller; }