/// <summary> /// Raises the drag gesture event. This event is raised by FingerGestures's DragRecognizer component. /// Determine the selected tile and in which direction the user dragged it and tell the <see cref="Match3BoardGameLogic"/> /// that we've started moving that tile in that direction. /// </summary> /// <param name='eventData'> /// Event data. /// </param> public void OnDragGesture(DragGesture eventData) { if (dragLock > 0) { tapSelectedTile = null; return; } // Check if we've selected any tile. if (eventData.StartSelection != null && eventData.StartSelection.layer == Match3Globals.Instance.layerBoardTile) { if (eventData.Phase == ContinuousGesturePhase.Started) { // Cancel the tap selected tile if we've done a drag gesture. tapSelectedTile = null; AbstractTile dragSelectedTile = eventData.StartSelection.GetComponent <AbstractTile>(); TileMoveDirection moveDirection = Match3BoardGameLogic.GetTileMoveDirection(eventData.TotalMove); if (InputFilter == null || InputFilter(dragSelectedTile, null, moveDirection)) { // Debug.Log("Drag event started! Start Selection: " + eventData.StartSelection + " -> totalMove = " + eventData.TotalMove); if (boardGameLogic.TryToMoveTile(dragSelectedTile, moveDirection)) { //boardGameLogic.loseConditions.NewMove(); } } } } }
bool InputFilter(AbstractTile selectedTile, AbstractTile destinationTile, TileMoveDirection moveDirection) { if (pieceToMove == null || pieceToMoveDestination == null) { return true; } AbstractTile tileToMove = pieceToMove.Tile; AbstractTile tileToMoveDest = pieceToMoveDestination.Tile; if (destinationTile == null) { Match3BoardGameLogic boardLogic = Match3BoardGameLogic.Instance; BoardCoord targetBoardPos = selectedTile.BoardPiece.BoardPosition; targetBoardPos.OffsetByAndClamp(boardLogic.tilesMoveDirections[(int)moveDirection], boardLogic.boardData.NumRows - 1, boardLogic.boardData.NumColumns - 1); destinationTile = boardLogic.boardData[targetBoardPos].Tile; } if (tileToMove == selectedTile && tileToMoveDest == destinationTile || tileToMove == destinationTile && tileToMoveDest == selectedTile) { disableTutorial = true; TileSwitchInput.Instance.InputFilter = null; return true; } return false; }
public override bool TryToMoveTile(AbstractTile tile, TileMoveDirection moveDirection) { //TODO: ask tile to determine if it can move to given position => trigger tile move anim => register to anim finish event => // notify back the gameboard logic to check for matches => // if no match -> switch back (if tile allows it) // if found matches => validate match pattern -> spawn new tiles, new effects, trigger other tiles, etc -> mark for destroy matched tiles // -> update board state (check all tiles that should be falling and set them to fall and let them update their positions until they stop) BoardCoord offsetDir = tilesMoveDirections[(int)moveDirection]; BoardCoord targetBoardPos = tile.BoardPiece.BoardPosition; // Offset the target board position by the tile movement direction offset and clamp the result to the border of the board. targetBoardPos.OffsetByAndClamp(tilesMoveDirections[(int)moveDirection], boardData.NumRows - 1, boardData.NumColumns - 1); // Debug.Log("[Match3BoardGameLogic] BeginMoveTile " + tile.name + " -> from: " + tile.BoardPiece.BoardPosition + // " to " + (tile.BoardPiece.BoardPosition.row + offsetDir.row) + ", " + (tile.BoardPiece.BoardPosition.col + offsetDir.col)); return(TryToMoveTile(tile, boardData[targetBoardPos].Tile)); }
void Update() { float timeElapsed = Time.realtimeSinceStartup - mTime; if (_GameUI.IsVisible()) { _GameUI.SetTime(timeElapsed); if (timeElapsed <= 100) { _GameUI.SetScore(100 - Mathf.CeilToInt(timeElapsed)); } else { _GameUI.SetScore(0); } } if (mFireBall != null) { if (mFireBall.IsStationary() && Input.GetKeyUp(KeyCode.W) || Input.GetKeyUp(KeyCode.UpArrow)) { mMoveDirection = TileMoveDirection.UP; mFireBall.AddForce(TileMoveDirection.UP); } else if (mFireBall.IsStationary() && Input.GetKeyUp(KeyCode.A) || Input.GetKeyUp(KeyCode.LeftArrow)) { mMoveDirection = TileMoveDirection.LEFT; mFireBall.AddForce(TileMoveDirection.LEFT); } else if (mFireBall.IsStationary() && Input.GetKeyUp(KeyCode.D) || Input.GetKeyUp(KeyCode.RightArrow)) { mMoveDirection = TileMoveDirection.RIGHT; mFireBall.AddForce(TileMoveDirection.RIGHT); } else if (mFireBall.IsStationary() && Input.GetKeyUp(KeyCode.S) || Input.GetKeyUp(KeyCode.DownArrow)) { mMoveDirection = TileMoveDirection.DOWN; mFireBall.AddForce(TileMoveDirection.DOWN); } } }
public void AddForce(TileMoveDirection moveDir) { transform.parent = null; if (moveDir == TileMoveDirection.UP) { mRigidbody.AddForce(transform.up * 3.0f); } else if (moveDir == TileMoveDirection.RIGHT) { mRigidbody.AddForce(transform.right * 3.0f); } else if (moveDir == TileMoveDirection.LEFT) { mRigidbody.AddForce(-transform.right * 3.0f); } else if (moveDir == TileMoveDirection.DOWN) { mRigidbody.AddForce(-transform.up * 3.0f); } }
void OnTriggerEnter(Collider other) { if (mTeleportToTile != null && other.gameObject.name.Contains("PfTileFireball")) { TileMoveDirection tileMoveDirection = LevelManager.pInstance.GetMoveDirection(); Rigidbody fireRigidbody = other.gameObject.GetComponent <Rigidbody>(); fireRigidbody.velocity = Vector3.zero; Vector3 otherPos = other.gameObject.transform.position; if (tileMoveDirection == TileMoveDirection.DOWN) { otherPos.y = mTeleportToTile.gameObject.transform.position.y - 1.00001f; otherPos.x = mTeleportToTile.gameObject.transform.position.x; } else if (tileMoveDirection == TileMoveDirection.RIGHT) { otherPos.x = mTeleportToTile.gameObject.transform.position.x + 1.00001f; otherPos.y = mTeleportToTile.gameObject.transform.position.y; } else if (tileMoveDirection == TileMoveDirection.LEFT) { otherPos.x = mTeleportToTile.gameObject.transform.position.x - 1.00001f; otherPos.y = mTeleportToTile.gameObject.transform.position.y; } else { otherPos.y = mTeleportToTile.gameObject.transform.position.y + 1.00001f; otherPos.x = mTeleportToTile.gameObject.transform.position.x; } other.gameObject.transform.position = otherPos; mAudioSource.Play(); } }
public abstract bool TryToMoveTile(AbstractTile tile, TileMoveDirection moveDirection);
public override bool TryToMoveTile(AbstractTile tile, TileMoveDirection moveDirection) { //TODO: ask tile to determine if it can move to given position => trigger tile move anim => register to anim finish event => // notify back the gameboard logic to check for matches => // if no match -> switch back (if tile allows it) // if found matches => validate match pattern -> spawn new tiles, new effects, trigger other tiles, etc -> mark for destroy matched tiles // -> update board state (check all tiles that should be falling and set them to fall and let them update their positions until they stop) BoardCoord offsetDir = tilesMoveDirections[(int)moveDirection]; BoardCoord targetBoardPos = tile.BoardPiece.BoardPosition; // Offset the target board position by the tile movement direction offset and clamp the result to the border of the board. targetBoardPos.OffsetByAndClamp(tilesMoveDirections[(int)moveDirection], boardData.NumRows - 1, boardData.NumColumns - 1); // Debug.Log("[Match3BoardGameLogic] BeginMoveTile " + tile.name + " -> from: " + tile.BoardPiece.BoardPosition + // " to " + (tile.BoardPiece.BoardPosition.row + offsetDir.row) + ", " + (tile.BoardPiece.BoardPosition.col + offsetDir.col)); return TryToMoveTile(tile, boardData[targetBoardPos].Tile); }