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); }
private void Awake() { instance = this; Debug.Log("Generando mapa..."); GenerateGrid(); neighborOffsetArray = new BubbleNeighbor(); onRemoveCluster = new UnityEvent <int, int, int>(); onResetProcessed = new UnityEvent(); cluster = new List <Bubble>(); floatingclusters = new List <Bubble>(); }
/// <summary> /// Clusters que pueden caer en un impacto y explosion /// </summary> /// <returns></returns> public IEnumerator ProcessFloatingClusters(int highestRowProcessed) { Debug.Log("Processing floating clusters...." + " max idx = " + highestRowProcessed); List <Bubble> foundFloatingClusters = new List <Bubble>(); List <Bubble> toProcessFloating = new List <Bubble>(); bool isFloating = false; // busco desde la ultima posicion que se que explotaron burbujas, // todas las que estan en esa fila, y las que estan por debajo. for (int row = highestRowProcessed; row < instance.grid.GetLength(1); row++) { for (int column = 0; column < instance.grid.GetLength(0); column++) { var tile = instance.grid[column, row]; if (tile == null || !tile.gameObject.activeInHierarchy) { isFloating = true; continue; } else { toProcessFloating.Add(tile); } //instance.grid[column, row].GetComponent<SpriteRenderer>().color = Color.black; //dbg } } yield return(null); // cuando tengo esa lista armada, voy a recorrer buscando sus vecinos que esten en // posicion de vecino [ 0, 1, 2, 3, 4 ] // ( en sentido contrario de las agujas del reloj, pos. derecha a izquierda lateral ) BubbleNeighbor neighborObject = new BubbleNeighbor(); var listedNeighbors = neighborObject.GetUpperNeighbors(); foreach (var possibleFloater in toProcessFloating) { if (possibleFloater.rowRaw < highestRowProcessed) { continue; } for (int i = 0; i < listedNeighbors.Length; i++) { var targetNeighborCol = possibleFloater.colRaw + (int)listedNeighbors[i].x; var targetNeighborRow = possibleFloater.rowRaw + (int)listedNeighbors[i].y; if (targetNeighborCol < 0) { targetNeighborCol = 0; } else if (targetNeighborCol >= TileGrid.instance.grid.GetLength(0)) { targetNeighborCol = TileGrid.instance.grid.GetLength(0) - 1; } if (targetNeighborRow < 0) { targetNeighborRow = 0; } else if (targetNeighborRow >= TileGrid.instance.grid.GetLength(1)) { targetNeighborRow = TileGrid.instance.grid.GetLength(1) - 1; } isFloating &= (instance.grid[targetNeighborCol, targetNeighborRow] == null || !instance.grid[targetNeighborCol, targetNeighborRow].gameObject.activeInHierarchy || instance.grid[targetNeighborCol, targetNeighborRow].floating); Debug.Log("floating = " + isFloating); if (instance.grid[targetNeighborCol, targetNeighborRow]) { instance.grid[targetNeighborCol, targetNeighborRow].floating = isFloating; foundFloatingClusters.Add(instance.grid[targetNeighborCol, targetNeighborRow]); } } } foreach (var floating in foundFloatingClusters) { if (floating.gameObject == null || !floating.gameObject.activeInHierarchy) { continue; } Debug.Log("Popping " + floating.name); floating.GetComponent <SpriteRenderer>().color = Color.white; Debug.Log("foundFloatingClusters " + floating.gameObject.name); yield return(floating.GetComponent <PopBubble>().StartCoroutine(floating.GetComponent <PopBubble>().StartNeighborScan(new BubbleType(), 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; } } }