public void Start() { bigDimensions = bigSize.GetRectPoint(); smallDimensions = smallSize.GetRectPoint(); Reset(); }
private void CreateBlast( RectPoint blastOrigin ) { foreach ( RectPoint point in grid.GetNeighborHood( blastOrigin, BLAST_RADIUS )) { if ( grid[point].Color != Color.black ) { GameObject blast = (GameObject)Instantiate ( blastPrefab ); blast.transform.parent = grid[point].transform; blast.transform.localPosition = Vector3.zero; blast.transform.localScale = Vector3.one * 100.0f; if ( map[ player.transform.localPosition ] == point ) { Destroy (player.gameObject); } List<GameObject> deadEnemies = new List<GameObject>(); foreach( GameObject enemy in enemies ) { if (map[ enemy.transform.localPosition ] == point) { deadEnemies.Add (enemy); } } foreach( GameObject enemy in deadEnemies) { enemies.Remove(enemy); Destroy(enemy.gameObject); } StartCoroutine( Blast(blast) ); } } }
//All tile points are relative to CurrentPosition public void AddTile(RectPoint tilePoint, SpriteCell tileObject) { tileObjects[tilePoint] = tileObject; }
/** * @version1_8 */ public InspectableVectorPoint(RectPoint point) { x = point.X; y = point.Y; }
private void SelectFirstPoint(RectPoint point) { cellSelectionState = 1; point0 = point; pathRoot.transform.DestroyChildren(); var bigPathPoint = grid.GetBigPoint(point); var smallPathPoint = grid.GetSmallPoint(point); var pathMarker = Instantiate(pathPrefab); pathMarker.name = ""; pathMarker.Color = Color.black; pathMarker.transform.parent = pathRoot.transform; pathMarker.transform.localScale = Vector3.one * 4; pathMarker.transform.localPosition = bigMap[bigPathPoint] + smallMap[smallPathPoint] - Vector3.forward; }
private Block MakeBlock(int id, BlockType type, RectPoint initialPosition) { var block = new Block(id); if (type == BlockType.Horizontal) { block.AddTile(RectPoint.Zero, MakeTile()); block.AddTile(RectPoint.East, MakeTile()); } else { block.AddTile(RectPoint.Zero, MakeTile()); block.AddTile(RectPoint.North, MakeTile()); } if (CanOccupy(block, initialPosition)) { foreach (SpriteCell tile in block.TileObjects) { tile.Color = colors[id]; tile.name = "" + id; } PlaceTile(block, initialPosition); block.UpdateTilePositions(map); } else { Debug.LogError("Invalid placement. Making block empty"); foreach (SpriteCell tile in block.TileObjects) { Destroy(tile.gameObject); } block.Clear(); } return block; }
private SpriteCell MakeCell(RectPoint point) { var cell = Instantiate(cellPrefab); cell.transform.parent = uiRoot.transform; cell.transform.localScale = Vector3.one; cell.transform.localPosition = map[point] + Vector3.forward; cell.Color = ExampleUtils.ColorFromInt(40, 40, 40); cell.HighlightOn = false; cell.name = ""; return cell; }
/** * This is a norm defined on the point, such that `p1.Difference(p2).Abs()` is equal to * `p1.DistanceFrom(p2)`. */ public RectPoint Translate(RectPoint translation) { return(new RectPoint(x + translation.X, y + translation.Y)); }
public bool Equals(RectPoint other) { bool areEqual = (x == other.X) && (y == other.Y); return(areEqual); }
/** * The lattice distance from this point to the other. */ public int DistanceFrom(RectPoint other) { return(Subtract(other).Magnitude()); }
private List <RectPoint> GetLinePoints(RectPoint p1, RectPoint p2) { List <RectPoint> linePath = new List <RectPoint>(); int x = p1.X; int y = p1.Y; int dx = p2.X - x; int dy = p2.Y - y; bool isVerticalFunction = Math.Abs(dx) < Math.Abs(dy); int move; int gradientMove; int biggerAxis; int smallerAxis; if (isVerticalFunction) { biggerAxis = Math.Abs(dy); smallerAxis = Math.Abs(dx); move = Math.Sign(dy); gradientMove = Math.Sign(dx); } // end if else { biggerAxis = Math.Abs(dx); smallerAxis = Math.Abs(dy); move = Math.Sign(dx); gradientMove = Math.Sign(dy); } // end else int totalGradient = biggerAxis / 2; for (int i = 0; i < biggerAxis; i++) { RectPoint point = new RectPoint(x, y); linePath.Add(point); if (isVerticalFunction) { y += move; } else { x += move; } totalGradient += smallerAxis; if (totalGradient >= biggerAxis) { if (isVerticalFunction) { x += gradientMove; } else { y += gradientMove; } totalGradient -= biggerAxis; } } // end for return(linePath); }
private List <RectPoint> GetConnectionTiles(RectPoint startTile, RectPoint endTile) { List <RectPoint> linearPath = GetLinePoints(startTile, endTile); return(GetCompletePathTiles(linearPath)); }
internal static Point GetPoint(this Rect rect, RectPoint rectPoint) { return(RectUtils.GetPoint(rect, rectPoint)); }
/** @version1_8 */ public InspectableVectorPoint(RectPoint point) { x = point.X; y = point.Y; }
private void BuildPuzzle() { const int size = 5; tileGrid = RectGrid<SpriteCell>.Rectangle(size, size); blocksGrid = (RectGrid<Block>) tileGrid.CloneStructure<Block>(); map = new RectMap(new Vector2(152, 152)) .AnchorCellMiddleCenter() .WithWindow(ExampleUtils.ScreenRect) .AlignMiddleCenter(tileGrid) .To3DXY(); foreach (RectPoint point in tileGrid) { var cell = MakeCell(point); tileGrid[point] = cell; blocksGrid[point] = null; } blocks = new List<Block>(); AddFirstBlock(); AddOtherBlocks(); winPosition = new RectPoint(4, 2); }
/** * Subtracts the other point from this point, and returns the result. */ public RectPoint Subtract(RectPoint other) { return(new RectPoint(x - other.X, y - other.Y)); }
private bool CanOccupy(Block block, RectPoint gridPoint) { foreach (RectPoint tilePoint in block.TilePoints) { var absoluteTilePoint = gridPoint + tilePoint; if (!tileGrid.Contains(absoluteTilePoint)) { return false; } if ((blocksGrid[absoluteTilePoint] != null) && (blocksGrid[absoluteTilePoint] != block)) { return false; } } return true; }
public RectPoint MoveBy(RectPoint translation) { return(Translate(translation)); }
private void PlaceTile(Block block, RectPoint gridPoint) { foreach (RectPoint tilePoint in block.TilePoints) { tileGrid[gridPoint + tilePoint].gameObject.SetActive(false); blocksGrid[gridPoint + tilePoint] = block; } block.CurrentPosition = gridPoint; }
public RectPoint MoveBackBy(RectPoint translation) { return(Translate(translation.Negate())); }
private void SelectLastPoint(RectPoint point) { cellSelectionState = 0; point1 = point; var path = Algorithms.AStar(grid, point0, point1, (p, q) => p.DistanceFrom(q), cell => !cell.HighlightOn, (p, q) => p.DistanceFrom(q)); foreach (var pathPoint in path.ButFirst()) { var bigPathPoint = grid.GetBigPoint(pathPoint); var smallPathPoint = grid.GetSmallPoint(pathPoint); var pathMarker = Instantiate(pathPrefab); pathMarker.name = (""); pathMarker.Color = Color.black; pathMarker.transform.parent = pathRoot.transform; pathMarker.transform.localScale = Vector3.one*4; pathMarker.transform.localPosition = bigMap[bigPathPoint] + smallMap[smallPathPoint] - Vector3.forward; } }
/** * @version1_7 */ public int Dot(RectPoint other) { return(x * other.X + y * other.Y); }
/** * @version1_7 */ public int PerpDot(RectPoint other) { return(x * other.Y - y * other.x); }
private HostAnchor(RectPoint position) { _position = position; }