Esempio n. 1
0
    // Use this for initialization
    public void init(GameManager owner, int type)
    {
        bossType  = type;
        this.name = "Boss";
        m         = owner;

        if (bossType == 1)
        {
            speed           = m.bossSpeed;
            chargeSpeed     = m.bossSpeed * this.chargeMultiplier;
            this.bossHealth = 100;
            var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad);                   // Create a quad object for holding the gem texture.
            model1 = modelObject.AddComponent <BossModel> ();                                   // Add a marbleModel script to control visuals of the gem.
            model1.init(this);
            this.bossHit  = m.bossHit;
            this.bossHitX = m.bossHitX;
            this.bossDead = m.bossDead;
            BoxCollider2D bossbody  = gameObject.AddComponent <BoxCollider2D> ();
            Rigidbody2D   bossRbody = gameObject.AddComponent <Rigidbody2D> ();
            bossRbody.gravityScale = 0;
            bossbody.isTrigger     = true;
            transform.localScale   = new Vector3(2f, 2f, 1);
        }
        else if (bossType == 2)
        {
            speed           = 1.8f;
            this.speed      = m.bossSpeed;
            this.charge     = false;
            this.flicker    = false;
            chargeSpeed     = m.bossSpeed * this.chargeMultiplier;
            this.bossHealth = 100;
            var modelObject = GameObject.CreatePrimitive(PrimitiveType.Quad);                   // Create a quad object for holding the gem texture.
            model2 = modelObject.AddComponent <Boss2Model>();                                   // Add a marbleModel script to control visuals of the gem.
            model2.init(this);

            BoxCollider2D bossbody  = gameObject.AddComponent <BoxCollider2D> ();
            Rigidbody2D   bossRbody = gameObject.AddComponent <Rigidbody2D> ();
            bossRbody.gravityScale = 0;
            bossbody.isTrigger     = true;

            transform.localScale = new Vector3(3f, 3f, 1);

            GameObject shieldObject = new GameObject();
            BossShield shield       = shieldObject.AddComponent <BossShield>();
            shield.init(this);
            shield.transform.position = new Vector3(this.transform.position.x + 3.5f, this.transform.position.y + 2.7f, 0);

            shieldDead    = false;
            this.bossHit  = m.bossHit;
            this.bossHitX = m.bossHitX;
            this.bossDead = m.bossDead;
        }
    }
