Esempio n. 1
0
    public void Attack()
    {
        Vector2 dirVect = new Vector2(Input.mousePosition.x - (x - C.getCameraInstance().x) * Futile.displayScale - Futile.screen.pixelWidth / 2f, Input.mousePosition.y - (this.y - C.getCameraInstance().y) * Futile.displayScale - Futile.screen.pixelHeight / 2f).normalized;
        Direction d = Direction.UP;
        if (Mathf.Abs(dirVect.x) > Mathf.Abs(dirVect.y))
        {
            if (dirVect.x < 0)
                d = Direction.LEFT;
            else
                d = Direction.RIGHT;
        }
        else if (dirVect.y < 0)
            d = Direction.DOWN;
        else
            d = Direction.UP;

        float dist = 30;
        Attack attack;
        Attack attack2;
        Attack attack3;
        Attack attack4;
        switch (currentAttack)
        {
            case AttackType.NORMAL:

                attack = new Attack(world, d);
                attack.SetDirection(d);
                attack.SetPosition(this.GetPosition() + dirVect * 5);
                Go.to(attack, .35f, new TweenConfig().floatProp("x", dirVect.x * dist, true).floatProp("y", dirVect.y * dist, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack); }));
                world.AddObject(attack);
                break;
            case AttackType.WIDE:

                attack = new Attack(world, d);
                attack.SetPosition(this.GetPosition() + dirVect * 5);
                float angle = Mathf.Atan2(dirVect.y, dirVect.x);
                dirVect.x = Mathf.Cos(angle - Mathf.PI / 7f);
                dirVect.y = Mathf.Sin(angle - Mathf.PI / 7f);
                Go.to(attack, .3f, new TweenConfig().floatProp("x", dirVect.x * dist, true).floatProp("y", dirVect.y * dist, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack); }));
                world.AddObject(attack);

                attack2 = new Attack(world, d);
                world.AddObject(attack2);
                Vector2 secondAttackDir = new Vector2(Mathf.Cos(angle + Mathf.PI / 7f), Mathf.Sin(angle + Mathf.PI / 7f));
                attack2.SetPosition(this.GetPosition() + secondAttackDir * 5);
                Go.to(attack2, .3f, new TweenConfig().floatProp("x", secondAttackDir.x * dist, true).floatProp("y", secondAttackDir.y * dist, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack2); }));

                break;
            case AttackType.WIDE_TWO:
                attack = new Attack(world, d);
                attack.SetPosition(this.GetPosition() + dirVect * 5);
                angle = Mathf.Atan2(dirVect.y, dirVect.x);
                dirVect.x = Mathf.Cos(angle - Mathf.PI / 10f);
                dirVect.y = Mathf.Sin(angle - Mathf.PI / 10f);
                Go.to(attack, .3f, new TweenConfig().floatProp("x", dirVect.x * dist * 1.5f, true).floatProp("y", dirVect.y * dist * 2f, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack); }));
                world.AddObject(attack);

                attack2 = new Attack(world, d);
                world.AddObject(attack2);
                secondAttackDir = new Vector2(Mathf.Cos(angle + Mathf.PI / 10f), Mathf.Sin(angle + Mathf.PI / 10f));
                attack2.SetPosition(this.GetPosition() + secondAttackDir * 5);
                Go.to(attack2, .3f, new TweenConfig().floatProp("x", secondAttackDir.x * dist * 1.5f, true).floatProp("y", secondAttackDir.y * dist * 2f, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack2); }));

                attack3 = new Attack(world, d);
                secondAttackDir = new Vector2(Mathf.Cos(angle - Mathf.PI / 4f), Mathf.Sin(angle - Mathf.PI / 4f));
                attack3.SetPosition(this.GetPosition() + secondAttackDir * 5);
                Go.to(attack3, .3f, new TweenConfig().floatProp("x", secondAttackDir.x * dist, true).floatProp("y", secondAttackDir.y * dist , true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack3); }));
                world.AddObject(attack3);

                attack4 = new Attack(world, d);
                world.AddObject(attack4);
                secondAttackDir = new Vector2(Mathf.Cos(angle + Mathf.PI / 4f), Mathf.Sin(angle + Mathf.PI / 4f));
                attack4.SetPosition(this.GetPosition() + secondAttackDir * 5);
                Go.to(attack4, .3f, new TweenConfig().floatProp("x", secondAttackDir.x * dist, true).floatProp("y", secondAttackDir.y * dist, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(attack4); }));

                break;
            case AttackType.WIDE_360:

                angle = Mathf.Atan2(dirVect.y, dirVect.x);
                for (int i = 0; i < 8; i++)
                {
                    Direction attackDir = Direction.UP;
                    if (Mathf.Abs(dirVect.x) > Mathf.Abs(dirVect.y))
                    {
                        if (dirVect.x < 0)
                            attackDir = Direction.LEFT;
                        else
                            attackDir = Direction.RIGHT;
                    }
                    else if (dirVect.y < 0)
                        attackDir = Direction.DOWN;
                    else
                        attackDir = Direction.UP;
                    Attack tempAttackWide = new Attack(world, attackDir);
                    Vector2 newDirVect = new Vector2(Mathf.Cos(angle), Mathf.Sin(angle));
                    tempAttackWide.SetPosition(this.GetPosition() + newDirVect * 5);
                    tempAttackWide.alpha = 0;
                    Go.to(tempAttackWide, (i + 1) * .03f, new TweenConfig().floatProp("alpha", 1).onComplete(() =>
                        {
                            Go.to(tempAttackWide, .3f, new TweenConfig().floatProp("x", newDirVect.x * dist, true).floatProp("y", newDirVect.y * dist, true).setEaseType(EaseType.QuadOut).onComplete(() => { world.RemoveObject(tempAttackWide); }));
                            world.AddObject(tempAttackWide);
                        }));
                    angle += Mathf.PI / 4;
                }

                break;
        }
    }