private void PrimeTricks() { //For every trick listed in the inspector for (int i = 0; i < tricks.Count; i++) { //Assign that given trick to "trick". Trick trick = tricks[i]; //Wait and listen for that trick to be completed. trick.onInputted.AddListener(() => { //When a trick is fully inputted, we want to do these things. //skip = true; if (performedTrick != null) { if (trick.inputs.Count > performedTrick.inputs.Count) { //Save that trick for later use. performedTrickStep = trick.trickStep; performedTrick = trick; } } else { performedTrickStep = trick.trickStep; performedTrick = trick; } }); } }
//A method that activates a given trick public void TrickStep(TrickStep trickStep) { currentTrickStep = trickStep; if (currentTrickStep.state != PlayerStateManager.PlayerState.Idle && !doingTrick) { //Change the player's state to that trick. stateManager.ActiveState(currentTrickStep.state); doingTrick = true; } if (currentTrickStep.comboMultiplier != 0) { //Add to the player's multiplier. comboManager.newComboValue = currentTrickStep.comboMultiplier; comboManager.AddToCombo(); } }
private void Update() { //Debug.Log("currentTricks.Count = " + currentTricks.Count); //If there are any tricks that can possibly be done given the player's recent inputs, if (currentTricks.Count > 0) { currentLeeway += Time.deltaTime; //When the time to enter combos runs out, if (currentLeeway >= trickLeeway) { if (lastInput != null) { if (performedTrickStep != null) { //Perform the last saved trick. TrickStep(performedTrickStep); } performedTrickStep = null; performedTrick = null; lastInput = null; } ResetTricks(); } } else { currentLeeway = 0; } //Clear last frame's input. TrickInput input = null; //This is where we look for input. // //Currently this does not allow for multiple tricks in the same jump. I don't think we want that. if (stateManager.currentState == PlayerStateManager.PlayerState.Airborne) { if (Input.GetKeyDown(upKey)) { input = new TrickInput(TrickStepType.up); } if (Input.GetKeyDown(downKey)) { input = new TrickInput(TrickStepType.down); } if (Input.GetKeyDown(leftKey)) { input = new TrickInput(TrickStepType.left); } if (Input.GetKeyDown(rightKey)) { input = new TrickInput(TrickStepType.right); } if (Input.GetKeyDown(spaceKey)) { input = new TrickInput(TrickStepType.touch); } } //If the player did not input anything, exit update for this frame. if (input == null) { return; } //Store which input the player inputted. lastInput = input; //Create a list of tricks to remove. List <int> remove = new List <int>(); //For every trick that is currently possible. for (int i = 0; i < currentTricks.Count; i++) { Trick t = tricks[currentTricks[i]]; //Call the ContinueTrick method and if the input that was given this frame can complete this given trick. if (t.ContinueTrick(input)) { //Give the player more time to input more TrickSteps currentLeeway = 0; } else { //If that input was not valid for a given trick, get ready to remove that trick from the list of possible tricks. remove.Add(i); } } //if (skip) //{ // skip = false; // return; //} //For every trick that exists for (int i = 0; i < tricks.Count; i++) { //if that trick is already in the currentTricks list, continue the loop if (currentTricks.Contains(i)) { continue; } //if if (tricks[i].ContinueTrick(input)) { currentTricks.Add(i); currentLeeway = 0; } } //Remove all of the tricks that became invalid from the list of possible tricks. foreach (int i in remove) { if (remove.Count < currentTricks.Count) { if (i < currentTricks.Count) { currentTricks.RemoveAt(i); } } } }