public static Player_Input.PlayerInput getPlayerInput(ref ComboInfo combo_info, bool enable_attacks, bool enable_parry, bool enable_dodge, bool enable_laser) { Player_Input.PlayerInput input = Player_Input.PlayerInput.None; //check if player has inputed dash if (enable_dodge && (Input.GetAxis("Horizontal") != 0 || Input.GetAxis("Vertical") != 0) && Input.GetButtonDown("Dodge")) { input |= Player_Input.PlayerInput.Dodge; } //otherwise input parry else if (enable_parry && (Input.GetAxis("Horizontal") == 0 && Input.GetAxis("Vertical") == 0) && Input.GetButtonDown("Dodge")) { input |= Player_Input.PlayerInput.Parry; } //otherwise check if left or right are inputed else if (Math.Abs(Input.GetAxis("Horizontal")) > 0.9) { input |= Player_Input.PlayerInput.Dash; } //check if jump is inputed if (Input.GetButtonDown("Jump")) { input |= Player_Input.PlayerInput.Jump; } //check if attack is inputted if (enable_attacks && Input.GetButtonDown("Attack")) { input |= Player_Input.PlayerInput.Attack; } //check if laser is inputted if (enable_laser && Input.GetButtonDown("SpecialAttack1") && combo_info.canFireLaser()) { input |= Player_Input.PlayerInput.Attack; input |= Player_Input.PlayerInput.Special_attack_0; } return(input); }
/* * Process the state controller using the transition function with the player input */ public bool process_state(Player_Input.PlayerInput input) { return(transition_function.process_state_with_player_input(ref curr_state, ref prev_states, ref state_duration, input)); }
public bool process_state_with_player_input(ref int curr_state, ref List <int> prev_states, ref float duration, Player_Input.PlayerInput input) { return(false); }
//add input to queue, that's it public bool process_state_with_player_input(ref int curr_state, ref List <int> prev_states, ref float duration, Player_Input.PlayerInput input) { //enqueue attack if attack queue is not full if (input.HasFlag(Player_Input.PlayerInput.Attack) && attack_queue.Count <= 8) { attack_queue.Enqueue((int)input); return(true); } //clear queue if non-attack action is inputted, and store what action that is else if (!(input == Player_Input.PlayerInput.None) && attack_queue.Count > 0) { attack_queue.Clear(); } return(false); }
public bool process_state_with_player_input(ref int curr_state, ref List <int> prev_states, ref float duration, Player_Input.PlayerInput input) { //exit jump attack state when landing if (player_characterController.isGrounded && curr_state == (int)player_state.attack_jump) { update_state((int)player_state.idle, 0, ref curr_state, ref prev_states, ref duration); } //exit parry state on successful parry if (player_health_info.getParrySuccess() && curr_state == (int)player_state.parry_active) { update_state((int)player_state.idle, 0, ref curr_state, ref prev_states, ref duration); } if (duration <= 0) { if (curr_state == (int)player_state.parry_active) { update_state((int)player_state.parry_cooldown, parry_cooldown_duration, ref curr_state, ref prev_states, ref duration); } else if (player_characterController.isGrounded && curr_state != (int)player_state.idle) { update_state((int)player_state.idle, 0, ref curr_state, ref prev_states, ref duration); } else if (!player_characterController.isGrounded && curr_state != (int)player_state.airborne) { update_state((int)player_state.airborne, 0, ref curr_state, ref prev_states, ref duration); } } else { return(false); } //if multiple inputs are present, attack has the highest priority if (input.HasFlag(Player_Input.PlayerInput.Attack)) { //if we aren't currently dodge/parrying/attack_basic, we will be moving into attack state if (curr_state != (int)player_state.dodge && curr_state != (int)player_state.attack_basic && curr_state != (int)player_state.attack_jump && curr_state != (int)player_state.attack_dash && curr_state != (int)player_state.attack_special_0) { if ((curr_state == (int)player_state.idle || curr_state == (int)player_state.walk || curr_state == (int)player_state.dash || curr_state == (int)player_state.airborne) && input.HasFlag(Player_Input.PlayerInput.Special_attack_0)) { //only shoot laser if cooldown is expired if (laser_cd_timer.Value <= 0) { update_state((int)player_state.attack_special_0, 0, ref curr_state, ref prev_states, ref duration); laser_cd_timer.Value = laser_cooldown; } else //do nothing if cooldown isn't expired { return(false); } } else if (curr_state == (int)player_state.airborne || input.HasFlag(Player_Input.PlayerInput.Jump)) { update_state((int)player_state.attack_jump, jump_attack_duration, ref curr_state, ref prev_states, ref duration); } else if (curr_state == (int)player_state.dash || input.HasFlag(Player_Input.PlayerInput.Dash)) { update_state((int)player_state.attack_dash, dash_attack_duration, ref curr_state, ref prev_states, ref duration); } else if (curr_state == (int)player_state.idle) { update_state((int)player_state.attack_basic, 0, ref curr_state, ref prev_states, ref duration); } return(true); } // else do nothing return(false); } else // process parry input if (input.HasFlag(Player_Input.PlayerInput.Parry)) { if (curr_state == (int)player_state.idle || curr_state == (int)player_state.walk || curr_state == (int)player_state.dash) { update_state((int)player_state.parry_active, parry_active_duration, ref curr_state, ref prev_states, ref duration); return(true); } } else if (input.HasFlag(Player_Input.PlayerInput.Jump)) { if (curr_state == (int)player_state.idle || curr_state == (int)player_state.walk || curr_state == (int)player_state.dash) { //start a new jump jump_count = 1; update_state((int)player_state.jump, 0, ref curr_state, ref prev_states, ref duration); } else if (curr_state == (int)player_state.airborne && jump_count < maximum_jump_count) { //another jump is allowed update_state((int)player_state.jump, 0, ref curr_state, ref prev_states, ref duration); jump_count++; } else { //cannot update state return(false); } return(true); } else if (input.HasFlag(Player_Input.PlayerInput.Dodge) && dodge_cd_timer.Value <= 0) { if (curr_state == (int)player_state.idle || curr_state == (int)player_state.walk || curr_state == (int)player_state.dash || curr_state == (int)player_state.airborne) { update_state((int)player_state.dodge, dodge_duration, ref curr_state, ref prev_states, ref duration); dodge_cd_timer.Value = dodge_cooldown; return(true); } return(false); } else //trying to move if (input.HasFlag(Player_Input.PlayerInput.Dash) || input.HasFlag(Player_Input.PlayerInput.Walk)) { if (curr_state == (int)player_state.idle || curr_state == (int)player_state.walk || curr_state == (int)player_state.dash) { //if not performing any special action, allow movement int walk_or_dash = (input.HasFlag(Player_Input.PlayerInput.Dash)) ? (int)player_state.dash : (int)player_state.walk; update_state(walk_or_dash, 0, ref curr_state, ref prev_states, ref duration); return(true); } return(false); } return(false); }
private void process_attack_input(bool state_changed, Player_Input.PlayerInput input) { if (input.HasFlag(Player_Input.PlayerInput.Attack)) { if (state_controller.curr_state == (int)Player_State_Transition_Func.player_state.attack_basic) { attack_controller.process_state(Player_Input.PlayerInput.Attack); } else if (state_changed) { if (state_controller.curr_state == (int)Player_State_Transition_Func.player_state.attack_jump) { attack_controller.process_state(Player_Input.PlayerInput.Jump | Player_Input.PlayerInput.Attack); } else if (state_controller.curr_state == (int)Player_State_Transition_Func.player_state.attack_dash) { attack_controller.process_state(Player_Input.PlayerInput.Dash | Player_Input.PlayerInput.Attack); } else if (state_controller.curr_state == (int)Player_State_Transition_Func.player_state.attack_special_0) { attack_controller.process_state(Player_Input.PlayerInput.Special_attack_0 | Player_Input.PlayerInput.Attack); } } } else { attack_controller.process_state(input); } bool attack_sequence_changed = attack_controller.process_state(); if (attack_sequence_changed) { state_controller.state_duration = attack_controller.state_duration; if (attack_controller.curr_state != 0 && attack_controller.curr_state <= (int)Attack_State_Transition_Func.attack_state.attack_basic_4) { state_controller.curr_state = (int)Player_State_Transition_Func.player_state.attack_basic; } if (attack_controller.curr_state == (int)Attack_State_Transition_Func.attack_state.attack_dash_0) { state_controller.curr_state = (int)Player_State_Transition_Func.player_state.attack_dash; } if (attack_controller.curr_state == (int)Attack_State_Transition_Func.attack_state.attack_jump_0) { state_controller.curr_state = (int)Player_State_Transition_Func.player_state.attack_jump; } if (attack_controller.curr_state == (int)Attack_State_Transition_Func.attack_state.attack_special_0) { state_controller.state_duration = attack_controller.state_duration; //do attack in correct direction if (transform.right.x >= 0) { laser_manager.fire_laser(new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), false, new Vector3(transform.position.x + 10, transform.position.y + 1, transform.position.z), 0.2f, 10f); } if (transform.right.x < 0) { laser_manager.fire_laser(new Vector3(transform.position.x, transform.position.y + 1, transform.position.z), false, new Vector3(transform.position.x - 10, transform.position.y + 1, transform.position.z), 0.2f, 10f); } } } }
// Update is called once per frame void Update() { if (!enable_control) { return; } float horizontal_input = Input.GetAxis("Horizontal"); float vertical_input = Input.GetAxis("Vertical"); bool pause_input = Input.GetButtonDown("Pause"); reload_scene_if_death(); Player_Input.PlayerInput input = Player_controller_helper.getPlayerInput(ref combo_info, enable_attacks, enable_parry, enable_dodge, enable_laser); if (pause_manager.GetLaserPaused()) { if (Input.GetButtonDown("Jump")) { pause_manager.UnpauseLaser(); pause_manager.RemoveLaserTutorial(); pause_manager.PauseCombo(); pause_manager.ShowComboTutorial(); } } else if (pause_manager.GetComboPaused()) { if (Input.GetButtonDown("Jump")) { pause_manager.UnpauseCombo(); pause_manager.RemoveComboTutorial(); Time.timeScale = 1f; } if (Input.GetButtonDown("Attack")) { pause_manager.UnpauseCombo(); pause_manager.RemoveComboTutorial(); pause_manager.PauseLaser(); pause_manager.ShowLaserTutorial(); } } pause_game(pause_input); if (pause_manager.GetPaused()) { if (Input.GetButtonDown("Jump") && pause_visual) { pause_manager.RemovePause(); pause_visual = false; } else if (Input.GetButtonDown("Jump") && !pause_visual) { pause_manager.ShowPause(); pause_visual = true; } return; } //if parry_stop is active, check if it should be removed if (parry_stop) { Time.timeScale = 0f; if (Time.realtimeSinceStartup - parry_stop_initial > 0.3f) { parry_stop = false; Time.timeScale = 1f; } } attack_controller.process_time(); state_controller.process_time(); bool state_changed = state_controller.process_state(input); process_attack_input(state_changed, input); if (attack_controller.curr_state != 0) { //attacking char_animator.Play(Utility_methods.GetDescription <Attack_State_Transition_Func.attack_state>((Attack_State_Transition_Func.attack_state)attack_controller.curr_state)); } else { string desc = Utility_methods.GetDescription <Player_State_Transition_Func.player_state>((Player_State_Transition_Func.player_state)state_controller.curr_state); if (desc != "") { char_animator.Play(desc); } //set animation to whatever else } process_parry(state_changed); setColour(); apply_movement(horizontal_input, vertical_input); update_indicators(); if (dodge_invuln_timer > 0) { dodge_invuln_timer -= Time.deltaTime; } if (knockback_timer > 0) { knockback_timer -= Time.deltaTime; } }