//Additional changes done in enemyhp when the enemy is frozen
    IEnumerator FreezeEnemy()
    {
        Icecycle.SetActive(true);
        if (emc != null)
        {
            emc.StopMovement();
        }
        if (ai != null)
        {
            ai.ChangeStatus(EnemyBehaviorStatus.Frozen);
            ai.anim.Play("Death");
            ai.anim.speed = 0;
        }
        yield return(new WaitForSeconds(PlayerDamageValues.Instance.FrostTimeToMelt));

        Icecycle.SetActive(false);
        if (emc != null)
        {
            emc.ResumeMovement();
        }
        if (ai != null)
        {
            ai.ChangeStatus(EnemyBehaviorStatus.Waiting);
            ai.anim.speed = 1;
            ai.anim.Play("Idle");
        }
        ChangeCondition(EnemyConditions.Normal);
    }
    //in this future this will probably need to be a coroutine, becuase it might take a few seconds to change status and update animation
    //and once that is complete, start up whatever the next status is.
    public void UpdateEnemyBehaviorStatus()
    {
        anim.SetBool("TempSurround", false);
        switch (CurrentStatus)
        {
        case EnemyBehaviorStatus.PrimaryAttacker:
            GetEnemyMovementCtrl.ResumeMovement();
            break;

        case EnemyBehaviorStatus.ArcRunner:
            GetEnemyMovementCtrl.ResumeMovement();
            TravelAlongArc();
            break;

        case EnemyBehaviorStatus.SurroundPlayer:
            KeepDistance();
            break;

        case EnemyBehaviorStatus.Waiting:
            GetEnemyMovementCtrl.StopMovement();
            break;

        case EnemyBehaviorStatus.Attacking:
            break;

        case EnemyBehaviorStatus.Busy:
            break;

        case EnemyBehaviorStatus.Sleeping:
            GetEnemyMovementCtrl.StopMovement();
            break;

        case EnemyBehaviorStatus.Staggered:
            GetEnemyMovementCtrl.StopMovement();
            break;

        case EnemyBehaviorStatus.BeingFinished:
            GetEnemyMovementCtrl.StopMovement();
            break;

        default:
            GetEnemyMovementCtrl.StopMovement();
            break;
        }
    }
Example #3
0
    //Leap Attack for a knight
    IEnumerator PerformSpecial1Attack()
    {
        MovementCtrl.StopMovement();
        MovementCtrl.SetLockToGround(false);
        AI.ChangeStatus(EnemyBehaviorStatus.Attacking);
        AI.ChangeAction(EnemyActions.Special1);
        sword.damage = PlayerDamageValues.Instance.JumpAttackDamage;
        //set animation
        //attack()
        //Animation
        //AI.anim.applyRootMotion = true;

        AI.anim.Play("JumpAttack");

        //AI.anim.transform.localEulerAngles = new Vector3(0, 0, 0);

        GetComponent <EnemyMovementController>().DisableNavAgent();

        // Calculate distance to target
        float target_Distance = Vector3.Distance(transform.position, playerT.position);

        // Calculate the velocity needed to throw the object to the target at specified angle.
        float projectile_Velocity = target_Distance / (Mathf.Sin(2 * firingAngle * Mathf.Deg2Rad) / gravity);

        // Extract the X  Y componenent of the velocity
        float Vx = Mathf.Sqrt(projectile_Velocity) * Mathf.Cos(firingAngle * Mathf.Deg2Rad);
        float Vy = Mathf.Sqrt(projectile_Velocity) * Mathf.Sin(firingAngle * Mathf.Deg2Rad);

        // Calculate flight time.
        float flightDuration = target_Distance / Vx;

        // Rotate projectile to face the target.
        transform.rotation = Quaternion.LookRotation(playerT.position - transform.position);

        float elapse_time = 0;

        GetComponent <CapsuleCollider>().isTrigger = true;

        bool interupted = false;

        while (elapse_time < flightDuration)
        {
            transform.Translate(0, (Vy - (gravity * elapse_time)) * Time.deltaTime, Vx * .8f * Time.deltaTime);

            elapse_time += Time.deltaTime;

            if (AI.GetDirector().IsInterupted(AI.GetCurrentStatus()))
            {
                interupted = true;
                break;
            }

            yield return(null);
        }

        yield return(new WaitForSeconds(.2f));

        GetComponent <CapsuleCollider>().isTrigger = false;

        GetComponent <EnemyMovementController>().EnableNavAgent();
        AI.GetDirector().Special1AttackCompleted();

        AI.ChangeAction(EnemyActions.None);

        MovementCtrl.SetLockToGround(true);

        if (!interupted)
        {
            AI.anim.Play("Idle");
            AI.ChangeStatus(EnemyBehaviorStatus.Waiting);
        }
    }
