コード例 #1
0
ファイル: tBoss.cs プロジェクト: dearlux/PowerOfNumbers
        // Use this for initialization
        public void init(tGameController 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 <tBossModel> ();                              // Add a marbleModel script to control visuals of the gem.
                model1.init(this);
                float z = transform.position.z;
                transform.position = new Vector3(-4f, 0f, z);
                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 <tBoss2Model>();                              // 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();
                tBossShield shield       = shieldObject.AddComponent <tBossShield>();
                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;
            }
        }
コード例 #2
0
        public void init(tBossShield owner)
        {
            this.owner = owner;

            transform.parent        = owner.transform;                  // Set the model's parent to the gem.
            transform.localPosition = new Vector3(0, 0, 0);             // Center the model on the parent.
            name = "Boss Model";                                        // Name the object.

            mat             = GetComponent <Renderer>().material;
            mat.shader      = Shader.Find("Sprites/Default");                           // Tell the renderer that our textures have transparency. // Get the material component of this quad object.
            mat.mainTexture = Resources.Load <Texture2D>("Textures/Boss2shield");       // Set the texture.  Must be in Resources folder.
        }
コード例 #3
0
ファイル: tBoss.cs プロジェクト: dearlux/PowerOfNumbers
        // Update is called once per frame
        void Update()
        {
//		if (this.m.currentplayer.playerType != 0 ) {
//			if (this.bossHealth <= 10) {
//				this.m.currentplayer.timeIndex = 1;
//
//			//	this.m.currentplayer.initDead (this.m.currentplayer.model.transform.position.x, this.m.currentplayer.model.transform.position.y, 4);
//			}
//		}
            float z = this.transform.position.z;

            this.transform.position = new Vector3(-4, 0, z);
            xpos    = transform.position.x;
            ypos    = transform.position.y;
            targetx = m.GetTargetX();
            targety = m.GetTargetY();
            if (this.m.playerOrderIndex > 2)
            {
                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();
                        tBossShield shield       = shieldObject.AddComponent <tBossShield>();
                        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, 5);
                    if (!charge)
                    {
                        if (attackCD <= 0)
                        {
                            attackCD = 2f;
                            if (x < 4)
                            {
                                FireTracer();
                            }
                            else
                            {
                                charge = true;
                                StartCoroutine(flickerRoutine());
                                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 < 2)
                            {
                                FireAOE();
                            }
                            else
                            {
                                FireBurst();
                            }
                        }
                    }

                    attackCD = attackCD - Time.deltaTime;
                }
            }
        }