private IEnumerator control() { bool still; while (true) { still = true; //the player is still, but if they've just finished moving a space, moving is still true for this frame (see end of coroutine) if (canInput) { if (!surfing && !bike) { if (Input.GetButton("Run")) { running = true; if (moving) { updateAnimation("run", runFPS); } else { updateAnimation("walk", walkFPS); } speed = runSpeed; } else { running = false; updateAnimation("walk", walkFPS); speed = walkSpeed; } } if (Input.GetButton("Start")) { //open Pause Menu if (moving || Input.GetButtonDown("Start")) { if (setCheckBusyWith(Scene.main.Pause.gameObject)) { animPause = true; Scene.main.Pause.gameObject.SetActive(true); StartCoroutine(Scene.main.Pause.control()); while (Scene.main.Pause.gameObject.activeSelf) { yield return(null); } unsetCheckBusyWith(Scene.main.Pause.gameObject); } } } else if (Input.GetButtonDown("Select")) { interact(); } //if pausing/interacting/etc. is not being called, then moving is possible. // (if any direction input is being entered) else if (Input.GetAxisRaw("Horizontal") != 0 || Input.GetAxisRaw("Vertical") != 0) { //if most recent direction pressed is held, but it isn't the current direction, set it to be if (mostRecentDirectionPressed != direction && isDirectionKeyHeld(mostRecentDirectionPressed)) { updateDirection(mostRecentDirectionPressed); if (!moving) { // unless player has just moved, wait a small amount of time to ensure that they have time to yield return(new WaitForSeconds(directionChangeInputDelay)); } // let go before moving (allows only turning) } //if a new direction wasn't found, direction would have been set, thus ending the update else { //if current direction is not held down, check for the new direction to turn to if (!isDirectionKeyHeld(direction)) { //it's least likely to have held the opposite direction by accident int directionCheck = (direction + 2 > 3) ? direction - 2 : direction + 2; if (isDirectionKeyHeld(directionCheck)) { updateDirection(directionCheck); if (!moving) { yield return(new WaitForSeconds(directionChangeInputDelay)); } } else { //it's either 90 degrees clockwise, counter, or none at this point. prioritise clockwise. directionCheck = (direction + 1 > 3) ? direction - 3 : direction + 1; if (isDirectionKeyHeld(directionCheck)) { updateDirection(directionCheck); if (!moving) { yield return(new WaitForSeconds(directionChangeInputDelay)); } } else { directionCheck = (direction - 1 < 0) ? direction + 3 : direction - 1; if (isDirectionKeyHeld(directionCheck)) { updateDirection(directionCheck); if (!moving) { yield return(new WaitForSeconds(directionChangeInputDelay)); } } } } } //if current direction was held, then we want to attempt to move forward. else { moving = true; } } //if moving is true (including by momentum from the previous step) then attempt to move forward. if (moving) { still = false; yield return(StartCoroutine(moveForward())); } } else if (Input.GetKeyDown("g")) { //DEBUG Debug.Log(currentMap.getTileTag(transform.position)); if (followerScript.canMove) { followerScript.StartCoroutine(followerScript.withdrawToBall()); } else { followerScript.canMove = true; } } } if (still) { //if still is true by this point, then no move function has been called animPause = true; moving = false; } //set moving to false. The player loses their momentum. yield return(null); } }
private IEnumerator surfCheck() { Pokemon targetPokemon = SaveData.currentSave.PC.getFirstFEUserInParty("Surf"); if (targetPokemon != null) { if (getForwardVector(direction, false) != Vector3.zero) { if (setCheckBusyWith(this.gameObject)) { Dialog.drawDialogBox(); yield return (Dialog.StartCoroutine(Dialog.drawText("The water is dyed a deep blue. Would you \nlike to surf on it?"))); Dialog.drawChoiceBox(); yield return(Dialog.StartCoroutine(Dialog.choiceNavigate())); Dialog.undrawChoiceBox(); int chosenIndex = Dialog.chosenIndex; if (chosenIndex == 1) { Dialog.drawDialogBox(); yield return (Dialog.StartCoroutine(Dialog.drawText(targetPokemon.getName() + " used " + targetPokemon.getFirstFEInstance("Surf") + "!"))); while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back")) { yield return(null); } surfing = true; updateMount(true, "surf"); BgmHandler.main.PlayMain(GlobalVariables.global.surfBGM, GlobalVariables.global.surfBgmLoopStart); //determine the vector for the space in front of the player by checking direction Vector3 spaceInFront = new Vector3(0, 0, 0); if (direction == 0) { spaceInFront = new Vector3(0, 0, 1); } else if (direction == 1) { spaceInFront = new Vector3(1, 0, 0); } else if (direction == 2) { spaceInFront = new Vector3(0, 0, -1); } else if (direction == 3) { spaceInFront = new Vector3(-1, 0, 0); } mount.transform.position = mount.transform.position + spaceInFront; followerScript.StartCoroutine(followerScript.withdrawToBall()); StartCoroutine(stillMount()); forceMoveForward(); yield return(StartCoroutine(jump())); updateAnimation("surf", walkFPS); speed = surfSpeed; } Dialog.undrawDialogBox(); unsetCheckBusyWith(this.gameObject); } } } else { if (setCheckBusyWith(this.gameObject)) { Dialog.drawDialogBox(); yield return(Dialog.StartCoroutine(Dialog.drawText("The water is dyed a deep blue."))); while (!Input.GetButtonDown("Select") && !Input.GetButtonDown("Back")) { yield return(null); } Dialog.undrawDialogBox(); unsetCheckBusyWith(this.gameObject); } } yield return(new WaitForSeconds(0.2f)); }