Example #4
0
    private void OnTriggerEnter2D(Collider2D collision)
    {
        if (collision.gameObject.layer == 12)
        {
            //Debug.Log("Enemy collided with barrier");
            DestroyEnemy();
        }

        if (collision.gameObject.layer == 15 && gameObject.layer == 19)
        {
            gameObject.GetComponent <SkeletonAnimation>().AnimationName = "Attack";
        }


        if (collision.gameObject.layer == 9 && gameObject.layer == 19 && !isHit)
        {
            //Debug.Log("Player Got hit");
            player.GetComponent <PlayerStateController>().subtractHP(20);
            HPBar.GetComponent <Image>().fillAmount = (float)player.GetComponent <PlayerStateController>().currentHP / player.GetComponent <PlayerStateController>().MaxHP;
        }
        else if (collision.gameObject.layer == 9 && !isHit)
        {
            //Debug.Log("Player Got hit by obstacle");
            player.GetComponent <PlayerStateController>().subtractHP(10);
            HPBar.GetComponent <Image>().fillAmount = (float)player.GetComponent <PlayerStateController>().currentHP / player.GetComponent <PlayerStateController>().MaxHP;
        }

        else if (collision.gameObject.layer == 16 && !isHit && (gameObject.layer != 19))
        {
            if (collision.gameObject.name == "BottomMissBox")
            {
                ScoreUIManager.instance.ScoreHit(1, transform.position);
                player.GetComponent <PlayerStateController>().subtractHP(5);
                HPBar.GetComponent <Image>().fillAmount = (float)player.GetComponent <PlayerStateController>().currentHP / player.GetComponent <PlayerStateController>().MaxHP;
            }
            else if (collision.gameObject.name == "TopMissBox" && !isHit)
            {
                ScoreUIManager.instance.ScoreHit(1, transform.position);
                player.GetComponent <PlayerStateController>().subtractHP(5);
                HPBar.GetComponent <Image>().fillAmount = (float)player.GetComponent <PlayerStateController>().currentHP / player.GetComponent <PlayerStateController>().MaxHP;
            }
            else if (collision.gameObject.layer == 12)
            {
                DestroyEnemy();
            }
        }


        if (collision.gameObject.layer == 13 && player.GetComponent <WeaponControls>().Attacking&& !isHit)
        {
            if (gameObject.layer == 19)
            {
                gameObject.GetComponent <SkeletonAnimation>().AnimationName = "Attack";
            }
            else
            {
                GetComponent <Collider2D>().enabled = false;
                //Debug.Log("is hit");
                isHit = true;
                PlayDeathDeathEffect();
                enemyMovement.StopMovement();
                animation.AnimationName = "Dead";

                rigid.bodyType     = RigidbodyType2D.Dynamic;
                rigid.mass         = 1f;
                rigid.gravityScale = 10;
                transform.parent   = null;
                //rigid.AddForce(new Vector2(-5, 20), (ForceMode2D)ForceMode.VelocityChange);
                rigid.AddTorque(13);
                rigid.velocity = new Vector2(-15, 35);

                Vector3 distance = new Vector3(
                    this.transform.position.x - Hitbox.transform.position.x,
                    this.transform.position.y - Hitbox.transform.position.y,
                    this.transform.position.z - Hitbox.transform.position.z);


                double distanceX = Math.Abs(distance.x);
                //Debug.Log(distanceX);
                if (distanceX >= 1.25) //ok
                {
                    Invoke("Obliterate", .1f);
                    ScoreUIManager.instance.ScoreHit(2, transform.position);
                }
                else if (distanceX > .75 && distanceX <= 1.25) //good
                {
                    Invoke("Obliterate", .1f);
                    ScoreUIManager.instance.ScoreHit(3, transform.position);
                }
                else if (distanceX <= .75) //perfect
                {
                    Invoke("Obliterate", .1f);
                    ScoreUIManager.instance.ScoreHit(4, transform.position);
                }



                player.GetComponent <PlayerStateController>().addHP(5);
                //Debug.Log("healed");
                HPBar.GetComponent <Image>().fillAmount = (float)player.GetComponent <PlayerStateController>().currentHP / player.GetComponent <PlayerStateController>().MaxHP;
            }
        }
    }