public float DstimateDistance(I_PathNode a, I_PathNode b) { DiamondGrid gridA = a as DiamondGrid; DiamondGrid gridB = b as DiamondGrid; return(Math.Abs(gridA.WorldX - gridB.WorldX) + Math.Abs(gridA.WorldZ - gridB.WorldZ)); }
// public void SetAdjacent(I_PathNode[] adjacent) { m_Adjacent = adjacent; } public float Distance(DiamondGrid other) { float cx = WorldX - other.WorldX; float cz = WorldZ - other.WorldZ; return((float)Math.Sqrt(cx * cx + cz * cz)); }
//1.732101616628176 public float AdjacentDistance(I_PathNode a, I_PathNode b) { DiamondGrid gridA = a as DiamondGrid; DiamondGrid gridB = b as DiamondGrid; return(gridA.Distance(gridB)); }
public static bool __CompilerHint__Diamond__TileCell() { var grid = new DiamondGrid<TileCell[]>(1, 1); foreach(var point in grid) { grid[point] = new TileCell[1]; } var shapeStorageInfo = new ShapeStorageInfo<DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo<TileCell>(shapeStorageInfo); return grid[grid.First()][0] == null || shapeInfo.Translate(DiamondPoint.Zero) != null; }
public static bool __CompilerHint2__Diamond__TileCell() { //Ensures abstract super classes for base grids gets created var grid = new DiamondGrid<TileCell>(1, 1, p => p == DiamondPoint.Zero, x => x, x => x, new List<DiamondPoint>()); //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo<DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo<TileCell>(shapeStorageInfo); return grid[grid.First()] == null || shapeInfo.Translate(DiamondPoint.Zero) != null; }
/** Call this method if you use a DiamondGrid. Replace the type __CellType to whatever type you have in your grid. You can call the method anywhere in your code. if(!__CompilerHint__Diamond()) return; This methods always returns true. @since 1.6 */ public static bool __CompilerHint1__Diamond() { //Ensures abstract super classes for base grids gets created var grid = new DiamondGrid<__CellType[]>(1, 1); foreach(var point in grid) { grid[point] = new __CellType[1]; } //Ensures shape infpo classes get created var shapeStorageInfo = new ShapeStorageInfo<DiamondPoint>(new IntRect(), p => true); var shapeInfo = new DiamondShapeInfo<__CellType>(shapeStorageInfo); return grid[grid.First()][0] == null || shapeInfo.Translate(DiamondPoint.Zero) != null; }
/** * This method is provided for generic testing purposes. * It should generally not be used in production code: it may * be slow and not type-safe. */ public static TGrid MakeGrid <TPoint, TGrid, TCell>(int width, int height, TPoint offset) where TPoint : IGridPoint <TPoint> where TGrid : IGrid <TCell, TPoint> { if (typeof(TPoint) == typeof(PointyHexPoint)) { Debug.Assert(typeof(TGrid) == typeof(PointyHexGrid <TCell>)); return((TGrid)(object)new PointyHexGrid <TCell>( width, height, x => PointyHexGrid <TCell> .DefaultContains(x, width, height), (PointyHexPoint)(object)offset)); } if (typeof(TPoint) == typeof(FlatHexPoint)) { Debug.Assert(typeof(TGrid) == typeof(FlatHexGrid <TCell>)); return((TGrid)(object)new FlatHexGrid <TCell>( width, height, x => FlatHexGrid <TCell> .DefaultContains(x, width, height), (FlatHexPoint)(object)offset)); } if (typeof(TPoint) == typeof(RectPoint)) { Debug.Assert(typeof(TGrid) == typeof(RectGrid <TCell>)); return((TGrid)(object)new RectGrid <TCell>( width, height, x => RectGrid <TCell> .DefaultContains(x, width, height), (RectPoint)(object)offset)); } if (typeof(TPoint) == typeof(DiamondPoint)) { Debug.Assert(typeof(TGrid) == typeof(DiamondGrid <TCell>)); return((TGrid)(object)new DiamondGrid <TCell>( width, height, x => DiamondGrid <TCell> .DefaultContains(x, width, height), (DiamondPoint)(object)offset)); } throw new NotSupportedException(); }
private void BuildGrid() { grid = DiamondGrid <SpriteCell> .ThinRectangle(5, 5); map = new DiamondMap(cellPrefab.Dimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY(); foreach (DiamondPoint point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[point.GetColor4()]; cell.name = point.ToString(); grid[point] = cell; } }
private void BuildGrid() { grid = DiamondGrid<SpriteCell>.ThinRectangle(5, 5); map = new DiamondMap(cellPrefab.Dimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .To3DXY(); foreach (DiamondPoint point in grid) { var cell = Instantiate(cellPrefab); Vector3 worldPoint = map[point]; cell.transform.parent = root.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = worldPoint; cell.Color = ExampleUtils.Colors[point.GetColor4()]; cell.name = point.ToString(); grid[point] = cell; } }