public override void RaiseEventTileSwitchAnimBegan(Match3Tile neighborTile) { base.RaiseEventTileSwitchAnimBegan(neighborTile); lastNeighborTile = neighborTile as NormalTile; movedByInput = true; }
public override bool TryToMoveTile(AbstractTile srcTile, AbstractTile dstTile) { if (srcTile == dstTile || srcTile == null || dstTile == null) { return(false); } if (CanMoveTile(srcTile, dstTile.BoardPiece)) { Match3Tile srcMatch3Tile = srcTile as Match3Tile; Match3Tile dstMatch3Tile = dstTile as Match3Tile; if (OnUserStartedTilesSwitch != null) { OnUserStartedTilesSwitch(srcMatch3Tile, dstMatch3Tile); } srcMatch3Tile.RaiseEventTileTappedFirst(); srcMatch3Tile.IsTileSwitching = true; dstMatch3Tile.IsTileSwitching = true; BoardAnimations.SwitchTilesAnim(true, srcMatch3Tile, dstMatch3Tile); return(true); } return(false); }
protected TileColorType GetMatchingColorBetweenDirections(Match3BoardPiece startPiece, Match3BoardPiece.LinkType dirA, Match3BoardPiece.LinkType dirB) { Match3BoardPiece pieceDirA = startPiece.GetNeighbor(dirA); Match3BoardPiece pieceDirB = null; if (dirA != dirB) { pieceDirB = startPiece.GetNeighbor(dirB); } else if (pieceDirA != null) { pieceDirB = pieceDirA.GetNeighbor(dirA); } if (pieceDirA != null && pieceDirB != null) { Match3Tile tileDirA = pieceDirA.Tile as Match3Tile; Match3Tile tileDirB = pieceDirB.Tile as Match3Tile; if (tileDirA != null && tileDirB != null && tileDirA.CanBeMatched && tileDirB.CanBeMatched && tileDirA.IsMatchWith(tileDirB)) { return(tileDirA.TileColor); } } return(TileColorType.None); }
IEnumerator DestroyColoredTiles() { // float offsetSize = Mathf.Abs(Board[0, 0].LocalPosition.x - Board[0, 1].LocalPosition.x) / 2f; if (OnTriggerColorBombTile != null) { OnTriggerColorBombTile(this); } if (destroyColor == TileColorType.None) { destroyColor = RuleEntry.genericColors[Random.Range(0, Match3BoardRenderer.maxNumBoardColors)]; } for (int i = 0; i < Board.NumRows; i++) { for (int j = 0; j < Board.NumColumns; j++) { Match3Tile tile = Board[i, j].Tile as Match3Tile; // if (tile != null && !(tile is DropTile) && tile.TileColor == destroyColor) if (IsValidTarget(tile, destroyColor)) { tilesToDestroy.Add(tile); if (iceTrailEffect != null) { Transform effectInstance = (Instantiate(iceTrailEffect) as GameObject).transform; effectInstance.position = WorldPosition; // + new Vector3(0f, 0f, -5f); effectInstance.parent = cachedTransform.parent; effectInstance.LookAt(tile.cachedTransform); tile.IsUserMoveable = false; StartCoroutine(MoveTargetTo(effectInstance, tile.cachedTransform, tilesDestroyEffect.destroyTileTime)); // HOTween.To(effectInstance, tilesDestroyEffect.destroyTileTime, "localPosition", Board[i, j].LocalPosition); Destroy(effectInstance.gameObject, tilesDestroyEffect.lifeTime * 1.5f); } } } } yield return(new WaitForSeconds(tilesDestroyEffect.destroyTileTime)); for (int i = 0; i < tilesToDestroy.Count; i++) { if (tilesToDestroy[i]) { tilesToDestroy[i].IsMatched = true; tilesToDestroy[i].Destroy(); } } if (tilesDestroyEffect.destroyTileTime < animation["effect_winterchill_idle"].length) { yield return(new WaitForSeconds(animation["effect_winterchill_idle"].length - tilesDestroyEffect.destroyTileTime)); } base.TileDestroy(false); Match3BoardGameLogic.Instance.TryCheckStableBoard(); }
public void ExecuteInitialSpawnRule() { if (initialTileSpawnRule != null) { List <RuleEntry> tempRuleEntryList; List <TileSpawnRule> immediateSpawnList = Match3BoardGameLogic.Instance.immediateSpawnList; //Check immediateSpawnList for available rules that can be applied, with respect to the eligibleSpawnList. for (int i = 0; i < immediateSpawnList.Count; i++) { if (eligibleSpawnList != null && eligibleSpawnList.Count > 0) { tempRuleEntryList = immediateSpawnList[i].CompareRuleEntries(eligibleSpawnList); immediateSpawnList.RemoveAt(i); } else { tempRuleEntryList = immediateSpawnList[i].ruleEntries; } if (tempRuleEntryList != null) { initialTileSpawnRule.ruleEntries = tempRuleEntryList; break; } } // Execute the initial spawn rule only if we have at least one RuleEntry. if (initialTileSpawnRule.ruleEntries.Count > 0) { Match3Tile newTile = initialTileSpawnRule.SpawnNewTile(true); Match3BoardRenderer.Instance.AttachTileToBoardAt(this, newTile, false, true); } } }
public Match3Tile SpawnTileAt(int rowIdx, int columnIdx, bool offBoardTile = false, bool noLockedTiles = false, bool isBoardSetup = false) { int rand; if (noLockedTiles) { //TODO: temporary spawn hack to spawn only new normal tiles on the board. rand = Random.Range(0, 6); //a normal tile } else { rand = Random.Range(0, 100); // current chance for locked tile is 6/100 = 6% if (rand < 6) { rand += 6; //a locked tile } else { rand = Random.Range(0, 6); //a normal tile } } Match3Tile newTilePrefab = tilesPrefabs[rand].GetComponent <Match3Tile>(); return(SpawnSpecificTileAt(rowIdx, columnIdx, newTilePrefab.GetType(), newTilePrefab.TileColor, offBoardTile, isBoardSetup)); }
public override void RaiseEventTileSwitchAnimBegan(Match3Tile neighborTile) { base.RaiseEventTileSwitchAnimBegan(neighborTile); if (neighborTile is BombTile) { BombTile neighborBomb = neighborTile as BombTile; // Mark this tile and it's neighbor as moving and without any gravity because there will be a custom animation on them // to try and keep things consistent. neighborBomb.DisableTileLogic(); DisableTileLogic(); // Prepare the bigger directional destroy effect on this directional tile. prefabTilesDestroyEffect = prefabBombCombineDestroyEffect; } if (neighborTile is DirectionalDestroyTile) { DirectionalDestroyTile directionalTile = neighborTile as DirectionalDestroyTile; directionalTile.SwitchBackOnMatchFail = false; SwitchBackOnMatchFail = false; CanBeMatched = false; (neighborTile as NormalTile).CanBeMatched = false; } }
void OnTilesDestroyed(Match3Tile tile) { if (!updatingValues) { StartCoroutine(UpdateValues()); } }
public Match3Tile SpawnTileAt(Match3BoardPiece boardPiece, BoardCoord boardPos, GameObject tilePrefab) { // Destroy previous tile from board piece (if present). if (boardPiece.EditorTile != null) { // Remove the first spawn rule entry for this tile if it corresponds to its type. SetBoardPieceSpawnRuleForTile(boardPiece, boardPiece.EditorTile, true); GameObject.DestroyImmediate(boardPiece.EditorTile.gameObject); } GameObject newTileGO = PrefabUtility.InstantiatePrefab(tilePrefab) as GameObject; PrefabUtility.DisconnectPrefabInstance(newTileGO); Match3Tile newTile = newTileGO.GetComponent <Match3Tile>(); newTile.name = string.Format("[{0},{1}] {2}", boardPos.row, boardPos.col, newTile.name); newTile.transform.parent = boardRenderer.transform; newTile.transform.localPosition = boardPiece.transform.localPosition - boardRenderer.transform.forward * 2f; boardPiece.EditorTile = newTile; // Add the first spawn rule entry for with this tile's type. SetBoardPieceSpawnRuleForTile(boardPiece, boardPiece.EditorTile); return(newTile); }
protected override void TileDestroy(bool useEffect) { spawnResult = CheckForSpawnPatterns(); cachedTransform.localPosition += Vector3.forward * -2f; if (spawnTimeBomb && !spawnResult) { spawnedTimeBomb = SpawnTimeBomb(); } if (useDestroyEffect && useEffect) { // Check if this bomb is a bomb resulted from a Bomb+Bomb combination if (prefabDestroyEffect == prefabDoubleDestroyEffect) { if (OnBombBombCombine != null) { OnBombBombCombine(this); } } TileBombDestroyEffect bombDestroyEffect = SpawnDestroyEffect(new Vector3(0f, 0f, -19f)).gameObject.GetComponent<TileBombDestroyEffect>(); bombDestroyEffect.explosionSpreadTime = animation.clip.length - bombDestroyEffect.delayAfterExplosionSpread; bombDestroyEffect.InitBombDestroyEffect(this, WorldPosition); bombDestroyEffect.triggerListener.OnTileEntered = OnTileEnteredDestroyTrigger; bombDestroyEffect.triggerListener.OnBoardPieceEntered = OnBoardPieceEnteredFreezeTrigger; bombDestroyEffect.OnEffectFinished = OnBombDestroyEffectFinished; //TODO:Remove redundant chunks of code if u will ever have the time / decency to do so //TODO: MIO: Revise this .. it was way too late when you wrote this. Transform effectInstance = (Instantiate(PrefabEffectBreakFragments) as GameObject).transform; effectInstance.position = WorldPosition; Destroy(effectInstance.gameObject, destroyEffect.lifeTime); effectBreakFragmentsInstance = effectInstance.GetComponent<TileDestroyEffect>(); if (freezeEffect) { Destroy(freezeEffect); effectBreakFragmentsInstance.GetComponent<TileDestroyEffect>().UpdateMaterial(PrefabFreezeDestroyMaterialArray[(int)TileColor - 1]); } else { effectBreakFragmentsInstance.GetComponent<TileDestroyEffect>().UpdateMaterial(TileColor); } tileModelRenderer.enabled = false; //-------------------------------------------------------------------------------------- animation.Play(); if(tileModelAdditionalRenderer != null) { tileModelAdditionalRenderer.transform.parent.animation.Play("tile_iceberg_destroy"); } if (OnTriggerBombTileFreeze != null) { OnTriggerBombTileFreeze(this); } } else { base.TileDestroy(false); } }
public static void OnDrawGizmos(Match3Tile tile, GizmoType gizmoType) { if (!tile.canDrawGizmos || !tilesDebugDisplayOverride) { return; } string tileStates = ""; if (tile.IsMoving) { tileStates = AppendState(tileStates, "M, ", maxStatesLength); } if (tile.IsDestroying) { tileStates = AppendState(tileStates, "D, ", maxStatesLength); } if (tile.debugPassiveGravity) { tileStates = AppendState(tileStates, "Pg, ", maxStatesLength); } if (tile.debugActiveGravity) { tileStates = AppendState(tileStates, "Ag, ", maxStatesLength); } if (tile.BoardPiece != null && !tile.HasReachedBoardPieceArea()) { tileStates = AppendState(tileStates, "Bd, ", maxStatesLength); } tileStates = tileStates.Trim(); if (labelStyle == null) { labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.yellow; labelStyle.fontSize = 14; labelStyle.normal.background = MakeTex(2, 2, Color.black); } Handles.Label(tile.transform.position + new Vector3(-tile.collider.bounds.extents.x, tile.collider.bounds.extents.y, 0f), tileStates, labelStyle); Matrix4x4 pushedMatrix = Gizmos.matrix; if (tile.transform.parent != null) { Gizmos.matrix = tile.transform.parent.localToWorldMatrix; } Gizmos.color = Color.green; Gizmos.DrawWireSphere(tile.fallDestination, 0.25f); if (tile.transform.parent != null) { Gizmos.matrix = pushedMatrix; } }
public void InitBombDestroyEffect(Match3Tile owner, Vector3 destroyTriggerPos) { effectOwner = owner; // Setup destroy trigger destroyTrigger.position = destroyTriggerPos; triggerListener = destroyTrigger.gameObject.GetComponent<TilesTriggerListener>(); StartCoroutine(StartTriggerScale(explosionSpreadTime)); }
protected void OnAnyTileDestroyedEvent(Match3Tile tile) { if(tile.GetType() == typeof(NormalTile)) { tileColorCount[(int)tile.TileColor]--; tileTotalCount--; colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount); } }
protected void OnAnyTileDestroyedEvent(Match3Tile tile) { if (tile.GetType() == typeof(NormalTile)) { tileColorCount[(int)tile.TileColor]--; tileTotalCount--; colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount); } }
public override void RaiseEventSwitchSuccess(Match3Tile neighborTile) { base.RaiseEventSwitchSuccess(neighborTile); //If this boardpiece is a dropperBehaviour if (BoardPiece.GetComponent <DropperBehaviour>() != null && !isDropping) { StartCoroutine(Drop()); } }
public void InitBombDestroyEffect(Match3Tile owner, Vector3 destroyTriggerPos) { effectOwner = owner; // Setup destroy trigger destroyTrigger.position = destroyTriggerPos; triggerListener = destroyTrigger.gameObject.GetComponent <TilesTriggerListener>(); StartCoroutine(StartTriggerScale(explosionSpreadTime)); }
protected void OnTileAttachedToBoardEvent(Match3Tile tile) { // Debug.LogError("[Spawner]++"); if (tile.GetType() == typeof(NormalTile)) { tileTotalCount++; tileColorCount[(int)tile.TileColor]++; colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount); } }
protected void OnTileAttachedToBoardEvent(Match3Tile tile) { // Debug.LogError("[Spawner]++"); if(tile.GetType() == typeof(NormalTile)) { tileTotalCount++; tileColorCount[(int)tile.TileColor]++; colorProbability[genericColorsIndexes[(int)tile.TileColor]] = 1f - (tileTotalCount == 0 ? 0f : tileColorCount[(int)tile.TileColor] / tileTotalCount); } }
// public override void RaiseBoardFinishedSetupEvent () // { // base.RaiseBoardFinishedSetupEvent(); // // BoardTilesInitializer initializer = new BoardTilesInitializer(Board); // initializer.Initialize(); // } /// <summary> /// Setup the board tiles prefabs specified in the <see cref="tilesPrefabs"/> array, /// based on their type and color for quick access at run-time. /// </summary> public override void SetupBoardTiles() { tilesDictionary = new TilesDictionary(); for (int i = 0; i < tilesPrefabs.Length; i++) { Match3Tile tile = tilesPrefabs[i].GetComponent <Match3Tile>(); tilesDictionary[tile.GetType(), tile.TileColor] = tile; } }
public override void RaiseEventSwitchSuccess (Match3Tile neighborTile) { base.RaiseEventSwitchSuccess (neighborTile); //If this boardpiece is a dropperBehaviour if (BoardPiece.GetComponent<DropperBehaviour>() != null && !isDropping) { StartCoroutine(Drop ()); } }
protected void OnTileDestroyed(Match3Tile tile) { foreach (DestroyTilesPair pair in destroyTiles) { if (pair.type.GetType().IsInstanceOfType(tile) && tile.TileColor == pair.type.TileColor) { pair.current++; } } CheckWin(); }
public override void InitComponent () { base.InitComponent (); match3BoardRenderer = BoardRenderer as Match3BoardRenderer; numEffectsFinished = 0; winterchilOriginTile = this; tilesToDestroy.Clear(); winterchillEffects.Clear(); additionalChildAnimationComponent.Play(childIdleAnimationName); }
public void OnTilesSwitchAnimFinished(AbstractBoardAnimations sender, AbstractTile srcTile, AbstractTile dstTile) { // Debug.Log("Switch anim finished!"); // Update the board positions of the animated tiles (update the board logic after the animation finishes). boardData.SwitchTiles(srcTile, dstTile); Match3Tile srcMatch3Tile = srcTile as Match3Tile; Match3Tile dstMatch3Tile = dstTile as Match3Tile; bool foundMatches = matchesFinder.FindMatches(); if ((!foundMatches || (!srcMatch3Tile.IsMatched && !dstMatch3Tile.IsMatched)) && (srcMatch3Tile.SwitchBackOnMatchFail && dstMatch3Tile.SwitchBackOnMatchFail)) { if (OnUserTilesSwitchBad != null) { OnUserTilesSwitchBad(srcMatch3Tile, dstMatch3Tile); } srcMatch3Tile.IsTileSwitching = true; dstMatch3Tile.IsTileSwitching = true; BoardAnimations.SwitchTilesAnim(false, srcMatch3Tile, dstMatch3Tile, (_sender, _srcTile, _dstTile) => { boardData.SwitchTiles(_srcTile, _dstTile); _srcTile.IsTileSwitching = false; _dstTile.IsTileSwitching = false; } ); srcMatch3Tile.RaiseEventSwitchBackOnFail(dstMatch3Tile); dstMatch3Tile.RaiseEventSwitchBackOnFail(srcMatch3Tile); } else if (srcMatch3Tile.IsMatched || dstMatch3Tile.IsMatched) { srcMatch3Tile.IsTileSwitching = false; dstMatch3Tile.IsTileSwitching = false; loseConditions.NewMove(); srcMatch3Tile.RaiseEventSwitchSuccess(dstMatch3Tile); dstMatch3Tile.RaiseEventSwitchSuccess(srcMatch3Tile); } else if (!srcMatch3Tile.SwitchBackOnMatchFail || !dstMatch3Tile.SwitchBackOnMatchFail) { // Reset the "IsTileSwitching" property for tiles that don't switch back on match fail because they finished their switch animation. srcMatch3Tile.IsTileSwitching = false; dstMatch3Tile.IsTileSwitching = false; } DestroyLastFoundMatches(); }
/// <summary> /// Finds the first possible match. This is the main method from this class that needs to be called. /// </summary> /// <returns> /// The first possible match. /// </returns> public bool FindFirstPossibleMatch() { numFoundPossibleMatches = 0; lastFoundIsolatedTile = null; foundPossibleMatch[0] = foundPossibleMatch[1] = foundPossibleMatch[2] = null; foundPossibleMatchColor = TileColorType.None; ClearPartialMatchesBuffers(); // Start searching for the first possible match Board.ApplyCancellableActionToAll(FindMatchingBoardPiecesAround); // Check if we previously found a possible match and store the result separatelly. if (foundPossibleMatchColor != TileColorType.None) { List <Match3Tile> foundPossibleMatchList = partialTileMatchesLists[(int)foundPossibleMatchColor]; // if (debugEnabled) { // Debug.Log(Time.frameCount + " normal possible match found: "); // } for (int i = 0; i < 3; i++) { foundPossibleMatch[i] = foundPossibleMatchList[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = 3; return(true); } else if (triggerTileMatchFound.Count >= 2) { // if (debugEnabled) { // Debug.Log(Time.frameCount + " trigger tiles possible match found: "); // } for (int i = 0; i < triggerTileMatchFound.Count; i++) { foundPossibleMatch[i] = triggerTileMatchFound[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = triggerTileMatchFound.Count; return(true); } return(false); }
public override void InitComponent() { base.InitComponent(); match3BoardRenderer = BoardRenderer as Match3BoardRenderer; numEffectsFinished = 0; winterchilOriginTile = this; tilesToDestroy.Clear(); winterchillEffects.Clear(); additionalChildAnimationComponent.Play(childIdleAnimationName); }
/// <summary> /// Finds the first possible match. This is the main method from this class that needs to be called. /// </summary> /// <returns> /// The first possible match. /// </returns> public bool FindFirstPossibleMatch() { numFoundPossibleMatches = 0; lastFoundIsolatedTile = null; foundPossibleMatch[0] = foundPossibleMatch[1] = foundPossibleMatch[2] = null; foundPossibleMatchColor = TileColorType.None; ClearPartialMatchesBuffers(); // Start searching for the first possible match Board.ApplyCancellableActionToAll(FindMatchingBoardPiecesAround); // Check if we previously found a possible match and store the result separatelly. if (foundPossibleMatchColor != TileColorType.None) { List<Match3Tile> foundPossibleMatchList = partialTileMatchesLists[(int)foundPossibleMatchColor]; // if (debugEnabled) { // Debug.Log(Time.frameCount + " normal possible match found: "); // } for(int i = 0; i < 3; i++) { foundPossibleMatch[i] = foundPossibleMatchList[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = 3; return true; } else if (triggerTileMatchFound.Count >= 2) { // if (debugEnabled) { // Debug.Log(Time.frameCount + " trigger tiles possible match found: "); // } for(int i = 0; i < triggerTileMatchFound.Count; i++) { foundPossibleMatch[i] = triggerTileMatchFound[i]; // if (debugEnabled) { // Debug.Log("Match tile: " + i + ": " + foundPossibleMatch[i]); // } } numFoundPossibleMatches = triggerTileMatchFound.Count; return true; } return false; }
public Match3Tile SpawnSpecificTile(System.Type tileType, TileColorType prefabDefaultColor, bool isBoardSetup = false) { Match3Tile newTile = (Instantiate(tilesDictionary[tileType, prefabDefaultColor].gameObject) as GameObject).GetComponent <Match3Tile>(); newTile.cachedTransform.parent = cachedTransform; newTile.BoardRenderer = this; if (!isBoardSetup) { newTile.InitComponent(); } return(newTile); }
public Match3BoardPiece AttachTileToBoardAt(int rowIdx, int columnIdx, Match3Tile tile, bool offBoardTile, bool isBoardSetup = false, bool resetTilePosition = true) { // Assign the tile to the specified BoardPiece. Match3BoardPiece targetBoardPiece = Board[rowIdx, columnIdx] as Match3BoardPiece; if (isBoardSetup) { targetBoardPiece.TileRef = tile; } else { targetBoardPiece.Tile = tile; // if (targetBoardPiece.BottomLink != null && targetBoardPiece.BottomLink.Tile != null && targetBoardPiece.BottomLink.Tile.IsMoving) { // Match3Tile nextTile = targetBoardPiece.BottomLink.Tile as Match3Tile; // newTile.moveVel = Mathf.Clamp(nextTile.moveVel - newTile.initialVel, -newTile.initialVel, newTile.maxVel); // } } if (resetTilePosition) { targetBoardPiece.ResetTilePosition(); } // if (offBoardTile) // { // Match3BoardPiece bottomLinkPiece = targetBoardPiece.BottomLink; // Vector3 tileLocalPos = newTile.LocalPosition; // // if (bottomLinkPiece != null && bottomLinkPiece.Tile != null && bottomLinkPiece.LocalPosition.y < bottomLinkPiece.Tile.LocalPosition.y) // { // tileLocalPos.y = bottomLinkPiece.Tile.LocalPosition.y + verticalTileDistance + verticalTileOffset; // } // else { // tileLocalPos.y = targetBoardPiece.LocalPosition.y + verticalTileDistance + verticalTileOffset; // } // // newTile.LocalPosition = tileLocalPos; // //// Debug.LogWarning("Spawning offboard tile at : " + tileLocalPos); // //Debug.Break(); // } if (!isBoardSetup && !offBoardTile) { tile.InitAfterAttachedToBoard(); } return(targetBoardPiece); }
public Match3Tile SpawnSpecificTileAt(int rowIdx, int columnIdx, System.Type tileType, TileColorType prefabDefaultColor, bool offBoardTile = false, bool isBoardSetup = false) { // Debug.LogWarning("[SpawnSpecificTileAt] " + tileType.ToString() + " " + prefabDefaultColor); // Spawn the specified tile Match3Tile newTile = SpawnSpecificTile(tileType, prefabDefaultColor, isBoardSetup); newTile.name = string.Format("[{0},{1}] {2}", rowIdx, columnIdx, newTile.name); // Assign the tile to the specified BoardPiece. AttachTileToBoardAt(rowIdx, columnIdx, newTile, offBoardTile, isBoardSetup); return(newTile); }
public override void OnInspectorGUI() { Match3Tile e = (Match3Tile)target; serializedObject.Update(); DrawSpritePreview(normalSprite, tile.normalSprite); DrawSpritePreview(hoverSprite, tile.hoverSprite); e.traits = (TraitsOfTile)EditorGUILayout.EnumFlagsField(e.traits); EditorGUILayout.PropertyField(color); // EditorGUILayout.PropertyField(flags); EditorGUILayout.PropertyField(colliderType); serializedObject.ApplyModifiedProperties(); }
public Match3Tile this[System.Type tileType, TileColorType tileColor] { get { return tilesDictionary[tileType][(int)tileColor]; } set { Match3Tile[] tiles; if (tilesDictionary.TryGetValue(tileType, out tiles) == false) { tiles = new Match3Tile[(int)TileColorType.Count]; } tiles[(int)tileColor] = value; tilesDictionary[tileType] = tiles; } }
public void GetPositionsOfRocks(MapDimentions mapDimentions, Tilemap tilemap) { for (int i = 0; i < mapDimentions.width; i++) { for (int j = 0; j < mapDimentions.height; j++) { Vector3Int pos = new Vector3Int(i, j, 0); Match3Tile m3 = tilemap.GetTile <Match3Tile>(pos); if (m3 && m3.traits.IsRock()) { this.SetPositionOfRock(pos); } } } }
public override void RaiseEventTileSwitchAnimEnded(AbstractTile neighborTile) { // Check if this directional tile was combined with a BombTile. // isCombineWithBombEffect flag check was added to remove some unwanted behaviors where (2x bomb/directional effects would spawn) // TODO: Investigate further into why this is happening. if (neighborTile is BombTile && !isCombineWithBombEffect) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); StartCoroutine(StartCombineWithBombEffect(neighborTile as BombTile)); } // Setup directional with directional tile combine effect. if (neighborTile is DirectionalDestroyTile && TappedFirst) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); IsDestroying = true; neighborTile.IsDestroying = true; Match3Tile crossTile = match3BoardRenderer.SpawnSpecificTileAt(BoardPiece.BoardPosition.row, BoardPiece.BoardPosition.col, typeof(CrossDestroyTile), TileColorType.None ); crossTile.TileColor = TileColor; crossTile.DisableTileLogic(); (crossTile as DirectionalDestroyTile).UpdateMaterial(); if (neighborTile.BoardPiece.Tile == neighborTile) { neighborTile.BoardPiece.Tile = null; } Destroy(neighborTile.gameObject); Destroy(gameObject); } if (neighborTile is ColorBombTile && TappedFirst) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); } // In the base classes "movedByInput" and "tappedFirst" flags are reset so we call the base at the end of the overriden code. base.RaiseEventTileSwitchAnimEnded(neighborTile); }
protected void SpawnNewTileInQueue(TileSpawnRule spawnRule) { Match3Tile newTile = spawnRule.SpawnNewTile(); newTile.LocalPosition = spawnPoint; // Deactivate and hide the tile until the spawn queue is processed. newTile.gameObject.SetActive(false); spawnQueue.Enqueue(newTile); if (!isSpawnQueueUpdating) { StartCoroutine(ProcessSpawnQueue()); } }
public Match3Tile this[System.Type tileType, TileColorType tileColor] { get { return(tilesDictionary[tileType][(int)tileColor]); } set { Match3Tile[] tiles; if (tilesDictionary.TryGetValue(tileType, out tiles) == false) { tiles = new Match3Tile[(int)TileColorType.Count]; } tiles[(int)tileColor] = value; tilesDictionary[tileType] = tiles; } }
public static void OnDrawGizmos(Match3Tile tile, GizmoType gizmoType) { if ( !tile.canDrawGizmos || !tilesDebugDisplayOverride) { return; } string tileStates = ""; if (tile.IsMoving) { tileStates = AppendState(tileStates, "M, ", maxStatesLength); } if (tile.IsDestroying) { tileStates = AppendState(tileStates, "D, ", maxStatesLength); } if (tile.debugPassiveGravity) { tileStates = AppendState(tileStates, "Pg, ", maxStatesLength); } if (tile.debugActiveGravity) { tileStates = AppendState(tileStates, "Ag, ", maxStatesLength); } if (tile.BoardPiece != null && !tile.HasReachedBoardPieceArea()) { tileStates = AppendState(tileStates, "Bd, ", maxStatesLength); } tileStates = tileStates.Trim(); if (labelStyle == null) { labelStyle = new GUIStyle(); labelStyle.normal.textColor = Color.yellow; labelStyle.fontSize = 14; labelStyle.normal.background = MakeTex(2, 2, Color.black); } Handles.Label(tile.transform.position + new Vector3(-tile.collider.bounds.extents.x, tile.collider.bounds.extents.y, 0f), tileStates, labelStyle); Matrix4x4 pushedMatrix = Gizmos.matrix; if (tile.transform.parent != null) { Gizmos.matrix = tile.transform.parent.localToWorldMatrix; } Gizmos.color = Color.green; Gizmos.DrawWireSphere(tile.fallDestination, 0.25f); if (tile.transform.parent != null) { Gizmos.matrix = pushedMatrix; } }
void OnTileDestroyed(Match3Tile tile) { timeNextLook = Random.Range(timeBetweenPowerLooks.x, timeBetweenPowerLooks.y); timeNextWave = Random.Range(timeBetweenWaves.x, timeBetweenWaves.y); if ((tile is ColorBombTile) && timeNextHappyBig <= 0) { if (NewSystem) { HappyFaceBig(); } else { HappyFace(); } } else if (((tile is BombTile) || (tile is DirectionalDestroyTile)) && timeNextHappy <= 0f) { HappyFace(); } }
protected void SelectAndDestroyTiles() { ActuallyUsingItem(); List <Match3BoardPiece> allBoardPiecesWithTiles = new List <Match3BoardPiece>(); List <LayeredBoardPiece> frostedBoardPieces = new List <LayeredBoardPiece>(); boardLogic.boardData.ApplyActionToAll((boardPiece) => { Match3Tile tile = boardPiece.Tile as Match3Tile; if (tile != null && !tile.IsMoving && tile.IsDestructible && !tile.IsDestroying && !(tile as NormalTile).IsFrozen()) { allBoardPiecesWithTiles.Add(boardPiece as Match3BoardPiece); } LayeredBoardPiece frostPiece = (boardPiece as LayeredBoardPiece); if (frostPiece != null && frostPiece.NumLayers > 0) { frostedBoardPieces.Add(frostPiece); } }); while (targetBoardPieces.Count < destroyTiles) { int index; if (frostedBoardPieces.Count > 0) { index = Random.Range(0, frostedBoardPieces.Count); targetBoardPieces.Add(frostedBoardPieces[index]); frostedBoardPieces.RemoveAt(index); } else if (allBoardPiecesWithTiles.Count > 0) { index = Random.Range(0, allBoardPiecesWithTiles.Count); targetBoardPieces.Add(allBoardPiecesWithTiles[index]); allBoardPiecesWithTiles.RemoveAt(index); } else { break; // REALLY? THERE AREN'T 3 TILES ON THE BOARD? WHAT HAS THE WORLD COME TO?!?! CURSE YOU CANDY CRUSH SAGA!!! } } StartCoroutine(DestroyStuff()); }
public override void RaiseEventTileSwitchAnimBegan(Match3Tile _neighborTile) { base.RaiseEventTileSwitchAnimBegan(_neighborTile); //One of the few cases were the color bomb swipe is invalid and a switchback is required if (!lastNeighborTile.IsDestructible) { SwitchBackOnMatchFail = true; return; } destroyColor = lastNeighborTile.TileColor; // Disable colliders for this tile and it's neighbor tile if the neighbor is a ColorBomb tile. // Because these will do a combine effect and they shouldn't be picked up by other destroy sensors in the meantime. if (lastNeighborTile is ColorBombTile) { DisableTileLogic(); lastNeighborTile.DisableTileLogic(); } // Cached the "TappedFirst" property here for this tile because it will be reset in "RaiseEventTileSwitchAnimEnded" event. wasFirstTapped = TappedFirst; if (lastNeighborTile is DirectionalDestroyTile) { lastNeighborTile.CanBeMatched = false; } if (lastNeighborTile is BombTile) { lastNeighborTile.CanBeMatched = false; } if (_neighborTile.GetType() == typeof(NormalTile) /* && wasFirstTapped*/) { (_neighborTile as NormalTile).CanBeMatched = false; if (!wasFirstTapped) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); } } }
protected void CheckMatch(Match3Tile currentTile, ref Match3Tile targetTile, bool isVerticalPass) { // Debug.Log("Current tile: " + currentTile + "\n" + "targetTile: " + targetTile); if (targetTile == null || !targetTile.CanBeMatched) { // If there is no target tile to check matches with yet, try to set the currentTile as the targetTile and // get back to the loop so we can move to the next tile to compare it with the new targetTile. if (currentTile != null && currentTile.CanBeMatched) { targetTile = currentTile; if (matchesBatch.Count > 0) { matchesBatch.Clear(); } matchesBatch.Add(targetTile); } } else if (currentTile != null && currentTile.IsMatchWith(targetTile)) { // If we found a matching tile with the targetTile add it to our temporary matches buffer. matchesBatch.Add(currentTile); } else { // If we found a tile different from the targetTile then we finished collecting tiles for the current batch and // we must check if we found at least 3 to add to our final "lastFoundMatches" result. // We also make the current tile the new targetTile because it belongs in a different batch of matches. targetTile = currentTile; if (matchesBatch.Count >= 3) { CollectNewFoundMatches(matchesBatch, isVerticalPass); } // Clear the current temporary matches buffer. matchesBatch.Clear(); // We check here if the new target tile can be matched then we already add it to the new batch of matches. if (targetTile != null && targetTile.CanBeMatched) { matchesBatch.Add(currentTile); } } }
public void SwitchTilesAnim(bool canRaiseGlobalSwitchEvent, Match3Tile src, Match3Tile dst, System.Action<Match3BoardAnimations, Match3Tile, Match3Tile> onAnimFinished = null) { // Debug.Log("[" + this.GetType().Name + "] SwitchTilesAnim " + src.name + " -> " + dst.name); src.IsMoving = true; dst.IsMoving = true; src.GravityEnabled = false; dst.GravityEnabled = false; //TODO: use a Tweener object pool and a TweenParams object pool for performance reasons Tweener srcToDstAnim = HOTween.To(src.cachedTransform, tileSwitchAnimDelay, new TweenParms().Prop("localPosition", dst.BoardPiece.LocalPosition) .Ease(EaseType.EaseInSine) ); Tweener dstToSrcAnim = HOTween.To(dst.cachedTransform, tileSwitchAnimDelay, new TweenParms().Prop("localPosition", src.BoardPiece.LocalPosition) .Ease(EaseType.EaseInSine) ); dstToSrcAnim.ApplyCallback(CallbackType.OnComplete, () => { // Call a single registered custom method when the tile switch animation finishes. (without registering it for future callbacks) if (onAnimFinished != null) { onAnimFinished(this, src, dst); } // Notify any registered methods of this event. RaiseEventTilesSwitchAnimFinished(canRaiseGlobalSwitchEvent, this, src, dst); src.RaiseEventTileSwitchAnimEnded(dst); dst.RaiseEventTileSwitchAnimEnded(src); }); src.RaiseEventTileSwitchAnimBegan(dst); dst.RaiseEventTileSwitchAnimBegan(src); // srcToDstAnim.Play(); // dstToSrcAnim.Play(); }
public void OnNewBoardPieceSelected(AbstractBoardPiece boardPiece, CustomInput.TouchInfo touchInfo) { if(BoardShuffleController.Instance.IsBoardReshuffling) { return; } bool selectionSucces = false; selectedBoardPiece = boardPiece; tileToDestroy = boardPiece.Tile as Match3Tile; effectPosition = boardPiece.cachedTransform; //Decide wether this selection is icepick worthy or not if(boardPiece.Tile == null) { if(boardPiece is LayeredBoardPiece && (boardPiece as LayeredBoardPiece).NumLayers > 0 ) { selectionSucces = true; } } else if (!tileToDestroy.IsMoving && tileToDestroy.IsDestructible && !tileToDestroy.IsDestroying && !(tileToDestroy as NormalTile).IsFrozen()) { selectionSucces = true; } if(selectionSucces) { SoundManager.Instance.PlayOneShot("icepick_sfx"); touchController.StopInputController(); touchController.OnNewBoardPieceSelected -= OnNewBoardPieceSelected; StartItemEffects(); } }
protected void CheckMatch(Match3Tile currentTile, ref Match3Tile targetTile, bool isVerticalPass) { // Debug.Log("Current tile: " + currentTile + "\n" + "targetTile: " + targetTile); if ( targetTile == null || !targetTile.CanBeMatched ) { // If there is no target tile to check matches with yet, try to set the currentTile as the targetTile and // get back to the loop so we can move to the next tile to compare it with the new targetTile. if (currentTile != null && currentTile.CanBeMatched) { targetTile = currentTile; if (matchesBatch.Count > 0) { matchesBatch.Clear(); } matchesBatch.Add(targetTile); } } else if (currentTile != null && currentTile.IsMatchWith(targetTile)) { // If we found a matching tile with the targetTile add it to our temporary matches buffer. matchesBatch.Add(currentTile); } else { // If we found a tile different from the targetTile then we finished collecting tiles for the current batch and // we must check if we found at least 3 to add to our final "lastFoundMatches" result. // We also make the current tile the new targetTile because it belongs in a different batch of matches. targetTile = currentTile; if (matchesBatch.Count >= 3) { CollectNewFoundMatches(matchesBatch, isVerticalPass); } // Clear the current temporary matches buffer. matchesBatch.Clear(); // We check here if the new target tile can be matched then we already add it to the new batch of matches. if (targetTile != null && targetTile.CanBeMatched) { matchesBatch.Add(currentTile); } } }
public Match3BoardPiece AttachTileToBoardAt(int rowIdx, int columnIdx, Match3Tile tile, bool offBoardTile, bool isBoardSetup = false, bool resetTilePosition = true) { // Assign the tile to the specified BoardPiece. Match3BoardPiece targetBoardPiece = Board[rowIdx, columnIdx] as Match3BoardPiece; if (isBoardSetup) { targetBoardPiece.TileRef = tile; } else { targetBoardPiece.Tile = tile; // if (targetBoardPiece.BottomLink != null && targetBoardPiece.BottomLink.Tile != null && targetBoardPiece.BottomLink.Tile.IsMoving) { // Match3Tile nextTile = targetBoardPiece.BottomLink.Tile as Match3Tile; // newTile.moveVel = Mathf.Clamp(nextTile.moveVel - newTile.initialVel, -newTile.initialVel, newTile.maxVel); // } } if (resetTilePosition) { targetBoardPiece.ResetTilePosition(); } // if (offBoardTile) // { // Match3BoardPiece bottomLinkPiece = targetBoardPiece.BottomLink; // Vector3 tileLocalPos = newTile.LocalPosition; // // if (bottomLinkPiece != null && bottomLinkPiece.Tile != null && bottomLinkPiece.LocalPosition.y < bottomLinkPiece.Tile.LocalPosition.y) // { // tileLocalPos.y = bottomLinkPiece.Tile.LocalPosition.y + verticalTileDistance + verticalTileOffset; // } // else { // tileLocalPos.y = targetBoardPiece.LocalPosition.y + verticalTileDistance + verticalTileOffset; // } // // newTile.LocalPosition = tileLocalPos; // //// Debug.LogWarning("Spawning offboard tile at : " + tileLocalPos); // //Debug.Break(); // } if ( !isBoardSetup && !offBoardTile ) { tile.InitAfterAttachedToBoard(); } return targetBoardPiece; }
public override void RaiseEventTileSwitchAnimBegan (Match3Tile neighborTile) { base.RaiseEventTileSwitchAnimBegan(neighborTile); if (neighborTile is BombTile) { BombTile neighborBomb = neighborTile as BombTile; // Mark this tile and it's neighbor as moving and without any gravity because there will be a custom animation on them // to try and keep things consistent. neighborBomb.DisableTileLogic(); DisableTileLogic(); // Prepare the bigger directional destroy effect on this directional tile. prefabTilesDestroyEffect = prefabBombCombineDestroyEffect; } if (neighborTile is DirectionalDestroyTile) { DirectionalDestroyTile directionalTile = neighborTile as DirectionalDestroyTile; directionalTile.SwitchBackOnMatchFail = false; SwitchBackOnMatchFail = false; CanBeMatched = false; (neighborTile as NormalTile).CanBeMatched = false; } }
/// <summary> /// Raises the tile switch animation begin event when this tile starts the switch animation with another neighbour tile. /// This event should be raised by the <see cref="Match3BoardGameLogic"/>. /// </summary> /// <param name='neighborTile'> /// Neighbour tile with which this tile does the switch. /// </param> public virtual void RaiseEventTileSwitchAnimBegan(Match3Tile neighborTile) { }
protected IEnumerator ProcessSpawnQueue() { Match3Tile nextTile = null; Vector3 tileLocalPos = Vector3.zero; isSpawnQueueUpdating = true; while(spawnQueue.Count > 0) { nextTile = spawnQueue.Peek(); if (boardPiece.Tile == null) { if (lastSpawnedTile == null || lastSpawnedTile.LocalPosition.y <= boardPiece.LocalPosition.y) { if (lastSpawnedTile != null && lastSpawnedTile.LocalPosition.y >= (boardPiece.LocalPosition.y - Match3BoardRenderer.halfVertTileDistance)) { nextTile.gameObject.SetActive(true); nextTile.moveVel = Mathf.Clamp(lastSpawnedTile.moveVel - nextTile.initialVel, 0f, nextTile.maxVel); tileLocalPos = nextTile.LocalPosition; tileLocalPos.y = lastSpawnedTile.LocalPosition.y + Match3BoardRenderer.vertTileDistance; nextTile.LocalPosition = tileLocalPos; } else { nextTile.gameObject.SetActive(true); nextTile.LocalPosition = spawnPoint; } Match3BoardRenderer.Instance.AttachTileToBoardAt(boardPiece, nextTile, false, false, false); lastSpawnedTile = spawnQueue.Dequeue(); } } yield return null; } isSpawnQueueUpdating = false; }
public virtual void RaiseEventSwitchBackOnFail(Match3Tile neighborTile) { }
protected IEnumerator StartCombineWithBombEffect(BombTile neighborBombTile) { Match3Tile nextToEffectOriginTile; // TileColorType movedTileColor; IsDestroying = true; neighborBombTile.IsDestroying = true; if (OnDirectionalBombCombine != null) { OnDirectionalBombCombine(this); } isCombineWithBombEffect = true; if ( !TappedFirst ) { // Do the combo destroy effect from the other tiles world position because that one was moved by input. winterchilOriginTile = neighborBombTile; nextToEffectOriginTile = this; } else { nextToEffectOriginTile = neighborBombTile; } // Spawn the combined tile effect (an enlarging cross directional tile that builds up and the destroys itself) CrossBombCombineVisualEffect combinedTileEffect = (Instantiate(prefabBombCombinedTileEffect) as GameObject).GetComponent<CrossBombCombineVisualEffect>(); combinedTileEffect.InitComponent(); // Bring this giant tile in the front combinedTileEffect.cachedTransform.position = winterchilOriginTile.WorldPosition - Vector3.forward * 0.5f; // Set the delay between the horizontal and vertical direction destroy effect. delayBetweenCrossDirections = combinedTileEffect.horizontalAnimTime; HOTween.To(nextToEffectOriginTile.cachedTransform, 0.2f, new TweenParms() .Prop("localPosition", winterchilOriginTile.LocalPosition) .Prop("localScale", Vector3.zero)); bombCombineEffectColumn = winterchilOriginTile.BoardPiece.BoardPosition.col; yield return new WaitForSeconds(0.2f); neighborBombTile.gameObject.SetActive(false); // Disable the default visual effect for this directional tile because we're doing a special combine effect. useDestroyEffect = false; StartCoroutine(DelayedTileRelease(0.1f)); // Destroy the cross tile effect after a delay. GameObject.Destroy(combinedTileEffect.gameObject, combinedTileEffect.totalAnimTime); SetVerticalColumnsLock(bombCombineEffectColumn, true); canDestroyBaseTileAfterWinterchill = false; direction = Direction.Horizontal; StartDirectionalDestroy(() => { canDestroyBaseTileAfterWinterchill = true; direction = Direction.Vertical; StartDirectionalDestroy(); if(neighborBombTile.BoardPiece) { neighborBombTile.BoardPiece.Tile = null; } GameObject.Destroy(neighborBombTile.gameObject, 0.2f); }); }
public virtual void RaiseEventSwitchSuccess(Match3Tile neighborTile) { }
public bool TryPossibleMatchMove() { // Knowing the isolated tile, determine the target coord where the isolated tile needs to be moved to make the match. Match3Tile[] lastFoundMatch = possibleMatchFinder.foundPossibleMatch; Match3Tile[] otherMatchTiles = new Match3Tile[2]; int j = 0; // Determine the other 2 tiles (non-isolated) in the "otherMatchTile" array. for(int i = 0; i < possibleMatchFinder.numFoundPossibleMatches; i++) { if (lastFoundMatch[i] != possibleMatchFinder.lastFoundIsolatedTile) { //TODO: for some reason an instance becomes null here, but in the same frame inside the possible matches finder it's not null. //That's why i've put this safety check here. if (lastFoundMatch[i] == null) { return false; } otherMatchTiles[j++] = lastFoundMatch[i]; } } // Determine the board coord where the isolated tile must move to match. BoardCoord isolatedTargetPos = possibleMatchFinder.lastFoundIsolatedTile.BoardPiece.BoardPosition; // Debug.Log(Time.frameCount + " otherMatchTiles[0] = " + otherMatchTiles[0]); // Debug.Log(Time.frameCount + " otherMatchTiles[1] = " + otherMatchTiles[1]); // Debug.Log(Time.frameCount + " lastFoundIsolatedTile = " + possibleMatchFinder.lastFoundIsolatedTile); BoardCoord otherTilesOffset; if (j == 1) { // When 2 special trigger tiles are found as a possible match, there is only 1 other tile besides the "isolated" tile in that match. otherTilesOffset = isolatedTargetPos - otherMatchTiles[0].BoardPiece.BoardPosition; } else { otherTilesOffset = otherMatchTiles[0].BoardPiece.BoardPosition - otherMatchTiles[1].BoardPiece.BoardPosition; } if (otherTilesOffset.row == 0) { // Check if the isolated tile is already on the same row, then we have to target the col. by recalculating the offset between the columns. if (possibleMatchFinder.lastFoundIsolatedTile.BoardPiece.BoardPosition.row == otherMatchTiles[0].BoardPiece.BoardPosition.row) { int colOffset = otherMatchTiles[0].BoardPiece.BoardPosition.col - possibleMatchFinder.lastFoundIsolatedTile.BoardPiece.BoardPosition.col; colOffset = Mathf.Clamp(colOffset, -1, 1); isolatedTargetPos.col += colOffset; } else { isolatedTargetPos.row = otherMatchTiles[0].BoardPiece.BoardPosition.row; } } else { // Check if the isolated tile is already on the same column, then we have to target the row by recalculating the offset between the rows. if (possibleMatchFinder.lastFoundIsolatedTile.BoardPiece.BoardPosition.col == otherMatchTiles[0].BoardPiece.BoardPosition.col) { int rowOffset = otherMatchTiles[0].BoardPiece.BoardPosition.row - possibleMatchFinder.lastFoundIsolatedTile.BoardPiece.BoardPosition.row; rowOffset = Mathf.Clamp(rowOffset, -1, 1); isolatedTargetPos.row += rowOffset; } else { isolatedTargetPos.col = otherMatchTiles[0].BoardPiece.BoardPosition.col; } } Match3BoardPiece targetPiece = gameLogic.boardData[isolatedTargetPos] as Match3BoardPiece; if (TileSwitchInput.Instance.IsEnabled && targetPiece != null && targetPiece.Tile != null && targetPiece.Tile.IsUserMoveable) { // Try to move the isolated tile to make the match. if ( !gameLogic.TryToMoveTile(possibleMatchFinder.lastFoundIsolatedTile, targetPiece.Tile) ) { // If for some reason we failed the above move, try a random move. if ( !useOnlyPossibleMoves ) { if ( TryRandomMoveAround(possibleMatchFinder.lastFoundIsolatedTile.BoardPiece as Match3BoardPiece) ) { return true; } } else { return false; } } else { // Possible match successed return true; } } return false; }
protected bool HasFoundPossibleMatchForColor(TileColorType tileColor) { int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // Check first if we found at least 2 trigger tiles that can be combined. // If thereis a ColorBomb in this list then it can be combined with any user moveable tile(ex:NormalTile) or any other trigger tile. if (triggerTileMatchFound.Count >= 2) { lastFoundIsolatedTile = triggerTileMatchFound[lastTriggerTileIdx]; // Debug.LogWarning("[PossibleMatchesFinder] lastFoundIsolatedTile = " + lastFoundIsolatedTile); return true; } // Check if we found a possible match. if (partialTileMatchesLists[(int)tileColor].Count == 3) { List<Match3Tile> isolatedTiles = isolatedTilesLists[(int)tileColor]; lastFoundIsolatedTile = null; // Usually in the isolated tiles list for a certain tile color, only one tile is left because the other 2 are adjacent. // In case there are more than 1 tiles left (usually all 3 are left) is because it means that none of them is adjacent to the other // and we have to see which 2 tiles are collinear (are on the same line horizontal/vertical) so we know that the 3rd tile is isolated. if (isolatedTiles.Count > 1) { // Search the 2 tiles that are collinear and mark them null so the list is left only with the isolated tile. for(int i = 0; i < isolatedTiles.Count - 1; i++) { Match3Tile tile = isolatedTiles[i]; for(int j = i + 1; j < isolatedTiles.Count; j++) { Match3Tile other = isolatedTiles[j]; if ( tile.BoardPiece.IsCollinearWith(other.BoardPiece) ) { // We found the 2 (and only possible) collinear tiles. // Mark them as null so we are left only with the isolated tile. Don't remove them because it's slower in this case. isolatedTiles[i] = null; isolatedTiles[j] = null; goto FinishedSearch; } } } FinishedSearch: // Find the remaining isolated tile for(int i = 0; i < isolatedTiles.Count; i++) { if (isolatedTiles[i] != null) { lastFoundIsolatedTile = isolatedTiles[i]; break; } } } else { lastFoundIsolatedTile = isolatedTiles[0]; } // Validate the isolated tile for this possible match group. if (lastFoundIsolatedTile == null) { // Debug.LogWarning("[PossibleMatchesFinder] For some reason the isolated tile wasn't found for a possible match! This shouldn't happen!"); // for(int i = 0; i < partialTileMatchesLists[(int)tileColor].Count; i++) // { // Debug.LogWarning(partialTileMatchesLists[(int)tileColor][i].name + ", "); // } } else if ( !lastFoundIsolatedTile.IsUserMoveable ) { // This tile is not user moveable. This possible match group is not valid. ClearPartialMatchesBuffers(); return false; } // isolatedTile.cachedTransform.localScale *= 1.25f; // Debug.Log("[PossibleMatchesFinder] The valid isolated tile is: " + lastFoundIsolatedTile.name); // Store the color type of the possible match. Stop the search here. foundPossibleMatchColor = tileColor; // Debug.LogWarning("We found a possible match: " + foundPossibleMatchColor); return true; } return false; }
/// <summary> /// Adds a new tile to the possible matches list corresponding to this new tile's color and determine if /// this tile is a possible isolated tile in a list of possible matches. /// An isolated tile in a possible match is the tile that can be moved to complete the match (this tile must be user moveable and matchable). /// </summary> /// <param name='newTile'> /// The new found tile. /// </param> protected void AddNewPossibleMatchTile(Match3Tile newTile) { int lastTriggerTileIdx = triggerTileMatchFound.Count - 1; // If the last trigger tile added was a ColorBomb the it can match with this new tile also even if it's a normal tile. // If this is a special (trigger) tile, add to the trigger tiles possible match list if (lastTriggerTileIdx >= 0 && triggerTileMatchFound[lastTriggerTileIdx] is ColorBombTile && triggerTileMatchFound[lastTriggerTileIdx].BoardPiece.IsAdjacentTo(newTile.BoardPiece) || newTile is TriggerTile && (triggerTileMatchFound.Count == 0 || triggerTileMatchFound[lastTriggerTileIdx].BoardPiece.IsAdjacentTo(newTile.BoardPiece))) { // if (lastTriggerTileIdx >= 0 && triggerTileMatchFound[lastTriggerTileIdx] is ColorBombTile) { // Debug.LogWarning("[PossibleMatchesFinder] newTile = " + newTile); // } triggerTileMatchFound.Add(newTile); } partialTileMatchesLists[(int)newTile.TileColor].Add(newTile); List<Match3Tile> isolatedTiles = isolatedTilesLists[(int)newTile.TileColor]; // Find the first adjacent isolated tile from the list corresponding to this tile's color. bool foundIsolatedAdjacentTile = false; for(int i = 0; i < isolatedTiles.Count; i++) { // Remove one of the other isolated tiles in the list because we found that the new tile is adjacent to it. if (isolatedTiles[i].BoardPiece.IsAdjacentTo(newTile.BoardPiece)) { isolatedTiles.RemoveAt(i); foundIsolatedAdjacentTile = true; break; } } // If we didn't find any isolated tile adjacent to this new one, add it to the possibly isolated tiles list corresponding // to this tile's color. if ( !foundIsolatedAdjacentTile ) { isolatedTiles.Add(newTile); } }
public bool IsMatchWith(Match3Tile otherTile) { return otherTile != null && otherTile.CanBeMatched && CanBeMatched && TileColor == otherTile.TileColor; }
public override void RaiseEventTileSwitchAnimBegan (Match3Tile neighborTile) { base.RaiseEventTileSwitchAnimBegan (neighborTile); if ((neighborTile is BombTile || neighborTile is ColorBombTile) && TappedFirst) { Match3BoardGameLogic.Instance.loseConditions.NewMove(); } if (neighborTile is BombTile) { // Don't allow this tile and it's neighbour with who it was switched to switch back on match fail. BombTile neighborBomb = neighborTile as BombTile; neighborBomb.SwitchBackOnMatchFail = false; neighborBomb.DisableTileLogic(); // Replace the default destroy effect with a bigger destroy effect neighborBomb.prefabDestroyEffect = neighborBomb.prefabDoubleDestroyEffect; neighborBomb.useBigTimeBomb = true; } }
public bool HasTileInArea(Match3Tile otherTile) { return (otherTile.LocalPosition - LocalPosition).sqrMagnitude <= Match3BoardRenderer.sqrVertTileDistance; }
public void OnTilesSwitchBadSndEvent(Match3Tile tileA, Match3Tile tileB) { SoundManager.Instance.PlayOneShot(sndTileSwapBad); }
void OnAnyTileDestroyed (Match3Tile tile) { timeToWait = multiplierWait; }