From d673b8c44fce8a3238adbdb56bc219d5f98990a0 Mon Sep 17 00:00:00 2001 From: Martin Felis Date: Sat, 3 Dec 2022 22:09:12 +0100 Subject: [PATCH] HexTile3Ds can now be positioned by specifying offset coordinates. --- scenes/HexTile3D.cs | 25 +++++++++++++++++++++++++ scenes/StreamContainer.cs | 11 +++++------ 2 files changed, 30 insertions(+), 6 deletions(-) diff --git a/scenes/HexTile3D.cs b/scenes/HexTile3D.cs index eea0071..e3fcc8e 100644 --- a/scenes/HexTile3D.cs +++ b/scenes/HexTile3D.cs @@ -24,9 +24,29 @@ public class HexTile3D : Spatial private SpatialMaterial _deepGrassMaterial; private SpatialMaterial _previousMaterial; + private HexGrid _hexGrid; + public HexCell Cell = new HexCell(); public bool IsMouseOver = false; + public Vector2 OffsetCoords + { + get + { + return Cell.OffsetCoords; + } + + set + { + Cell.OffsetCoords = value; + Transform tile3dTransform = this.Transform; + Vector2 cellPlaneCoords = _hexGrid.GetHexCenter(Cell); + tile3dTransform.origin.x = cellPlaneCoords.x; + tile3dTransform.origin.z = cellPlaneCoords.y; + this.Transform = tile3dTransform; + } + } + private TileType _type; public TileType Type { @@ -54,6 +74,11 @@ public class HexTile3D : Spatial } } + HexTile3D() + { + _hexGrid = new HexGrid(); + } + // Called when the node enters the scene tree for the first time. public override void _Ready() { diff --git a/scenes/StreamContainer.cs b/scenes/StreamContainer.cs index 017d62b..40bcffc 100644 --- a/scenes/StreamContainer.cs +++ b/scenes/StreamContainer.cs @@ -123,14 +123,13 @@ public class StreamContainer : Spatial if (!_coordToTile.Keys.Contains(offsetCoords)) { HexTile3D tile3d = (HexTile3D)_hexTileScene.Instance(); - HexCell cell = new HexCell(); - cell.OffsetCoords = offsetCoords; - Vector2 cellPlaneCoords = _hexGrid.GetHexCenter(cell); - Transform tile3dTransform = Transform.Identity; - tile3dTransform.origin = new Vector3(cellPlaneCoords.x, GD.Randf() * 0.1f, cellPlaneCoords.y); - tile3d.Transform = tile3dTransform; + tile3d.OffsetCoords = offsetCoords; _activeTiles.AddChild(tile3d); + Transform tileTransform = tile3d.Transform; + tileTransform.origin.y = GD.Randf() * 0.2f; + tile3d.Transform = tileTransform; + tile3d.Type = HexTile3D.ValidTileTypes[_tileTypeRandom.Next(HexTile3D.ValidTileTypes.Length)]; _coordToTile[offsetCoords] = tile3d; }