private void BuildGrid() { const int side = 5; grid = FlatTriGrid<SpriteCell> .BeginShape() .Hexagon(side) .EndShape(); map = new FlatTriMap(TriDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .AnchorCellMiddleCenter() .To3DXY(); foreach(FlatTriPoint point in grid) { SpriteCell 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.GetColor2() * 2]; cell.name = point.ToString(); cell.SetAngle(360 / FlatTriPoint.SpliceCount * point.I); grid[point] = cell; } }
private void SetCellSprite(FlatTriGrid <int> vertexGrid, PointyHexPoint point, TileCell tileCell) { var cell = (SpriteCell)tileCell; var vertices = from vertexPoint in point.GetVertices() select vertexGrid[vertexPoint]; int imageIndex = vertices.Reverse().Aggregate((x, y) => (x << 1) + y); float zRotation = 30; for (int i = 0; i < 6; i++) { if (frameIndices[imageIndex] != -1) { cell.FrameIndex = frameIndices[imageIndex]; cell.transform.SetRotationZ(zRotation); break; } zRotation += 60; imageIndex = RotateEdgeNumberClockWise(imageIndex); } }
private void BuildGrid() { const int side = 5; grid = FlatTriGrid <SpriteCell> .BeginShape() .Hexagon(side) .EndShape(); map = new FlatTriMap(TriDimensions) .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(grid) .AnchorCellMiddleCenter() .To3DXY(); foreach (FlatTriPoint point in grid) { SpriteCell 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.GetColor2() * 2]; cell.name = point.ToString(); cell.SetAngle(360 / FlatTriPoint.SpliceCount * point.I); grid[point] = cell; } }
public static bool __CompilerHint__FlatTri__TileCell() { var grid1 = new PointyHexGrid<TileCell[]>(1, 1); foreach(var point in grid1) { grid1[point] = new TileCell[1]; } var grid2 = new FlatTriGrid<TileCell>(1, 1); foreach(var point in grid2) { grid2[point] = null; } var shapeStorageInfo = new ShapeStorageInfo<FlatTriPoint>(new IntRect(), p => true); var shapeInfo = new FlatTriShapeInfo<TileCell>(shapeStorageInfo); return grid1[grid1.First()][0] == null || grid2[grid2.First()] == null || shapeInfo.IncIndex(0) != null; }
/** * Generates a maze using a randomized version of Prim's algorithm. * * @returns a IEnumerable of passages */ //For some reason, the generic version gives a TypeLoadException in Unity (but not when run from visual studio). /* * public static IEnumerable<TEdge> GenerateMazeWalls<TGrid, TPoint, TEdge>(TGrid grid) * where TEdge : IGridPoint<TEdge>, IEdge<TPoint> * where TPoint : IGridPoint<TPoint>, ISupportsEdges<TEdge> * where TGrid : ISupportsEdgeGrid<TEdge>, IGridSpace<TPoint> * { * IGrid<bool, TEdge> walls = grid.MakeEdgeGrid<bool>(); //true indicates passable * var wallList = new List<TEdge>(); * * TPoint newMaizePoint = grid.RandomItem<TPoint>(); * var inMaze = new List<TPoint>(); * inMaze.Add(newMaizePoint); * * var edges = newMaizePoint.GetEdges(); * wallList.AddRange(edges); * * while (wallList.Any()) * { * var randomWall = wallList.RandomItem(); * IEnumerable<TPoint> faces = (randomWall as IEdge<TPoint>).GetEdgeFaces().Where(x => grid.Contains(x)); * * //At least one of the two faces must be in the maze * if (faces.Any(point => !inMaze.Contains(point))) * { * newMaizePoint = faces.First(point => !inMaze.Contains(point)); * inMaze.Add(newMaizePoint); * walls[randomWall] = true; * * yield return randomWall; * * // Add all edges that are not passages * edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge])); * wallList.AddRange(edges); * } * else * { * wallList.Remove(randomWall); * } * } * yield return (TEdge)(object) g.First(); * yield break; * } */ /** * Generates a maze using a randomized version of Prim's algorithm. * * @returns a IEnumerable of passages */ public static IEnumerable <PointyRhombPoint> GenerateMazeWalls <TCell>(FlatTriGrid <TCell> grid) { var walls = grid.MakeEdgeGrid <bool>(); //true indicates passable var wallList = new PointList <PointyRhombPoint>(); var newMaizePoint = grid.RandomItem(); var inMaze = new PointList <FlatTriPoint> { newMaizePoint }; var edges = newMaizePoint.GetEdges(); wallList.AddRange(edges); while (wallList.Any()) { var randomWall = wallList.RandomItem(); var faces = (randomWall as IEdge <FlatTriPoint>).GetEdgeFaces().Where(x => grid.Contains(x)); //At least one of the two faces must be in the maze if (faces.Any(point => !inMaze.Contains(point))) { newMaizePoint = faces.First(point => !inMaze.Contains(point)); inMaze.Add(newMaizePoint); walls[randomWall] = true; yield return(randomWall); // Add all edges that are not passages edges = newMaizePoint.GetEdges().Where(edge => !(walls[edge])); wallList.AddRange(edges); } else { wallList.Remove(randomWall); } } }