コード例 #1
0
    //Performs Shield ability
    //NOTE: Also need to pass in bool if that's how I'm gonna handle animationss
    public void Shield(ref PlayerState playerState)
    {
        switch (shieldState)
        {
        case ShieldState.Setup:
            //Activate shield collider here
            playerFaceDirection = orientationSystem.DetermineDirectionFromVector(moveInfo.GetLastMove());
            ActivateCorrespondingCollider(playerFaceDirection);
            //Debug.Log (playerFaceDirection);

            //Play animation
            animator.Play("Shield State");

            shieldState = ShieldState.Shielding;

            break;

        case ShieldState.Shielding:
            //NOTE: if strafing, play strafe animation
            Strafe();

            //If player is shielding, stay in this state; else, exit state
            if (isShielding())
            {
                //Stay in this state
            }
            else
            {
                DeactivateCorrespondingCollider(playerFaceDirection);

                shieldState = ShieldState.Setup;
                playerState = PlayerState.Default;
                return;
            }

            //Check for Grab, Dodge, or (maybe) Jump inputs
            //Grab
            if (Input.GetButtonDown("AttackPS4"))
            {
                //shieldColliderUp.enabled = false;
                //Switch to grab state
            }
            else if (Input.GetButtonDown("SprintPS4"))
            {
                //Check if there's any movement
                if (playerMoving)
                {
                    //Switch to DodgeRoll state
                    DeactivateCorrespondingCollider(playerFaceDirection);
                    shieldState = ShieldState.Setup;
                    playerState = PlayerState.DodgeRolling;
                }
            }

            break;
        }
    }     //Shield
コード例 #2
0
    /// <summary>
    ///    Modifies the hold position to the direction the player is
    ///    facing when performing a grab.
    /// </summary>
    void ModifyHoldPosition()
    {
        switch (oSystem.DetermineDirectionFromVector(moveInfo.GetLastMove()))
        {
        case EightDirections.North:
            holdPosition.localPosition = new Vector2(0, .15f);
            break;

        case EightDirections.NorthEast:
            holdPosition.localPosition = new Vector2(.106f, .106f);
            break;

        case EightDirections.East:
            holdPosition.localPosition = new Vector2(.15f, 0);
            break;

        case EightDirections.SouthEast:
            holdPosition.localPosition = new Vector2(.106f, -.106f);
            break;

        case EightDirections.South:
            holdPosition.localPosition = new Vector2(0, -.15f);
            break;

        case EightDirections.SouthWest:
            holdPosition.localPosition = new Vector2(-.106f, -.106f);
            break;

        case EightDirections.West:
            holdPosition.localPosition = new Vector2(-.15f, 0);
            break;

        case EightDirections.NorthWest:
            holdPosition.localPosition = new Vector2(-.106f, .106f);
            break;
        }
    }
コード例 #3
0
    public void ChargeAttack(ref PlayerState playerState, Vector2 attackDirection)
    {
        switch (chargeAttackState)
        {
        case ChargeAttackState.Setup:
            timer               = maxChargeTime;
            finalAttackForce    = baseAttackForce;
            chargeAttackState   = ChargeAttackState.Charging;
            playerBody.velocity = Vector2.zero;
            spriteRenderer.material.SetFloat("_FlashAmount", 0.60f);

            //Activate corresponding collider
            //playerFaceDirection = orientationSystem.GetDirection(attackDirection);
            playerFaceDirection = DirectionHandler.GetDirectionFromVector(attackDirection);
            break;

        case ChargeAttackState.Charging:
            timer -= Time.deltaTime;

            //Play Charging Animation
            animator.Play("Charging Attack");

            //Make player flash while charging
            spriteRenderer.material.SetFloat("_FlashAmount", Mathf.PingPong(timer * 4.7f, 0.60f));

            //If timer is up or player releases button, then perform attack
            if (timer <= 0f || (Input.GetButtonUp("AttackPS4")) || Input.GetButtonUp("Attack"))
            {
                spriteRenderer.material.SetFloat("_FlashAmount", 0f);
                chargeAttackState = ChargeAttackState.Attacking;
                ActivateCorrespondingCollider(playerFaceDirection);

                playerAttackInfo.UpdateAttackInfo(AttackID.ChargedAttack, finalAttackForce,
                                                  movementInfo.GetLastMove().normalized, damageAmount);
            }

            //If button is still being held down
            if (Input.GetButton("AttackPS4") || Input.GetButton("Attack"))
            {
                //Increase damage that will be dealt here
                finalAttackForce += (Time.deltaTime * chargeMultiplier);
                break;
            }

            break;

        case ChargeAttackState.Attacking:

            //Play animation
            animator.Play("Charged Attack");

            break;

        case ChargeAttackState.Cooldown:
            timer -= Time.deltaTime;

            if (timer <= 0f)
            {
                //Reset stuff
                timer             = 0f;
                chargeAttackState = ChargeAttackState.Setup;
                playerState       = PlayerState.Default;
            }

            break;
        }
    }
