Example #1
0
    //Called by opponent on hit
    public void ApplyDamage(float dmgreceived)
    {
        print(gameObject.name + " got hit");

        if (stun == eStun.blocking)
        {
            //CVoice.PlayVoiceSound();
            CVoice.PlayImpactSound();
            StartCoroutine(camShake.Shake(0.15f, 0.4f));
            hitPoints -= dmgreceived;
            GameManager.instance.UpdateHP();
        }
        else if (stun == eStun.blockbroken)
        {
            state = ePlayerState.Hurt;
            //anim.SetBool("knockdown", true);        //TODO implement knockdown anim
            CVoice.PlayLongCrySound();
            StartCoroutine(camShake.Shake(0.15f, 0.4f));
            hitPoints -= dmgreceived;
            GameManager.instance.UpdateHP();
        }
        else if (stun == eStun.jumped)
        {
            state = ePlayerState.Hurt;
            anim.SetTrigger("longhurt");
            CVoice.PlayVoiceSound();
            StartCoroutine(camShake.Shake(0.15f, 0.4f));
            hitPoints -= dmgreceived;
            GameManager.instance.UpdateHP();
        }
        else if (stun == eStun.normal)
        {
            state = ePlayerState.Hurt;
            anim.SetTrigger("hurt");
            CVoice.PlayVoiceSound();
            StartCoroutine(camShake.Shake(0.15f, 0.4f));
            hitPoints -= dmgreceived;
            GameManager.instance.UpdateHP();
        }

        print(gameObject.name + "s HP: " + hitPoints);
        stun = eStun.normal;
    }
Example #2
0
    public void Update()
    {
        anim.SetBool("grounded", grounded);

        switch (GameManager.instance.GameMode)
        {
        case eGameMode.Running:

            horizontal = Input.GetAxis("Horizontal_" + PlayerIndex);
            vertical   = Input.GetAxis("Vertical_" + PlayerIndex);

            if (Input.GetButtonDown("Reset_" + PlayerIndex))
            {
                print("resetting");
                state = ePlayerState.Ready;
            }

            if (hitPoints <= 0)
            {
                print(name + " is dead");
            }

            #region Playerstate switch
            switch (state)
            {
            case ePlayerState.Ready:

                attack1 = false;
                attack2 = false;

                attack = eAttacks.None;
                anim.SetBool("blocking", false);

                Move();

                Flip();

                if (Input.GetButtonDown("Attack1_" + PlayerIndex))
                {
                    //print("Attack1");
                    state  = ePlayerState.Attacking;
                    attack = eAttacks.Light;
                    anim.SetTrigger("attack1");
                    hitCheck = true;
                    CVoice.PlayAttack1Sound();
                    //StartCoroutine(Attack1());
                }

                if (Input.GetButtonDown("Attack2_" + PlayerIndex))
                {
                    //print("Attack2");
                    state  = ePlayerState.Attacking;
                    attack = eAttacks.Heavy;
                    anim.SetTrigger("attack2");
                    hitCheck = true;
                    CVoice.PlayAttack2Sound();
                    //StartCoroutine(Attack2());
                }

                if (Input.GetButtonDown("Breaker_" + PlayerIndex))
                {
                    print("Blockbreaker");
                    state  = ePlayerState.Attacking;
                    attack = eAttacks.Blockbreak;
                    anim.SetTrigger("blockbreak");
                    blockbreak = true;
                    hitCheck   = true;
                    CVoice.PlayBlockBreakSound();
                    //Blockbreaking Move
                }

                if (Input.GetButton("Block_" + PlayerIndex) && grounded)
                {
                    print("block");
                    state = ePlayerState.Blocking;
                    //break; //for while loop
                }

                if (vertical == -1f && grounded)
                {
                    state = ePlayerState.JumpTakeOff;
                    CVoice.PlayTakeOffSound(transform.position);         //HACK jump sound
                    anim.SetBool("walkbackwards", false);
                    anim.SetBool("walkforwards", false);
                    anim.SetBool("startup", true);
                }

                break;

            case ePlayerState.Attacking:
                anim.SetBool("walkbackwards", false);
                anim.SetBool("walkforwards", false);
                break;

            case ePlayerState.JumpTakeOff:
                break;

            case ePlayerState.InAir:
                Move();
                Flip();

                if (rigid.velocity.y > 0f && !grounded && !anim.GetBool("jumping"))
                {
                    anim.SetBool("jumping", true);
                }
                else if (rigid.velocity.y <= 0f && !grounded)
                {
                    anim.SetBool("jumping", false);
                    anim.SetBool("falling", true);
                    rigid.velocity += Vector2.up * Physics.gravity * extraGravity * Time.deltaTime;
                }
                else if (grounded && anim.GetBool("falling"))
                {
                    anim.SetBool("falling", false);
                    anim.SetTrigger("land");
                    CVoice.PlayLandSound();
                }

                if (Input.GetButtonDown("Attack1_" + PlayerIndex) && transform.position.y >= jumpAttack)
                {
                    state  = ePlayerState.InAirAttack;
                    attack = eAttacks.Jump;
                    anim.SetTrigger("jumpattack");
                    CVoice.PlayAttack1Sound();
                    hitCheck = true;
                }

                break;

            case ePlayerState.InAirAttack:
                Move();

                break;

            case ePlayerState.DiveAttack:

                if (rigid.velocity.y <= 0f && !grounded)
                {
                    anim.SetBool("jumping", false);
                    anim.SetBool("jumpattack", true);
                    rigid.velocity += Vector2.up * Physics.gravity * airAttackGravity * Time.deltaTime;

                    //45° angle in face direction downwards
                    if (!facingRight)
                    {
                        rigid.AddForce(new Vector2(-1, -1) * Time.deltaTime);
                    }
                    else if (facingRight)
                    {
                        rigid.AddForce(new Vector2(1, -1) * Time.deltaTime);
                    }
                }
                else if (grounded && anim.GetBool("jumpattack"))
                {
                    GetAttackValues();
                    anim.SetTrigger("land");
                    anim.SetBool("jumpattack", false);
                    state = ePlayerState.Ready;
                }

                break;

            case ePlayerState.Blocking:

                anim.SetBool("walkbackwards", false);
                anim.SetBool("walkforwards", false);
                anim.SetBool("blocking", true);
                stun = eStun.blocking;

                if (Input.GetButtonUp("Block_" + PlayerIndex))
                {
                    state = ePlayerState.Ready;
                    stun  = eStun.normal;
                }
                //if (vertical < 0.95f && vertical >= 0f)
                //{
                //    print("not blocking");
                //    anim.SetBool("blocking", false);
                //    state = ePlayerState.Ready;
                //}
                break;

            case ePlayerState.Hurt:
                //HurtTimer();
                break;

            case ePlayerState.Dead:
                //play dying animation
                //when finished, set bool for gamemanager matchover
                break;

            default:
                break;
            }
            #endregion

            break;
        }
    }