public static void AddBombMixEffect(BombPair pair, string effect) { if (!data.ContainsKey(pair)) { data.Add(pair, effect); } }
public bool CompareTo(BombPair pair) { bool result = false; result = result || (pair.a == a && pair.b == b); result = result || (pair.a == b && pair.b == a); return(result); }
// Function of creation effect of mixing chips based on the pair public static void Mix(BombPair pair, SlotForChip slot) { if (!ContainsPair(pair)) return; BombMixEffect effect = ContentAssistant.main.GetItem<BombMixEffect> (data [pair]); effect.GetChip().can_move = false; effect.GetChip().gravity = false; slot.SetChip (effect.GetChip ()); }
// Function of creation effect of mixing chips based on the pair public static void Mix(BombPair pair, SlotForChip slot) { if (!ContainsPair(pair)) { return; } BombMixEffect effect = ContentAssistant.main.GetItem <BombMixEffect> (data [pair]); slot.SetChip(effect.GetChip()); }
IEnumerator SwapTwoItemRoutine(Chip a, Chip b) { if (swaping) { yield break; } if (!a || !b) { yield break; } if (!SessionAssistant.main.CanIAnimate()) { yield break; } switch (LevelProfile.main.target) { case FieldTarget.Jelly: case FieldTarget.Score: if (SessionAssistant.main.movesCount <= 0) { yield break; } break; case FieldTarget.Timer: if (SessionAssistant.main.timeLeft <= 0) { yield break; } break; } bool mix = false; if (BombMixEffect.ContainsPair(a.chipType, b.chipType)) { mix = true; } int move = 0; SessionAssistant.main.animate++; swaping = true; Vector3 posA = a.parentSlot.transform.position; Vector3 posB = b.parentSlot.transform.position; float progress = 0; while (progress < swapDuration) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration); if (!mix) { b.transform.position = Vector3.Lerp(posB, posA, progress / swapDuration); } progress += Time.deltaTime; yield return(0); } a.transform.position = posB; if (!mix) { b.transform.position = posA; } a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); if (mix) { swaping = false; BombPair pair = new BombPair(a.chipType, b.chipType); SlotForChip slot = b.parentSlot; a.HideChip(); b.HideChip(); BombMixEffect.Mix(pair, slot); SessionAssistant.main.movesCount--; SessionAssistant.main.animate--; yield break; } SlotForChip slotA = a.parentSlot; SlotForChip slotB = b.parentSlot; slotB.SetChip(a); slotA.SetChip(b); move++; int count = 0; SessionAssistant.Solution solution; solution = slotA.MatchAnaliz(); if (solution != null) { count += solution.count; } solution = slotB.MatchAnaliz(); if (solution != null) { count += solution.count; } if (count == 0 && !forceSwap) { AudioAssistant.Shot("SwapFailed"); while (progress > 0) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration); b.transform.position = Vector3.Lerp(posB, posA, progress / swapDuration); progress -= Time.deltaTime; yield return(0); } a.transform.position = posA; b.transform.position = posB; a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); slotB.SetChip(b); slotA.SetChip(a); move--; } else { AudioAssistant.Shot("SwapSuccess"); } SessionAssistant.main.movesCount -= move; SessionAssistant.main.MatchingCounter(); SessionAssistant.main.animate--; swaping = false; }
public static bool ContainsPair(BombPair pair) { return(data.ContainsKey(pair)); }
// Coroutine swapping 2 chips IEnumerator SwapTwoItemRoutine(Chip a, Chip b) { // cancellation terms if (swaping) { yield break; // If the process is already running } if (!a || !b) { yield break; // If one of the chips is missing } if (a.parentSlot.slot.GetBlock() || b.parentSlot.slot.GetBlock()) { yield break; // If one of the chips is blocked } if (!SessionAssistant.main.CanIAnimate()) { yield break; // If the core prohibits animation } switch (LevelProfile.main.limitation) { case Limitation.Moves: if (SessionAssistant.main.movesCount <= 0) { yield break; } break; // If not enough moves case Limitation.Time: if (SessionAssistant.main.timeLeft <= 0) { yield break; } break; // If not enough time } bool mix = false; // The effect of mixing or not if (BombMixEffect.ContainsPair(a.chipType, b.chipType)) // Checking the possibility of mixing { mix = true; } int move = 0; // Number of points movement which will be expend SessionAssistant.main.animate++; swaping = true; Vector3 posA = a.parentSlot.transform.position; Vector3 posB = b.parentSlot.transform.position; float progress = 0; Vector3 normal = a.parentSlot.slot.x == b.parentSlot.slot.x ? Vector3.right : Vector3.up; // Animation swapping 2 chips while (progress < swapDuration) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration) + normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; if (!mix) { b.transform.position = Vector3.Lerp(posB, posA, progress / swapDuration) - normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; } progress += Time.deltaTime; yield return(0); } a.transform.position = posB; if (!mix) { b.transform.position = posA; } a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); if (mix) // Scenario mix effect { swaping = false; BombPair pair = new BombPair(a.chipType, b.chipType); SlotForChip slot = b.parentSlot; a.HideChip(); b.HideChip(); BombMixEffect.Mix(pair, slot); SessionAssistant.main.movesCount--; SessionAssistant.main.animate--; yield break; } // Scenario the effect of swapping two chips SlotForChip slotA = a.parentSlot; SlotForChip slotB = b.parentSlot; slotB.SetChip(a); slotA.SetChip(b); move++; // searching for solutions of matching int count = 0; SessionAssistant.Solution solution; solution = slotA.MatchAnaliz(); if (solution != null) { count += solution.count; } solution = slotB.MatchAnaliz(); if (solution != null) { count += solution.count; } // Scenario canceling of changing places of chips if (count == 0 && !forceSwap) { AudioAssistant.Shot("SwapFailed"); while (progress > 0) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration) - normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; b.transform.position = Vector3.Lerp(posB, posA, progress / swapDuration) + normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; progress -= Time.deltaTime; yield return(0); } a.transform.position = posA; b.transform.position = posB; a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); slotB.SetChip(b); slotA.SetChip(a); move--; } else { AudioAssistant.Shot("SwapSuccess"); SessionAssistant.main.swapEvent++; } SessionAssistant.main.firstChipGeneration = false; SessionAssistant.main.movesCount -= move; SessionAssistant.main.EventCounter(); SessionAssistant.main.animate--; swaping = false; }
// Coroutine swapping 2 chips IEnumerator SwapTwoItemRoutine(Chip a, Chip b) { // cancellation terms if (swaping) yield break; // If the process is already running if (!a || !b) yield break; // If one of the chips is missing if (a.parentSlot.slot.GetBlock() || b.parentSlot.slot.GetBlock()) yield break; // If one of the chips is blocked if (!SessionAssistant.main.CanIAnimate()) yield break; // If the core prohibits animation switch (LevelProfile.main.limitation) { case Limitation.Moves: if (SessionAssistant.main.movesCount <= 0) yield break; break; // If not enough moves case Limitation.Time: if (SessionAssistant.main.timeLeft <= 0) yield break; break; // If not enough time } bool mix = false; // The effect of mixing or not if (BombMixEffect.ContainsPair (a.chipType, b.chipType)) // Checking the possibility of mixing mix = true; int move = 0; // Number of points movement which will be expend SessionAssistant.main.animate++; swaping = true; Vector3 posA = a.parentSlot.transform.position; Vector3 posB = b.parentSlot.transform.position; float progress = 0; Vector3 normal = a.parentSlot.slot.x == b.parentSlot.slot.x ? Vector3.right : Vector3.up; // Animation swapping 2 chips while (progress < swapDuration) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration) + normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; if (!mix) b.transform.position = Vector3.Lerp(posB, posA, progress/swapDuration) - normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; progress += Time.deltaTime; yield return 0; } a.transform.position = posB; if (!mix) b.transform.position = posA; a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); if (mix) { // Scenario mix effect swaping = false; BombPair pair = new BombPair(a.chipType, b.chipType); SlotForChip slot = b.parentSlot; a.HideChip(); b.HideChip(); BombMixEffect.Mix(pair, slot); SessionAssistant.main.movesCount--; SessionAssistant.main.animate--; yield break; } // Scenario the effect of swapping two chips SlotForChip slotA = a.parentSlot; SlotForChip slotB = b.parentSlot; slotB.SetChip(a); slotA.SetChip(b); move++; // searching for solutions of matching int count = 0; SessionAssistant.Solution solution; solution = slotA.MatchAnaliz(); if (solution != null) count += solution.count; solution = slotB.MatchAnaliz(); if (solution != null) count += solution.count; // Scenario canceling of changing places of chips if (count == 0 && !forceSwap) { AudioAssistant.Shot("SwapFailed"); while (progress > 0) { a.transform.position = Vector3.Lerp(posA, posB, progress / swapDuration) - normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; b.transform.position = Vector3.Lerp(posB, posA, progress / swapDuration) + normal * Mathf.Sin(3.14f * progress / swapDuration) * 0.2f; progress -= Time.deltaTime; yield return 0; } a.transform.position = posA; b.transform.position = posB; a.movementID = SessionAssistant.main.GetMovementID(); b.movementID = SessionAssistant.main.GetMovementID(); slotB.SetChip(b); slotA.SetChip(a); move--; } else { AudioAssistant.Shot("SwapSuccess"); SessionAssistant.main.swapEvent ++; } SessionAssistant.main.firstChipGeneration = false; SessionAssistant.main.movesCount -= move; SessionAssistant.main.EventCounter (); SessionAssistant.main.animate--; swaping = false; }
public bool CompareTo(BombPair pair) { bool result = false; result = result || (pair.a == a && pair.b == b); result = result || (pair.a == b && pair.b == a); return result; }
public static bool ContainsPair(BombPair pair) { return data.ContainsKey (pair); }
// Generation impassable walls IEnumerator GenerateWalls() { int x; int y; Slot near; Slot current; for (x = 0; x < field.width-1; x++) for (y = 0; y < field.height; y++) { field.wallsV[x,y] = LevelProfile.main.GetWallV(x,height-y-1); if (field.wallsV[x,y] && field.slots[x,y]) { current = Slot.GetSlot(x, y); if (current) { current.SetWall(Side.Right); near = current[Side.Right]; if (near) near.SetWall(Side.Left); } } } for (x = 0; x < field.width; x++) for (y = 0; y < field.height-1; y++) { field.wallsH[x,y] = LevelProfile.main.GetWallH(x, height-y-2); if (field.wallsH[x,y] && field.slots[x,y]) { current = Slot.GetSlot(x, y); if (current) { current.SetWall(Side.Top); near = current[Side.Top]; if (near) near.SetWall(Side.Bottom); } } } List<BombPair> walls = new List<BombPair>(); BombPair pair; Vector3 position; GameObject wall; foreach (Slot slot in Slot.all.Values) { yield return 0; foreach (Side side in Utils.straightSides) { if (slot[side] != null) continue; pair = new BombPair(slot.key, (slot.x + Utils.SideOffsetX(side)) + "_" + (slot.y + Utils.SideOffsetY(side))); if (walls.Contains(pair)) continue; position = new Vector3(); position.x = Utils.SideOffsetX(side) * 0.353f; position.y = Utils.SideOffsetY(side) * 0.353f; wall = ContentAssistant.main.GetItem("Wall", position); wall.transform.parent = slot.transform; wall.transform.localPosition = position; wall.name = "Wall_" + side; if (Utils.SideOffsetY(side) != 0) wall.transform.Rotate(0, 0, 90); walls.Add(pair); } } }