コード例 #1
0
        void Attack(AttackProfile attackProfile)
        {
            Vector2 attackVector = Vector2.zero;

            if (!isInRecover && !isInBuildup && !isInRoll && !isCrouching && !isPushingObject && !isFlashing)
            {
                ennemiesHitLastTime.Clear();

                switch (dirAngle)
                {
                case DirectionAngle.North:
                    attackVector = Vector2.up;
                    break;

                case DirectionAngle.West:
                    attackVector = Vector2.left;
                    break;

                case DirectionAngle.Est:
                    attackVector = Vector2.right;
                    break;

                case DirectionAngle.South:
                    attackVector = Vector2.down;
                    break;
                }
                isInBuildup             = true;
                attackProfile.atkVector = attackVector;
                StartCoroutine(Buildup(attackProfile));

                Debug.Log(attackProfile.atkName);
            }
        }
コード例 #2
0
        IEnumerator Buildup(AttackProfile attackProfile)
        {
            yield return(new WaitForSeconds(attackProfile.atkBuildup));

            isInBuildup = false;
            isInRecover = true;
            StartCoroutine(Hit(attackProfile));
        }
コード例 #3
0
        IEnumerator Hit(AttackProfile attackProfile)
        {
            Collider2D[] hitEnnemies = Physics2D.OverlapCircleAll(transform.position, attackProfile.atkZone.x, ennemies);
            Collider2D[] hitObjects  = Physics2D.OverlapCircleAll(transform.position, attackProfile.atkZone.x, breakableObjects);

            if (!ennemyWasHitOnce)
            {
                foreach (Collider2D ennemy in hitEnnemies)
                {
                    if (!ennemiesHitLastTime.Contains(ennemy))
                    {
                        Debug.Log(ennemy.bounds.extents.magnitude);
                        Vector2 ennemyDirection = ennemy.transform.position - transform.position;
                        float   ennemyAngle     = Vector2.Angle(attackProfile.atkVector, ennemyDirection);
                        float   a = ennemyDirection.magnitude;
                        float   b = ennemyDirection.magnitude;
                        float   c = ennemy.bounds.extents.x * 2;
                        float   additionalAngle = Mathf.Rad2Deg * Mathf.Acos(((a * a) + (b * b) - (c * c)) / (2 * (a * b)));
                        float   totalAngle      = attackProfile.atkZone.y + additionalAngle;
                        //Debug.Log("Additional Angle = " + additionalAngle + " / AA+AtkAngle = " + totalAngle + " / Ennemy Angle = " + ennemyAngle);
                        if (ennemyAngle <= totalAngle)
                        {
                            if (ennemy.GetComponent <JUB_EnnemyDamage>())
                            {
                                ennemy.GetComponent <JUB_EnnemyDamage>().TakeDamage(attackProfile.atkDamage);
                                Debug.Log("attack was performed");
                                ennemiesHitLastTime.Add(ennemy);
                            }
                        }
                    }
                }
            }

            foreach (Collider2D breakableObject in hitObjects)
            {
                breakableObject.GetComponent <JUB_BreakableBehavior>().Breaking();
            }

            yield return(new WaitForSeconds(attackProfile.atkRecover));

            isInRecover = false;
        }
コード例 #4
0
        // Start is called before the first frame update
        void Start()
        {
            rigidBody  = GetComponent <Rigidbody2D>();
            controller = new Controller();
            controller.Enable();
            displayBonbons.text = currentBonbons.ToString();

            AttackProfile quickAttack = new AttackProfile(1, new Vector2(1, 1), 0.1f, 0.2f, "quick");
            AttackProfile heavyAttack = new AttackProfile(3, new Vector2(2, 1), 0, 0.8f, "heavy");

            currentLife = maxLife;

            controller.MainController.Roll.performed     += ctx => Roll();
            controller.MainController.Crouch.performed   += ctx => Crouch();
            controller.MainController.Push.performed     += ctx => PushObjects();
            controller.MainController.Interact.performed += ctx => Interact();
            //controller.MainController.Crouch.performed += ctx => isCrouching = !isCrouching;
            controller.MainController.Attack.performed      += ctx => Attack(quickAttack);// Attack();
            controller.MainController.HeavyAttack.performed += ctx => Attack(heavyAttack);
        }