コード例 #4
0
    public void SprintAttack(ref PlayerState playerState, Vector3 attackDirection)
    {
        switch (attackState)
        {
        case AttackState.Setup:
            //modify sprint bool so that we can change the animation
            //playerSprinting = false;
            //playerSprAttacking = true;
            attackState     = AttackState.SprintAttacking;
            attackTimer     = sprintAttackTime;
            startPosition   = transform.position;
            currentLerpTime = 0f;
            Debug.Log("SPRINT ATTACK!");

            playerFaceDirection = DirectionHandler.GetDirectionFromVector(movementInfo.GetLastMove());
            ActivateCorrespondingCollider(playerFaceDirection);
            playerAttackInfo.UpdateAttackInfo(AttackID.SprintAttack, baseAttackForce,
                                              movementInfo.GetLastMove().normalized, damageAmount);
            playerAnimator.Play("Sprint Attack");
            break;

        case AttackState.SprintAttacking:
            //This state is when the player was sprinting and attacked
            attackTimer -= Time.deltaTime;

            //move towards attack direction
            playerBody.velocity = Vector2.zero;             //Stop player from moving while attacking

            currentLerpTime += Time.deltaTime;
            if (currentLerpTime > sprintAttackTime)
            {
                currentLerpTime = sprintAttackTime;
            }

            float t = currentLerpTime / sprintAttackTime;
            t = Mathf.Sin(t * Mathf.PI * 0.5f);
            transform.position = Vector2.Lerp(startPosition, attackDirection, t);

            if (attackTimer <= 0f)
            {
                attackState = AttackState.SprintAttackCooldown;

                //Disable colliders
                DeactivateCorrespondingCollider(playerFaceDirection);

                //Cooldown time for dash attack
                attackTimer = sprintAttackCooldownTime;
            }

            break;

        case AttackState.SprintAttackCooldown:
            attackTimer -= Time.deltaTime;

            if (attackTimer <= 0f)
            {
                //Reset stuff
                attackTimer = 0f;
                attackState = AttackState.Setup;
                playerState = PlayerState.Default;
                //playerSprAttacking = false;
            }
            break;

        case AttackState.Done:
            attackState = AttackState.Setup;
            playerState = PlayerState.Default;
            break;
        }
    }