Esempio n. 2
0
    // Update is called once per frame
    void Update()
    {
        xpos    = transform.position.x;
        ypos    = transform.position.y;
        targetx = m.GetTargetX();
        targety = m.GetTargetY();

        if (bossType == 1)
        {
            if (!usingBlades)
            {
                if ((targety - this.transform.position.y) <= 0 && !charge)
                {
                    float angle = Mathf.Rad2Deg * Mathf.Acos(Mathf.Abs(targety - this.transform.position.y) / Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2)));
                    float sign  = (targetx - this.transform.position.x) / Mathf.Abs(targetx - this.transform.position.x);
                    transform.eulerAngles = new Vector3(0, 0, 180 + (sign * angle));
                }
                else if ((targety - this.transform.position.y) > 0 && !charge)
                {
                    float angle = Mathf.Rad2Deg * Mathf.Acos(Mathf.Abs(targety - this.transform.position.y) / Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2)));
                    float sign  = (targetx - this.transform.position.x) / Mathf.Abs(targetx - this.transform.position.x);
                    transform.eulerAngles = new Vector3(0, 0, 0 + (sign * angle * -1));
                }
                else
                {
                    transform.Translate(Vector3.up * chargeSpeed * Time.deltaTime);
                    charging = charging - Time.deltaTime;

                    if (charging <= 0)
                    {
                        charge = false;



                        chargecd = 1;
                    }
                }
            }

            if (!usingBlades)
            {
                if ((Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2))) >= 3.5f)
                {
                    slow = true;
                    int x = Random.Range(0, 550);
                    if (x == 0)
                    {
                        if (bossHealth >= 50)
                        {
                            if (chargecd <= 0)
                            {
                                if (!charge)
                                {
                                    charge   = true;
                                    charging = 1.3f;
                                }
                            }
                        }
                        else
                        {
                            if (swirlCooldown <= 0)
                            {
                                swirling   = true;
                                swirlangle = 0;
                            }
                        }
                    }
                    if (swirling && bulletCooldown <= 0)
                    {
                        FireSwirl(swirlangle);
                        swirlangle     = swirlangle + 10;
                        bulletCooldown = .05f;
                        if (swirlangle == 360)
                        {
                            swirling      = false;
                            swirlCooldown = 1;
                        }
                    }
                    else if ((Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2))) >= 5.5f && !swirling)
                    {
                        slow = false;
                        if (beamCooldown <= 0)
                        {
                            FireBeam();
                            beamCooldown = 1;
                        }
                        beamCooldown = beamCooldown - Time.deltaTime;
                    }
                    else if (bulletCooldown <= 0)
                    {
                        FireBullet();
                        bulletCooldown = .6f;
                    }
                    else
                    {
                        chargecd       = chargecd - Time.deltaTime;
                        bulletCooldown = bulletCooldown - Time.deltaTime;
                        swirlCooldown  = swirlCooldown - Time.deltaTime;
                    }
                }
                else if ((Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2))) < 3.5f)
                {
                    if (bladeCooldown <= 0)
                    {
                        SpawnBlades();
                        usingBlades   = true;
                        bladeDuration = 1f;
                        bladeCooldown = 1.5f;
                    }
                    else if (!usingBlades)
                    {
                        bladeCooldown = bladeCooldown - Time.deltaTime;
                    }
                }
            }

            if (usingBlades)
            {
                bladeDuration = bladeDuration - Time.deltaTime;

                if (bladeDuration <= 0)
                {
                    usingBlades = false;
                    blade.Retract();
                }
            }

            if (this.bossHealth <= 0)
            {
                //Destroy (this.gameObject);
                if (this.bossType == 1)
                {
                    m.PlayEffect(bossDead);
                }
            }
        }
        else if (bossType == 2)
        {
            if ((targety - this.transform.position.y) <= 0 && !charge)
            {
                float angle = Mathf.Rad2Deg * Mathf.Acos(Mathf.Abs(targety - this.transform.position.y) / Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2)));
                float sign  = (targetx - this.transform.position.x) / Mathf.Abs(targetx - this.transform.position.x);
                transform.eulerAngles = new Vector3(0, 0, 180 + (sign * angle));
            }
            else if ((targety - this.transform.position.y) > 0 && !charge)
            {
                float angle = Mathf.Rad2Deg * Mathf.Acos(Mathf.Abs(targety - this.transform.position.y) / Mathf.Sqrt(Mathf.Pow((targetx - this.transform.position.x), 2) + Mathf.Pow((targety - this.transform.position.y), 2)));
                float sign  = (targetx - this.transform.position.x) / Mathf.Abs(targetx - this.transform.position.x);
                transform.eulerAngles = new Vector3(0, 0, 0 + (sign * angle * -1));
            }
            if (shieldDead)
            {
                shieldcharge = shieldcharge - Time.deltaTime;
                if (shieldcharge <= 0)
                {
                    shieldDead = false;
                    GameObject shieldObject = new GameObject();
                    BossShield shield       = shieldObject.AddComponent <BossShield>();
                    shield.init(this);
                    shield.transform.position = new Vector3(this.transform.position.x - .5f, this.transform.position.y + .5f, 0);
                }
            }
            else
            {
                int x = Random.Range(0, 7);
                if (!charge)
                {
                    if (attackCD <= 0)
                    {
                        attackCD = 1.5f;
                        if (x < 5)
                        {
                            FireTracer();
                        }
                        else
                        {
                            charge = true;
                            StartCoroutine(flickerRoutine());
                            this.m.PlayEffect(this.m.charging);
                            recharging = 1.5f;
                        }
                    }
                }
                else
                {
                    recharging = recharging - Time.deltaTime;
                    if (recharging <= 0)
                    {
                        charge = false;
                        StopCoroutine(flickerRoutine());
                        this.model2.mat.mainTexture = Resources.Load <Texture2D>("Textures/boss2d0");
                        if (x < 3)
                        {
                            FireAOE();
                        }
                        else
                        {
                            FireBurst();
                        }
                    }
                }

                attackCD = attackCD - Time.deltaTime;
            }
        }
    }