//-----------------------------------------------------------------------------------------------------------------------------------------------// private void Start() { //gets all required components P_rb = GetComponent <Rigidbody2D>(); P_CColl = GetComponent <CapsuleCollider2D>(); P_ShieldSprite = GameObject.FindGameObjectWithTag("Shield").GetComponent <SpriteRenderer>(); //sets the input variables P_PlayerDirection = Vector2.zero; //now set the state from the start P_CurrentState = P_States.controlled; //set timer to 0 P_DashTimer = 0.0f; //setup inputs string[] temp0 = new string[2]; temp0[0] = "CTRL - A"; temp0[1] = "Dash"; P_dash = new Button(temp0); string[] temp1 = new string[3]; temp1[0] = "CTRL - LSX"; temp1[1] = "CTRL - DPADX"; temp1[2] = "Horizontal"; string[] temp2 = new string[3]; temp2[0] = "CTRL - LSY"; temp2[1] = "CTRL - DPADY"; temp2[2] = "Vertical"; P_axis = new Joystick(temp1, temp2); }
public void UnFreeze() { if (P_CurrentState == P_States.frozen) { P_CurrentState = P_States.controlled; } }
//-----------------------------------------------------------------------------------------------------------------------------------------------// private void P_HandleStates() { // the controlled state if (P_CurrentState == P_States.controlled) { // if the dash button is pressed if (P_dash.getDown()) { // checks if there is a direction for the player to dash in if (P_PlayerDirection != Vector2.zero && P_DashTimer <= 0.0f) { // regular dash P_CurrentState = P_States.dash; return; } // if there is no direction to dash in then you will start shielding if (P_PlayerDirection == Vector2.zero) { P_CurrentState = P_States.shield; return; } } } // the controlled state // the dash state if (P_CurrentState == P_States.dash) { if (P_axis.get() != Vector2.zero && P_DashTimer >= P_DashTime - P_DashDanceTimeFrame && P_dash.getDown()) { P_DashTimer = 0.0f; P_PlayerDirection = P_axis.get(); Debug.Log("HI"); } }// the dash state }
} /* TODO: add functionality if needed */ //-----------------------------------------------------------------------------------------------------------------------------------------------// public bool Freeze() { if (P_CurrentState == P_States.controlled) { P_CurrentState = P_States.frozen; return(true); } else { return(false); } }
private void P_HandleShield() { if (P_dash.getHold()) { P_CColl.isTrigger = true; P_ShieldSprite.enabled = true; } else { P_CColl.isTrigger = false; P_ShieldSprite.enabled = false; P_CurrentState = P_States.controlled; } }
private void P_HandleDash() { //get current position Vector2 newPos = transform.position; //add the displacement newPos += P_PlayerDirection * P_DashDistance * (Time.fixedDeltaTime / P_DashTime); //apply new position P_rb.MovePosition(newPos); //handle the timer P_DashTimer += Time.fixedDeltaTime; if (P_DashTimer >= P_DashTime) { P_CurrentState = P_States.controlled; P_DashTimer = P_DashDelay; } }