コード例 #5
0
    //Performs the attack ability
    //  @playerState: the state of the player is needed so we can change it to Attacking state
    //  @playerAttacking: the bool is needed so that we can let the animator know when an attack is happening
    //  @attackDirection: the vector that contains which direction the attack is happening at so we can set the
    //                    appropriate animation and collider
    public void Attack(ref PlayerState playerState, Vector3 attackDirection)
    {
        switch (attackState)
        {
        case AttackState.Ready:
            //Setup attack
            attackState = AttackState.Attacking;
            timer       = inputBufferTime;
            //Increase combo counter
            comboCount++;     //Use combo count to let animator know which attack is being performed
            playerAnimator.SetInteger("ComboCount", comboCount);

            if (comboCount == 1)
            {
                lastAttackDirection = attackDirection;
            }

            //Decide which animation to play
            switch (comboCount)
            {
            case 1:
                playerAnimator.Play("Attack 1");
                break;

            case 2:
                playerAnimator.Play("Attack 2");
                break;

            case 3:
                playerAnimator.Play("Attack 1");
                break;

            case 4:
                playerAnimator.Play("Attack 2");
                break;
            }

            //Determine which which collider to enable
            //playerFaceDirection = orientationSystem.GetDirection(CreateAttackVector());
            Debug.Log(CreateAttackVector());
            playerFaceDirection = DirectionHandler.GetDirectionFromVector(CreateAttackVector());
            ActivateCorrespondingCollider(playerFaceDirection);
            playerAttacking = true;

            //Set up to check if charged attack will be performed
            //Charge attack happens if attack button is held down while performing attack
            if (Input.GetButtonUp("AttackPS4") || Input.GetButtonUp("Attack"))
            {
                this.chargeAttack = false;
            }
            else
            {
                this.chargeAttack = true;
            }

            //Let the attack info container know what just happened
            playerAttackInfo.UpdateAttackInfo(AttackID.NormalAttack,
                                              baseAttackForce, movementInfo.GetLastMove().normalized, damageAmount);

            //Calculate where the attack will move the player
            targetPosition = new Vector3(transform.position.x + lastAttackDirection.x * 10f,
                                         transform.position.y + lastAttackDirection.y * 10f);

            break;


        case AttackState.Attacking:
            //This state is when the sword is swinging in the animation
            timer -= Time.deltaTime;

            if (Input.GetButtonUp("AttackPS4") || Input.GetButtonUp("Attack"))
            {
                this.chargeAttack = false;
            }

            //Check if user inputted attack while an attack is still happening (in buffer time window)
            if (!(timer <= 0f) && (Input.GetButtonDown("AttackPS4") || Input.GetButtonDown("Attack")) &&
                (comboCount != comboMax))
            {
                bufferInput = true;
            }

            //move towards click position
            playerBody.velocity = Vector2.zero;     //Stop player from moving while attacking
            transform.position  = Vector3.MoveTowards(transform.position, targetPosition, attackDistance * Time.deltaTime);

            //Animation Event will trigger exit out of this state
            break;


        case AttackState.Done:
            //NOTE: Will need to have the animation continue to play during this state. During this state, the sword is
            //      no longer swinging, but this state can be interrupted by another attack -> combo
            timer -= Time.deltaTime;

            //Check for charged attack
            if (Input.GetButtonUp("AttackPS4") || Input.GetButtonUp("Attack") || comboCount == comboMax)
            {
                this.chargeAttack = false;
            }

            //Inputs that can interrupt attack:
            //  Moving
            //  Attack -> Combo
            //If input is received within cooldown period (except when combo max reached), change states.
            if (((Input.GetButtonDown("AttackPS4") || Input.GetButtonDown("Attack")) &&
                 (comboCount != comboMax)) || bufferInput)
            {
                //Go to next attack -> Maybe create switch case here to assign different animations or attack times
                Debug.Log("Buffered Input");
                attackState = AttackState.Ready;
                bufferInput = false;
            }

            //If input not received, finish playing the cooldown animation and then transition into default state
            if (timer <= 0f)
            {
                //Reset stuff
                comboCount      = 0;
                timer           = 0f;
                playerAttacking = false;
                attackState     = AttackState.Ready;

                if (this.chargeAttack)
                {
                    playerState = PlayerState.ChargedAttacking;
                }
                else
                {
                    playerState = PlayerState.Default;
                }

                this.bufferInput  = false;
                this.chargeAttack = true;
            }

            //need some sort of bool/message that will let the animator know to keep playing cooldown animation/sprite

            break;
        }//switch
    }
