void HandleSnapIntoGrid(Bubble processRelativeTo) { transform.parent = TileGrid.instance.transform; var colHit = processRelativeTo.colRaw; var rowHit = processRelativeTo.rowRaw; if (colHit < 0) { colHit = 0; } else if (colHit >= TileGrid.instance.grid.GetLength(0)) { colHit = TileGrid.instance.grid.GetLength(0) - 1; } if (rowHit < 0) { rowHit = 0; } else if (rowHit >= TileGrid.instance.grid.GetLength(1)) { rowHit = TileGrid.instance.grid.GetLength(1) - 1; } var radius = TileGrid.instance.tileSize / 2; if (TileGrid.instance.grid[colHit, rowHit] != null) { var hitBubble = TileGrid.instance.grid[colHit, rowHit]; //Debug.Log("Hit handling at x:" + hitBubble.colRaw + ", y: " + hitBubble.rowRaw); BubbleNeighbor neighborComparer = new BubbleNeighbor(); var listNeighborOffset = neighborComparer.GetWithoutDiagonals();//GetTileOffsetsBasedOnParity(rowHit % 2); //GetWithoutDiagonals();// var cast = Physics2D.RaycastAll(hitBubble.transform.position, (transform.position - hitBubble.transform.position), radius); Debug.DrawRay(hitBubble.transform.position, (transform.position - hitBubble.transform.position) * radius, Color.green, 2f); foreach (var found in cast) { if (found.collider.GetComponent <ThrownBubble>()) { //Debug.Log("found bubble at " + found.collider.name.ToString() + " , " + found.point); SetNearestPositionOnGrid(listNeighborOffset, hitBubble.transform, transform); break; } } } if (GameManagerActions.instance.CheckGameOver()) { return; } this.gameObject.SetActive(false); //TileGrid.instance.SetCurrentCluster(colHit, rowHit, true, false); }
public virtual IEnumerator SearchAnidado(BubbleType matchType, bool matchByType = true) { // me fijo si : // - el tipo es igual // - es un especial que no matchea por color // - ya procese este vecino if ((matchType.Equals(compoBubble.type) && matchByType) && !processed) { processed = true; TileGrid.instance.cluster.Add(this.compoBubble); BubbleNeighbor myNeighbors = new BubbleNeighbor(); foreach (var neighbor in myNeighbors.GetWithoutDiagonals()) //GetTileOffsetsBasedOnParity(compoBubble.rowRaw % 2)) { // lista de vectores de offset para agregar a la posicion de // composite bubble. // reviso estar en rango y que tenga sentido hacer la comparacion if (compoBubble.rowRaw - (int)neighbor.y >= 0 && compoBubble.rowRaw - (int)neighbor.y < TileGrid.instance.grid.GetLength(1)) { if (compoBubble.colRaw + (int)neighbor.x >= 0 && compoBubble.colRaw + (int)neighbor.x < TileGrid.instance.grid.GetLength(0)) { // estando en la grilla, reviso el tipo var target = TileGrid.instance.grid[compoBubble.colRaw + (int)neighbor.x, compoBubble.rowRaw - (int)neighbor.y]; // si es valido y es una burbuja, hago otro search anidado a sus vecinos if (target != null && target.gameObject.activeInHierarchy) { RaycastHit2D recheck = Physics2D.Raycast(transform.position, target.transform.position - transform.position); Debug.DrawRay(transform.position, target.transform.position - transform.position, Color.red, 2f); Debug.Log("Drawing ray recheck"); //yield return new WaitForSeconds(2f); if (recheck.collider != null && this.compoBubble != null) { if (matchType.Equals(this.compoBubble.type) && matchType.Equals(recheck.collider.GetComponent <Bubble>().type)) { yield return(StartCoroutine(target.GetComponent <PopBubble>().SearchAnidado(matchType, matchByType))); } } } } } } } else if (!matchByType && !processed) { switch (compoBubble.type.type) { /// todos estos casos deben estar definidos en la lista de burbujas /// especiales (guardada en BubbleResources). case "line": processed = true; for (int col = 0; col < TileGrid.instance.grid.GetLength(0); col++) { if (compoBubble.rowRaw >= 1 && compoBubble.rowRaw < TileGrid.instance.grid.GetLength(1)) { TileGrid.instance.cluster.Add(TileGrid.instance.grid[col, this.compoBubble.rowRaw]); TileGrid.instance.cluster.Add(TileGrid.instance.grid[col, compoBubble.rowRaw - 1]); Debug.Log("Doble fila deleteada"); } else if (compoBubble.rowRaw == 0) { TileGrid.instance.cluster.Add(TileGrid.instance.grid[col, this.compoBubble.rowRaw]); Debug.Log("Fila techo deleteada"); } } break; } } }