Beispiel #1
0
 // Update is called once per frame
 void Update()
 {
     for (int i = 0; i < EnemySpawnManager._instance.enemyList.Count; i++)
     {
         Enemy          enemy = (Enemy)EnemySpawnManager._instance.enemyList [i];
         QuadTextureAni ani   = enemy.GetTransform().GetComponentInChildren <QuadTextureAni> ();
         //enemy.SetPos (new Vector3 (enemy.GetPos ().x + 0.01f * Time.timeScale, enemy.GetPos ().y, enemy.GetPos ().z));
         if (enemy.GetPos().x < 15.45f)
         {
             //first path, walk down
             enemy.SetPos(new Vector3(enemy.GetPos().x + enemy.Speed * Time.timeScale, enemy.GetPos().y, enemy.GetPos().z));
         }
         else if (enemy.GetPos().x <= 19.8f && enemy.GetPos().x >= 15.45f && enemy.GetPos().z >= 18.6f && enemy.GetPos().z <= 25.6f)
         {
             //second path, walk left
             if (ani != null)
             {
                 ani.namePrefix = "walkright";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 if (enemy.characterType == CharacterData.CharacterModel.BOWMAN || enemy.characterType == CharacterData.CharacterModel.VIKING)
                 {
                     ani.mirror = true;
                 }
                 else
                 {
                     ani.mirror = false;
                 }
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x, enemy.GetPos().y, enemy.GetPos().z - enemy.Speed * Time.timeScale));
         }
         else if (enemy.GetPos().z > 18.2f && enemy.GetPos().z < 18.6f && enemy.GetPos().x >= 15.45f && enemy.GetPos().x <= 19.8f)
         {
             //third path, walk down
             if (ani != null)
             {
                 ani.namePrefix = "walkdown";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 ani.mirror = false;
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x + enemy.Speed * Time.timeScale, enemy.GetPos().y, enemy.GetPos().z));
         }
         else if (enemy.GetPos().x < 19.9f && enemy.GetPos().x > 19.8f && enemy.GetPos().z <= 23.5f)
         {
             //forth path, walk right
             if (ani != null)
             {
                 ani.namePrefix = "walkright";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 if (enemy.characterType == CharacterData.CharacterModel.BOWMAN || enemy.characterType == CharacterData.CharacterModel.VIKING)
                 {
                     ani.mirror = false;
                 }
                 else
                 {
                     ani.mirror = true;
                 }
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x, enemy.GetPos().y, enemy.GetPos().z + enemy.Speed * Time.timeScale));
         }
         else if (enemy.GetPos().z < 23.6f && enemy.GetPos().z >= 23.5f && enemy.GetPos().x > 19.8f && enemy.GetPos().x <= 22.3f)
         {
             //fifth path, walk down
             if (ani != null)
             {
                 ani.namePrefix = "walkdown";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 ani.mirror = false;
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x + enemy.Speed * Time.timeScale, enemy.GetPos().y, enemy.GetPos().z));
         }
         else if (enemy.GetPos().x < 22.6f && enemy.GetPos().x > 22.3f && enemy.GetPos().z <= 23.6f && enemy.GetPos().z >= 19.5f)
         {
             //sixth path,walk left
             if (ani != null)
             {
                 ani.namePrefix = "walkright";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 if (enemy.characterType == CharacterData.CharacterModel.BOWMAN || enemy.characterType == CharacterData.CharacterModel.VIKING)
                 {
                     ani.mirror = true;
                 }
                 else
                 {
                     ani.mirror = false;
                 }
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x, enemy.GetPos().y, enemy.GetPos().z - enemy.Speed * Time.timeScale));
         }
         else if (enemy.GetPos().x >= 22.3f && enemy.GetPos().z < 19.5f)
         {
             //seventh path,walk down
             if (ani != null)
             {
                 ani.namePrefix = "walkdown";
                 ani.mFPS       = 20;
                 ani.RebuildSpriteList();
                 ani.mirror = false;
             }
             enemy.SetPos(new Vector3(enemy.GetPos().x + enemy.Speed * Time.timeScale, enemy.GetPos().y, enemy.GetPos().z));
         }
         if (enemy.GetPos().x > 23.2f)
         {
             //show the escape effect
             //TODO
             AudioSource.PlayClipAtPoint(AudioManager._instance.escapeMusic, enemy.GetPos());
             effect11 = (GameObject)GameObject.Instantiate(Resources.Load("effect11"));
             effect11.transform.position = enemy.GetPos();
             //current life decrease 1
             //if life is less than 0, game over
             if (LifeManager._instance.GetLife() > 1)
             {
                 LifeManager._instance.SetLife(LifeManager._instance.GetLife() - 1);
             }
             else if (LifeManager._instance.GetLife() == 1)
             {
                 LifeManager._instance.SetLife(LifeManager._instance.GetLife() - 1);
                 GameManager.Instance.CurStatus = GameManager.Status.END_GAME;
             }
             EnemySpawnManager._instance.enemyList.Remove(enemy);
             enemy.Destroy();
             //last enemy will not affect the speed
             //enemy reach base, if the extra slow1 is active
             if (node.GetExtraSlow)
             {
                 if (EnemySpawnManager._instance.enemyList.Count != 0)
                 {
                     //set the variable
                     TowerBuildManager._instance.SetExtraSlowNum(0.8f);
                     isExtraSlow = true;
                     time        = 0;
                 }
                 else
                 {
                     TowerBuildManager._instance.SetExtraSlowNum(1.0f);
                     isExtraSlow = false;
                     time        = 0;
                 }
             }
         }
     }
     if (isExtraSlow)
     {
         time += Time.deltaTime;
         if (time >= timer)
         {
             TowerBuildManager._instance.SetExtraSlowNum(1.0f);
             isExtraSlow = false;
             time        = 0;
         }
     }
 }