コード例 #6
0
    //===========UNUSED================
    //May need it if I decide to implement bow and arrow
    //Makes the Player look towards a given point on the world map (like the mouse position)

    /*
     * public void LookTowardsPoint(Vector3 target) {
     *      //Rotate towards target
     *      target = target - transform.position;
     *
     *      float angle = Mathf.Atan2 (target.y, target.x) * Mathf.Rad2Deg;
     *
     *      //transform.rotation = Quaternion.Euler (new Vector3 (0, 0, angle));
     *      transform.rotation = Quaternion.AngleAxis(angle, Vector3.forward);
     *
     * }
     */

    //Handles and updates the Player logic with a state machine
    public void UpdatePlayer()
    {
        //Animator bools
        playerMoving          = false;
        playerDashing         = false;
        playerAttacking       = false;
        playerSprintAttacking = false;

        //Switch Design: Make each Ability class/state take in the playerState
        //  and modify it only when that Ablity action is done executing

        switch (playerState)
        {
        /*
         * case PlayerState.Default:
         *      if (controllerPref == ControllerPreference.KeyboardMouse)
         *              GetKeyboardInput ();
         *      else
         *              GetControllerInput ();
         *
         *      MovePlayer ();
         *      break;
         */

        case PlayerState.Default:
            basicMovement.Idle(ref playerState);
            anim.Play("Idle Direction");
            break;

        case PlayerState.Moving:
            basicMovement.Move(ref playerState);
            anim.Play("Player Movement");
            break;

        case PlayerState.Dashing:
            //Note: Normalize first Dash because Player may be accelerating or slowing down, causing shorter dashes
            dashAbility.Dash(basicMovement.GetLastMove().normalized, ref playerState, ref playerDashing);
            break;

        case PlayerState.Attacking:
            attackAbility.Attack(ref playerState, basicMovement.GetAttackDirection());
            break;

        case PlayerState.ChargedAttacking:
            chargedAttackAbility.ChargeAttack(ref playerState, basicMovement.GetAttackDirection());
            break;

        case PlayerState.SprintAttacking:
            sprintAttackAbility.SprintAttack(ref playerState, basicMovement.GetAttackDirection());
            break;

        case PlayerState.Shielding:
            shieldAbility.Shield(ref playerState);
            break;

        case PlayerState.Grabbing:
            grabAbility.Grab(ref playerState);
            break;

        case PlayerState.DodgeRolling:
            dodgeAbility.DodgeRoll(ref playerState, shieldAbility.GetDodgeRollDirection());
            break;

        case PlayerState.Flinch:
            flinchState.Flinch(ref playerState);
            break;

        case PlayerState.Falling:
            fallState.Fall(ref playerState);
            break;

        case PlayerState.Interacting:
            interactState.Interact(ref playerState);
            break;

        case PlayerState.Dialogue:
            dialogueState.Dialogue(ref playerState);
            break;

        case PlayerState.WarpStrike:
            warpStrikeAbility.WarpStrike(ref playerState, basicMovement.GetAttackDirection());
            break;

        case PlayerState.HyperDashing:
            //if (abilityHyperDash.hyperDashingActive)
            ////////attackDirection = GetMousePositionVector ();
            //abilityHyperDash.HyperDash (ref playerState, ref hyperDashCoolDownTimer, ref playerHyperDashing, attackDirection,
            //	                        moveHorizontal, moveVertical);
            break;
        }         //switch

        //Let the animator know what just happened in this frame (like which way the player was facing
        anim.SetFloat("MoveX", basicMovement.GetLastMove().x);
        anim.SetFloat("MoveY", basicMovement.GetLastMove().y);
        anim.SetBool("PlayerMoving", basicMovement.GetPlayerMoving());
        anim.SetFloat("LastMoveX", basicMovement.GetLastMove().x);
        anim.SetFloat("LastMoveY", basicMovement.GetLastMove().y);
        anim.SetBool("PlayerDashing", playerDashing);
        anim.SetBool("PlayerAttacking", attackAbility.GetPlayerAttacking());
        //anim.SetInteger ("PlayerAttackDirection", (int)playerDirections);
        //anim.SetBool ("PlayerSprinting", playerSprinting);

        //anim.SetInteger ("PlayerAttackDirection", (int)playerDirection);
    }