/// <summary> /// This function is used to animate tokens moving into empty spaces after making a match. /// </summary> /// <param name="startGridX"></param> /// <param name="startGridY"></param> /// <param name="endGridX"></param> /// <param name="endGridY"></param> /// <param name="token"></param> public virtual void MoveTokenToEmptyPos(int startGridX, int startGridY, int endGridX, int endGridY, GameObject token) { /* * The next two lines set references to the locations we're using to move the tokens. * startPos is set to the place where a token is coming from * endPos is set to the empty space's location * * The positions are converted into grid positions by gameManager.GetWorldPositionFromGridPosition. */ Vector3 startPos = gameManager.GetWorldPositionFromGridPosition(startGridX, startGridY); Vector3 endPos = gameManager.GetWorldPositionFromGridPosition(endGridX, endGridY); Vector3 pos = Vector3.Lerp(startPos, endPos, lerpPercent); token.transform.position = pos; if (lerpPercent == 1) //If the lerp percentage is complete { /* * Swap the valid token with the empty space. */ gameManager.gridArray[endGridX, endGridY] = token; gameManager.gridArray[startGridX, startGridY] = null; repopulateScript.AddNewTokensToRepopulateGrid(); //THIS COULD ALLOW YOU TO SPAWN VERTICAL MATCH REPLACEMENTS MID-MOVE! } }
/// <summary> /// This function is used to animate tokens moving into empty spaces after making a match. /// </summary> /// <param name="startGridX"></param> /// <param name="startGridY"></param> /// <param name="endGridX"></param> /// <param name="endGridY"></param> /// <param name="token"></param> public virtual void MoveTokenToEmptyPos(int startGridX, int startGridY, int endGridX, int endGridY, GameObject token) { /* * The next two lines set references to the locations we're using to move the tokens. * startPos is set to the place where a token is coming from * endPos is set to the empty space's location * * The positions are converted into grid positions by gameManager.GetWorldPositionFromGridPosition. */ Vector3 startPos = gameManager.GetWorldPositionFromGridPosition(startGridX, startGridY); Vector3 endPos = gameManager.GetWorldPositionFromGridPosition(endGridX, endGridY); Vector3 pos = Vector3.Lerp(startPos, endPos, timer / timeBetweenBeats); token.transform.position = pos; if (timer == timeBetweenBeats) //If the lerp percentage is complete { /* * Swap the valid token with the empty space. */ gameManager.gridArray[endGridX, endGridY] = token; gameManager.gridArray[startGridX, startGridY] = null; RepopulateScript repopulateScript = GetComponent <RepopulateScript>(); repopulateScript.AddNewTokensToRepopulateGrid(); } }
public virtual void Update() { if (!GridHasEmpty()) { if (matchManager.GridHasMatch()) { matchManager.RemoveMatches(); } else { inputManager.SelectToken(); } } else { if (!moveTokenManager.move) { moveTokenManager.SetupTokenMove(); } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) { repopulateManager.AddNewTokensToRepopulateGrid(); } } }
public virtual void Update() { //every frame, check whether the grid is full of tokens. if (!GridHasEmpty()) { //if the grid is full of tokens and has matches, remove them. if (matchManager.GridHasMatch()) { matchManager.RemoveMatches(); } else { //if the grid is full and there are no matches, wait for the player to make a move (and look for it in InputManager) inputManager.SelectToken(); } } else { if (!moveTokenManager.move) { //if the icons are currently moving, set them up to move and leave it be moveTokenManager.SetupTokenMove(); } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) { //if the MoveTokenManager hasn't added any tokens to the grid //tell Repopulate Script to add new tokens repopulateManager.AddNewTokensToRepopulateGrid(); } } }
public virtual void Update() { if (!GridHasEmpty()) //if grid is fully populated { if (matchManager.GridHasMatch()) //if there are matches { matchManager.RemoveMatches(); //remove the matches } else { inputManager.SelectToken(); //allow token to be selected } } else //if grid not fully populated { if (!moveTokenManager.move) //if token movement is false { moveTokenManager.SetupTokenMove(); //set it true so they can fill empty space } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) //if is false { repopulateManager.AddNewTokensToRepopulateGrid(); //and there are still free spaces, allow it to populate } } }
public virtual void Update() { if (!GridHasEmpty()) //if the grid has no empty spots { if (matchManager.GridHasMatch()) //check if it has a match or not { matchManager.RemoveMatches(); //remove the matches if it has } else { inputManager.SelectToken(); //let manager check to see if we clicked on a token } } else { if (!moveTokenManager.move) { moveTokenManager.SetupTokenMove(); } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) { repopulateManager.AddNewTokensToRepopulateGrid(); } } }
public virtual void Update() { //update moves left movesText.text = "Moves Left: " + MovesLeft; //update your score playerScoreText.text = "Your Score: " + PlayerScore; //update their score opponentScoreText.text = "Their Score: " + OpponentScore; switch (currentState) { case GameState.BoardSettled: if (isPlayersTurn) { currentState = GameState.PlayerMakingMove; } else { currentState = GameState.OpponentMakingMove; } break; case GameState.PlayerMakingMove: inputManager.SelectToken(); if (matchManager.GridHasMatch()) { //isPlayersTurn = false; movesLeft--; currentState = GameState.RemovingMatches; } break; case GameState.OpponentMakingMove: StartCoroutine(opponentController.OpponentMove()); currentState = GameState.CheckingMatch; break; case GameState.CheckingMatch: if (matchManager.GridHasMatch()) { //isPlayersTurn = true; currentState = GameState.RemovingMatches; } else if (!moveTokenManager.move) { currentState = GameState.OpponentMakingMove; } break; case GameState.RemovingMatches: matchManager.RemoveMatches(); if (GridHasEmpty() && !moveTokenManager.MoveTokensToFillEmptySpaces()) { currentState = GameState.FillingBoard; } break; case GameState.FillingBoard: if (!moveTokenManager.move) { moveTokenManager.SetupTokenMove(); } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) { repopulateManager.AddNewTokensToRepopulateGrid(); } if (matchManager.GridHasMatch()) { currentState = GameState.RemovingMatches; } if (!GridHasEmpty() && !matchManager.GridHasMatch()) { isPlayersTurn = !isPlayersTurn; currentState = GameState.BoardSettled; } break; } if (Input.GetKey(KeyCode.R)) { SceneManager.LoadScene(0); } if (MovesLeft <= 0 && !moveTokenManager.move) { GameOver(); } }
public virtual void Update() { if (!PlayerLost) { timer += Time.deltaTime; //check to see if the game is over if (!music.isPlaying && !gameOver) { gameOver = GameOver(SUCCESS_MARKER); return; } //each beat, check for matches if (!GridHasEmpty() && timer >= timeBetweenBeats) { if (matchManager.GridHasMatch()) { matchManager.RemoveMatches(); numberManager.ScorePoints(); //check to see if the game is over } } else if (!GridHasEmpty()) { inputManager.SelectToken(); //if not on the beat, allow the player to make selections } //if there are empty spaces, tokens need to move if (GridHasEmpty()) { if (!moveTokenManager.move) { //if the icons are currently moving, set them up to move and leave it be moveTokenManager.SetupTokenMove(); } if (!moveTokenManager.MoveTokensToFillEmptySpaces()) { //if the MoveTokenManager hasn't added any tokens to the grid //tell Repopulate Script to add new tokens repopulateManager.AddNewTokensToRepopulateGrid(); } } //keep on the beat if (timer >= timeBetweenBeats) { timer = 0.0f; } } else if (PlayerLost) { failTimer += Time.deltaTime; healthText.color = failColor; if (failTimer >= failGameEndDelay) { GameOver(FAIL_MARKER); } } //every frame, check whether the grid is full of tokens. // if(!GridHasEmpty()){ // //if the grid is full of tokens and has matches, remove them. // if(matchManager.GridHasMatch()){ // matchManager.RemoveMatches(); // } else { // //if the grid is full and there are no matches, wait for the player to make a move (and look for it in InputManager) // inputManager.SelectToken(); // } // // } else { // if(!moveTokenManager.move){ // //if the icons are currently moving, set them up to move and leave it be // moveTokenManager.SetupTokenMove(); // } // if(!moveTokenManager.MoveTokensToFillEmptySpaces()){ // //if the MoveTokenManager hasn't added any tokens to the grid // //tell Repopulate Script to add new tokens // repopulateManager.AddNewTokensToRepopulateGrid(); // } // } }