private Tile SelectNeighbour(RaycastHit hit) { var offset = hit.point.x - hit.transform.position.x; var offsetY = hit.point.y - hit.transform.position.y; HexDirection dir, dir2nd; if (offset < 0f) { if (offsetY < 0f) { dir = HexDirection.SE; dir2nd = HexDirection.SE; } else { dir = HexDirection.E; dir2nd = HexDirection.SE; } } else { if (offsetY < 0f) { dir = HexDirection.SW; dir2nd = HexDirection.SW; } else { dir = HexDirection.W; dir2nd = HexDirection.SW; } } //top if (hit.transform.CompareTag(FirstRowTag)) { return(grid.Nearest(hit.point)); } //bubble hit var bubble = hit.transform.GetComponentInParent <Bubble>(); var tileHit = grid.Get(bubble); var newTile = grid.Neighbour(tileHit, dir); if (grid.Get(newTile)) { newTile = grid.Neighbour(tileHit, dir2nd); } if (grid.Get(newTile)) { return(null); } return(newTile); }
bool IsAttached(Bubble bubble, HashSet <Bubble> alreadyChecked = null) { if (bubble == null) { return(false); } if (alreadyChecked == null) { alreadyChecked = new HashSet <Bubble>(); } alreadyChecked.Add(bubble); //check self var cubeIndex = grid.Get(bubble).Index; if (cubeIndex.y == 0) { // verified return(true); } //check others foreach (var direction in looseCheck) { var checkBubble = grid.Neighbour(bubble, direction); if (!alreadyChecked.Contains(checkBubble) && IsAttached(checkBubble, alreadyChecked)) { return(true); } } return(false); }
private void FillRow(int q, int r, Vector3 offset = default) { Tile tile = grid.TileAt(q, r); while (tile != null) { var bubble = spawner.CreateRandom(); bubble.Movement.Teleport(tile.transform.position + offset); grid.Attach(bubble, tile); tile = grid.Neighbour(tile, HexDirection.E); } }
private void FillRow(int q, int r, ref int exponent) { Tile tile = grid.TileAt(q, r); while (tile != null) { if (exponent >= values.Length) { return; } var value = values[exponent++]; if (value > 0) { var bubble = spawner.Create(new BubbleScore(value)); grid.Insert(bubble, tile); } tile = grid.Neighbour(tile, HexDirection.E); } }