Beispiel #2
0
    void ChangeAnim()
    {
        if (needChangeStatus == false)
        {
            return;
        }
        bool   needMirror = false;
        int    mfps       = 12;
        string namePrefix = "";
        bool   reverse    = false;

        if (rotateWeapon)
        {
            CancelInvoke("IdleChange");
        }
        if (mPose == Pose.Run)
        {
            namePrefix = "walk";
            if (mDir == Dir.RightDown)
            {
                namePrefix += "down";
            }
            else if (mDir == Dir.Right)
            {
                namePrefix += "right";
            }
            else if (mDir == Dir.RightUp)
            {
                namePrefix += "up";
            }
            else if (mDir == Dir.LeftDown)
            {
                namePrefix += "down";
                needMirror  = true;
            }
            else if (mDir == Dir.Left)
            {
                namePrefix += "right";
                needMirror  = true;
            }
            else if (mDir == Dir.LeftUp)
            {
                namePrefix += "up";
                needMirror  = true;
            }
        }
        else if (mPose == Pose.Idle)
        {
            if (rotateWeapon)
            {
                InvokeRepeating("IdleChange", 0f, 1.0f);
                mfps = 1;
            }
            else
            {
                namePrefix = "stand";
                if (mDir == Dir.RightDown)
                {
                    namePrefix += "down";
                }
                else if (mDir == Dir.Right)
                {
                    namePrefix += "right";
                }
                else if (mDir == Dir.RightUp)
                {
                    namePrefix += "up";
                }
                else if (mDir == Dir.LeftDown)
                {
                    namePrefix += "down";
                    needMirror  = true;
                }
                else if (mDir == Dir.Left)
                {
                    namePrefix += "right";
                    needMirror  = true;
                }
                else if (mDir == Dir.LeftUp)
                {
                    namePrefix += "up";
                    needMirror  = true;
                }
                mfps = 5;
            }
        }
        else if (mPose == Pose.Attack)
        {
            if (rotateWeapon)
            {
            }
            else
            {
                namePrefix = "attack";
                if (mDir == Dir.RightDown)
                {
                    namePrefix += "down";
                }
                else if (mDir == Dir.Right)
                {
                    namePrefix += "right";
                }
                else if (mDir == Dir.RightUp)
                {
                    namePrefix += "up";
                }
                else if (mDir == Dir.LeftDown)
                {
                    namePrefix += "down";
                    needMirror  = true;
                }
                else if (mDir == Dir.Left)
                {
                    namePrefix += "right";
                    needMirror  = true;
                }
                else if (mDir == Dir.LeftUp)
                {
                    namePrefix += "up";
                    needMirror  = true;
                }
                mfps = 6;
            }
        }
        else if (mPose == Pose.Summon)
        {
            namePrefix = "victory";
            if (mDir == Dir.RightDown)
            {
                namePrefix += "down";
            }
            else if (mDir == Dir.Right)
            {
                namePrefix += "right";
            }
            else if (mDir == Dir.RightUp)
            {
                namePrefix += "up";
            }
            else if (mDir == Dir.LeftDown)
            {
                namePrefix += "down";
                needMirror  = true;
            }
            else if (mDir == Dir.Left)
            {
                namePrefix += "right";
                needMirror  = true;
            }
            else if (mDir == Dir.LeftUp)
            {
                namePrefix += "up";
                needMirror  = true;
            }
            mfps = 6;
        }
        else if (mPose == Pose.Die)
        {
            namePrefix = "";
            QuadTextureAni ani1 = GetComponentInChildren <QuadTextureAni>();
            if (ani1 != null)
            {
                ani1.mActive = false;
            }
            transform.GetChild(0).localPosition = Vector3.zero;
            QuadTexture4Ngui tex = transform.GetChild(0).GetComponent <QuadTexture4Ngui>();
            tex.mSpriteName = "baseruins";
            tex.InitFace();
            transform.GetChild(0).gameObject.GetComponent <Renderer>().sortingOrder = -1;
            if (transform.childCount > 2)
            {
                transform.GetChild(2).gameObject.SetActive(false);
            }
        }
        QuadTextureAni ani = GetComponentInChildren <QuadTextureAni>();

        if (ani != null && namePrefix != "")
        {
            ani.namePrefix = namePrefix;
            ani.mFPS       = mfps;
            ani.RebuildSpriteList();
            ani.mirror = needMirror;
            if (mPose == Pose.Attack)
            {
                ani.OnNormalAniFinished += OnAttackEnd;
            }
        }
        needChangeStatus = false;
    }
    //change the animation
    void ChangeAnim()
    {
        if (needChangeStatus == false)
        {
            return;
        }
        bool   needMirror = false;
        int    mfps       = 12;
        string namePrefix = "";

//		bool reverse = false;
        if (mPose == Pose.Run)
        {
            namePrefix = "walk";
            if (mDir == Dir.RightDown)
            {
                namePrefix += "down";
            }
            else if (mDir == Dir.Right)
            {
                namePrefix += "right";
            }
            else if (mDir == Dir.RightUp)
            {
                namePrefix += "up";
            }

            else if (mDir == Dir.LeftDown)
            {
                namePrefix += "down";
                needMirror  = true;
            }
            else if (mDir == Dir.Left)
            {
                namePrefix += "left";
                needMirror  = true;
            }
            else if (mDir == Dir.LeftUp)
            {
                namePrefix += "up";
                needMirror  = true;
            }
        }
        else if (mPose == Pose.Idle)
        {
            //only the weapon have the animation idle
            //the enemy can only move
            if (rotateWeapon)
            {
            }
            else
            {
                return;
            }
        }
        else if (mPose == Pose.Attack)
        {
            //only the weapon can attack
            //the enemy can not attack
            if (rotateWeapon)
            {
            }
            else
            {
                return;
            }
        }
        else if (mPose == Pose.Die)
        {
            namePrefix = "Death00";
        }
        QuadTextureAni ani = GetComponentInChildren <QuadTextureAni> ();

        if (ani != null && string.IsNullOrEmpty(namePrefix))
        {
            ani.namePrefix = namePrefix;
            ani.mFPS       = mfps;
            ani.RebuildSpriteList();
            ani.mirror = needMirror;
            if (mPose == Pose.Attack)
            {
                //ani.OnNormalAnimFinished += OnAttackEnd;
            }
        }
        needChangeStatus = false;
    }