IEnumerator ColorMixRoutine(Chip secondary) { chip.busy = true; chip.gravity = false; chip.destroyable = false; SimpleChip[] allChips = FindObjectsOfType <SimpleChip>(); List <SimpleChip>[] sorted = new List <SimpleChip> [Chip.colors.Length]; int[] count = new int[Chip.colors.Length]; foreach (SimpleChip c in allChips) { if (c.chip.destroying) { continue; } if (!c.chip.slot) { continue; } if (c.chip == secondary) { continue; } count[c.chip.id]++; if (sorted[c.chip.id] == null) { sorted[c.chip.id] = new List <SimpleChip>(); } sorted[c.chip.id].Add(c); } List <Slot> targets = new List <Slot>(); int i; for (i = 0; i < Chip.colors.Length; i++) { if (sorted[i] != null && sorted[i].Count > 0) { targets.Add(sorted[i].GetRandom().chip.slot); } } yield return(new WaitForSeconds(0.1f)); AudioAssistant.Shot("ColorBombCrush"); chip.Play("Destroying"); foreach (Slot target in targets) { Chip pu = FieldAssistant.main.AddPowerup(target.coord, secondary.chipType); target.chip = pu; Lightning.CreateLightning(3, transform, pu.transform, Chip.colors[chip.id]); yield return(new WaitForSeconds(0.1f)); } yield return(new WaitForSeconds(0.2f)); if (chip.slot.jam) { chip.jamType = chip.slot.jam.type; } SessionAssistant.main.EventCounter(); if (secondary.chipType != "UltraColorBomb") { for (i = 0; i < targets.Count; i++) { if (targets[i].chip) { targets[i].chip.jamType = chip.jamType; targets[i].chip.DestroyChip(); } yield return(new WaitForSeconds(0.05f)); } } chip.busy = false; chip.gravity = true; FieldAssistant.main.JellyCrush(chip.slot.coord); while (chip.IsPlaying("Destroying")) { yield return(0); } chip.ParentRemove(); chip.HideChip(false); }
// Coroutine destruction / activation public IEnumerator Destroying() { if (birth == SessionAssistant.main.eventCount) { chip.destroying = false; yield break; } chip.busy = true; chip.Play("Destroying"); AudioAssistant.Shot("ColorBombCrush"); Slot s; if (chip.slot) { FieldAssistant.main.JellyCrush(chip.slot.coord); } chip.gravity = false; int2 key = new int2(); for (key.x = 0; key.x < LevelProfile.main.width; key.x++) { for (key.y = 0; key.y < LevelProfile.main.height; key.y++) { if (key == chip.slot.coord) { continue; } s = Slot.GetSlot(key); if (s && s.chip && s.chip.id == chip.id) { Lightning.CreateLightning(3, transform, s.chip.transform, color); yield return(new WaitForSeconds(0.03f)); } } } yield return(new WaitForSeconds(0.1f)); for (key.x = 0; key.x < LevelProfile.main.width; key.x++) { for (key.y = 0; key.y < LevelProfile.main.height; key.y++) { if (key == chip.slot.coord) { continue; } s = Slot.GetSlot(key); if (s && s.chip && s.chip.id == chip.id) { s.chip.SetScore(0.3f); FieldAssistant.main.BlockCrush(key, true); FieldAssistant.main.JellyCrush(key); s.chip.jamType = chip.jamType; s.chip.DestroyChip(); yield return(new WaitForSeconds(0.02f)); } } } yield return(new WaitForSeconds(0.1f)); chip.busy = false; chip.gravity = true; while (chip.IsPlaying("Destroying")) { yield return(0); } chip.ParentRemove(); Destroy(gameObject); }
IEnumerator LightningBranch(string powerup = "") { yield return(new WaitForSeconds(0.1f)); Slot currentSlot = chip.slot; Chip nextChip; Slot nextSlot; Lightning lightning = null; int iter = 10; int count = 10; List <Chip> branch = new List <Chip>(); while (true) { if (iter <= 0 || count <= 0) { break; } nextSlot = currentSlot.nearSlot.Values.Where(x => x != null).ToList().GetRandom(); if (!nextSlot) { iter--; continue; } nextChip = nextSlot.chip; if (!nextChip || nextChip.destroying) { iter--; continue; } if (!currentSlot.chip) { iter--; continue; } if (chips.Contains(nextChip) || branch.Contains(nextChip)) { iter--; continue; } chips.Add(nextChip); branch.Add(nextChip); int id = nextChip.id; if (lightning != null) { lightning.Remove(); } lightning = Lightning.CreateLightning(0, currentSlot.chip.transform, nextChip.transform, id == Mathf.Clamp(id, 0, 5) ? Chip.colors[id] : Color.white); count--; currentSlot.chip.SetScore(0.3f); currentSlot.chip.jamType = chip.jamType; currentSlot.chip.DestroyChip(); currentSlot = nextSlot; yield return(new WaitForSeconds(0.02f)); } if (powerup != "") { bool dontDestroy = powerup == "RainbowHeart" || powerup == "UltraColorBomb"; Chip pu = FieldAssistant.main.AddPowerup(currentSlot.coord, powerup); //if (!dontDestroy) // pu.can_move = false; pu.transform.localPosition = Vector3.zero; yield return(0); while (!dontDestroy && pu != null && pu.GetComponent <Animation>().isPlaying) { yield return(0); } if (pu != null && !dontDestroy) { SessionAssistant.main.EventCounter(); pu.jamType = chip.jamType; pu.DestroyChip(); } } if (lightning != null) { lightning.Remove(); if (currentSlot.chip) { currentSlot.chip.jamType = chip.jamType; currentSlot.chip.DestroyChip(); } } branchCount--; while (branchCount > 0) { yield return(0); } yield return(0); branchCount = -1; //yield return new WaitForSeconds(0.02f); //for (int i = 0; i < branch.Count; i++) { // yield return new WaitForSeconds(0.03f); // if (branch[i].destroing || !branch[i].parentSlot) // continue; // branch[i].SetScore(0.1f); // FieldAssistant.main.BlockCrush(branch[i].parentSlot.slot.x, branch[i].parentSlot.slot.y, true); // FieldAssistant.main.JellyCrush(branch[i].parentSlot.slot.x, branch[i].parentSlot.slot.y); // if (branch[i] != chip) // branch[i].DestroyChip(); //} //branchCount--; //while (branchCount > 0) // yield return 0; //branchCount = -1; }
IEnumerator TeleportChipRoutine(Chip chip, Slot target) { if (!chip.parentSlot) { yield break; } TrailRenderer trail = chip.gameObject.GetComponentInChildren <TrailRenderer> (); float trailTime = 0; if (trail) { trailTime = trail.time; trail.time = 0; } float defScale = chip.transform.localScale.x; float scale = defScale; // chip.animation.Play("Minimizing"); // // while (chip.animation.isPlaying) { // yield return 0; // } while (scale > 0f) { scale -= Time.deltaTime * 10f; chip.transform.localScale = Vector3.one * scale; yield return(0); } if (!target.GetChip() && chip && chip.parentSlot) { Transform a = chip.parentSlot.transform; Transform b = target.transform; Color color; if (chip.id == Mathf.Clamp(chip.id, 0, 5)) { color = Chip.colors[chip.id]; } else { color = Color.white; } Lightning l = Lightning.CreateLightning(5, a, b, color); target.SetChip(chip); chip.transform.position = chip.parentSlot.transform.position; yield return(0); l.end = null; } yield return(0); if (trail) { trail.time = trailTime; } scale = 0.2f; while (scale < defScale) { scale += Time.deltaTime * 10f; chip.transform.localScale = Vector3.one * scale; yield return(0); } chip.transform.localScale = Vector3.one * defScale; }
IEnumerator MixEffect() { yield return(0); Chip chip = GetChip(); while (chip.parentSlot == null) { yield return(0); } transform.position = chip.parentSlot.transform.position; while (!SessionAssistant.main.CanIWait()) { yield return(0); } SessionAssistant.main.matching++; AudioAssistant.Shot("ColorBombCrush"); int sx = chip.parentSlot.slot.x; int sy = chip.parentSlot.slot.y; SimpleChip[] allChips = GameObject.FindObjectsOfType <SimpleChip> (); List <SimpleChip>[] sorted = new List <SimpleChip> [6]; int[] count = new int[6]; foreach (SimpleChip c in allChips) { if (c.chip.destroing) { continue; } count[c.chip.id]++; if (sorted[c.chip.id] == null) { sorted[c.chip.id] = new List <SimpleChip>(); } sorted[c.chip.id].Add(c); } List <Chip> target = new List <Chip>(); int i; for (i = 0; i < 6; i++) { if (sorted[i] != null && sorted[i].Count > 0) { target.Add(sorted[i][Random.Range(0, sorted[i].Count)].chip); } } int x; int y; for (i = 0; i < target.Count; i++) { x = target[i].parentSlot.slot.x; y = target[i].parentSlot.slot.y; target[i] = FieldAssistant.main.AddPowerup(x, y, targetBomb); Lightning.CreateLightning(3, transform, target[i].transform, Chip.colors[i]); yield return(new WaitForSeconds(0.1f)); } yield return(new WaitForSeconds(0.3f)); SessionAssistant.main.eventCount++; for (i = 0; i < target.Count; i++) { if (target[i]) { target[i].DestroyChip(); } yield return(new WaitForSeconds(0.2f)); } yield return(new WaitForSeconds(0.4f)); SessionAssistant.main.matching--; FieldAssistant.main.BlockCrush(sx, sy, false); FieldAssistant.main.JellyCrush(sx, sy); destroingLock = false; DestroyChipFunction(); }
// Coroutine destruction / activation IEnumerator DestroyChipFunction() { if (birth == SessionAssistant.main.eventCount) { chip.destroing = false; yield break; } matching = true; GetComponent <Animation>().Play("ColorBump"); AudioAssistant.Shot("ColorBombCrush"); int width = FieldAssistant.main.field.width; int height = FieldAssistant.main.field.height; int sx = chip.parentSlot.slot.x; int sy = chip.parentSlot.slot.y; Slot s; FieldAssistant.main.JellyCrush(sx, sy); chip.ParentRemove(); for (int x = 0; x < width; x++) { for (int y = 0; y < height; y++) { if (y == sy && x == sx) { continue; } s = FieldAssistant.main.GetSlot(x, y); if (s && s.GetChip() && s.GetChip().id == chip.id) { Lightning.CreateLightning(3, transform, s.GetChip().transform, color); } } } yield return(new WaitForSeconds(0.3f)); for (int x1 = 0; x1 < width; x1++) { for (int y1 = 0; y1 < height; y1++) { if (y1 == sy && x1 == sx) { continue; } s = FieldAssistant.main.GetSlot(x1, y1); if (s && s.GetChip() && s.GetChip().id == chip.id) { s.GetChip().SetScore(1); FieldAssistant.main.BlockCrush(x1, y1, true); FieldAssistant.main.JellyCrush(x1, y1); s.GetChip().DestroyChip(); } } } yield return(new WaitForSeconds(0.1f)); matching = false; while (GetComponent <Animation>().isPlaying) { yield return(0); } Destroy(gameObject); }
IEnumerator UltraColorMixRoutine(Chip secondary) { chip.busy = true; chip.destroyable = false; chip.Play("Hit"); AudioAssistant.Shot("ColorBombCrush"); FieldAssistant.main.JellyCrush(chip.slot.coord); if (chip.slot.jam) { chip.jamType = chip.slot.jam.type; } List <Chip> target = new List <Chip>(); foreach (Slot slot in Slot.all.Values) { if (slot == chip.slot) { continue; } if (slot.chip == null || slot.chip == secondary) { continue; } if (secondary.chipType == "UltraColorBomb" || slot.chip.id == secondary.id) { yield return(new WaitForSeconds(0.02f)); if (slot.chip) { if (secondary.chipType != "SimpleChip" && secondary.chipType != "UltraColorBomb") { FieldAssistant.main.AddPowerup(slot.coord, secondary.chipType); } Lightning.CreateLightning(3, transform, slot.chip.transform, slot.chip.IsColored() ? Chip.colors[slot.chip.id] : Color.white); target.Add(slot.chip); } } } yield return(new WaitForSeconds(0.1f)); SessionAssistant.main.EventCounter(); foreach (Chip t in target) { if (t.destroying) { continue; } t.SetScore(0.3f); FieldAssistant.main.BlockCrush(t.slot.coord, true); FieldAssistant.main.JellyCrush(t.slot.coord); t.jamType = chip.jamType; t.DestroyChip(); yield return(new WaitForSeconds(0.02f)); } yield return(new WaitForSeconds(0.1f)); FieldAssistant.main.JellyCrush(chip.slot.coord); while (chip.IsPlaying("Hit")) { yield return(0); } chip.Play("Destroying"); while (chip.IsPlaying("Destroying")) { yield return(0); } chip.busy = false; chip.ParentRemove(); Destroy(gameObject); }