private void EnableAttackCollider()
    {
        //See which way we're facing
        FourDirections dir = dirHandler.GetDirectionFromVector(lastMove);

        switch (dir)
        {
        case FourDirections.North:
            this.attackUp.EnableAttackCollider();
            break;

        case FourDirections.East:
            this.attackRight.EnableAttackCollider();
            break;

        case FourDirections.South:
            this.attackDown.EnableAttackCollider();
            break;

        case FourDirections.West:
            this.attackLeft.EnableAttackCollider();
            break;
        }
    }
Exemple #2
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;
        }
    }
    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;
        }
    }
Exemple #4
0
 public FourDirections GetFaceDirectionIn4DirSystem()
 {
     return(DirectionSystem.GetDirectionFromVector(this.lastMove));
 }
    //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
    }