HexTile3Ds can now be positioned by specifying offset coordinates.

WorldChunkRefactoring
Martin Felis 2022-12-03 22:09:12 +01:00
parent 5d39ec2b21
commit d673b8c44f
2 changed files with 30 additions and 6 deletions

View File

@ -24,9 +24,29 @@ public class HexTile3D : Spatial
private SpatialMaterial _deepGrassMaterial; private SpatialMaterial _deepGrassMaterial;
private SpatialMaterial _previousMaterial; private SpatialMaterial _previousMaterial;
private HexGrid _hexGrid;
public HexCell Cell = new HexCell(); public HexCell Cell = new HexCell();
public bool IsMouseOver = false; 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; private TileType _type;
public 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. // Called when the node enters the scene tree for the first time.
public override void _Ready() public override void _Ready()
{ {

View File

@ -123,14 +123,13 @@ public class StreamContainer : Spatial
if (!_coordToTile.Keys.Contains(offsetCoords)) if (!_coordToTile.Keys.Contains(offsetCoords))
{ {
HexTile3D tile3d = (HexTile3D)_hexTileScene.Instance(); HexTile3D tile3d = (HexTile3D)_hexTileScene.Instance();
HexCell cell = new HexCell(); tile3d.OffsetCoords = offsetCoords;
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;
_activeTiles.AddChild(tile3d); _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)]; tile3d.Type = HexTile3D.ValidTileTypes[_tileTypeRandom.Next(HexTile3D.ValidTileTypes.Length)];
_coordToTile[offsetCoords] = tile3d; _coordToTile[offsetCoords] = tile3d;
} }