private void Log(int index, string debug)
 {
     if (this.index == index)
     {
         GGDebug.Log(debug);
     }
 }
Esempio n. 2
0
    //零散墙
    public void CreateSingleWall()
    {
        //1.确定生成的数目
        int num = this.GetRateNum(wallNum, wallNumRate);

        //2.确定位置
        if (num == 0)
        {
            GGDebug.Log("==================零散墙===================");
        }
        else if (num == 1)
        {
            int posIndex = Random.Range(1, 6);
            WallUnitController script = WallUnitController.Create();
            this.AddWallUnit(script.gameObject, this.GetWallPos(fWallPosX[posIndex - 1]));
            GGDebug.Log("==================零散墙===================");
        }
        else if (num == 2)
        {
            int posIndex1 = Random.Range(1, 6);
            int posIndex2 = this.GetDontSideNum(posIndex1);

            WallUnitController script = WallUnitController.Create();
            this.AddWallUnit(script.gameObject, this.GetWallPos(fWallPosX[posIndex1 - 1]));

            script = WallUnitController.Create();
            this.AddWallUnit(script.gameObject, this.GetWallPos(fWallPosX[posIndex2 - 1]));
            GGDebug.Log("==================零散墙===================");
        }

        this.curCreateWallIndex++;
        this.loopIndexNum++;
        this.curHorizontalType = Global.WallHorizontalType.FRANCE;
    }
 void Awake()
 {
     if (instance)
     {
         GGDebug.LogError("======================================Constructor twice!!!===================================");
     }
     instance = this;
     Application.targetFrameRate = 60;
 }
Esempio n. 4
0
    private float[] franceNumRate = { 40f, 70f, 90f, 100f }; //栅栏数目:0-3权重

    void Awake()
    {
        if (instance)
        {
            GGDebug.LogError("Constructor twice!!!");
        }
        instance = this;

        //初始
        this.curCreateWallIndex = Mathf.CeilToInt((Screen.height + Global.wallHeight * 3) / Global.wallHeight);
    }
Esempio n. 5
0
 //满墙
 public void CreateFullWall()
 {
     GGDebug.Log("==================满墙===================");
     for (int i = 0; i < fWallPosX.Length; i++)
     {
         WallUnitController script = WallUnitController.Create();
         this.AddWallUnit(script.gameObject, this.GetWallPos(fWallPosX[i]));
     }
     this.curCreateWallIndex++;
     this.curHorizontalType = Global.WallHorizontalType.FRANCE;
 }
Esempio n. 6
0
 /// <summary>
 /// 设置蛇的生命数目
 /// </summary>
 public void SetLifeCounts(int lifeCounts)
 {
     if (this.lifeCounts < 0)
     {
         GGDebug.Log("=============================lifeCount不可以赋值为负数=============================");
         return;
     }
     else
     {
         this.lifeCounts = lifeCounts;
     }
 }
Esempio n. 7
0
 //设置生命数目Text
 public void SetLifeNumText()
 {
     if (lifeNumText == null)
     {
         GGDebug.Log("=================lifeNumText是空的,哪里出问题了====================");
         return;
     }
     else
     {
         lifeCounts       = mSnakeList.Count;
         lifeNumText.text = this.lifeCounts + "";
     }
 }
 void OnTriggerEnter2D(Collider2D cell)
 {
     if (cell.gameObject.name.Equals("WallUnit(Clone)"))
     {
         GGDebug.Log("---蛇:-----开始碰撞-------");
         GGDebug.Log(cell.gameObject.name);
         SnakeManage.GetInstance().DelSnakeUnit();
         Destroy(gameObject);
     }
     if (cell.gameObject.name.Equals("France1(Clone)") || cell.gameObject.name.Equals("France2(Clone)"))
     {
         LogicPartController.GetInstance().IsTriggerWall = true;
     }
 }
Esempio n. 9
0
 private void AddWallUnit(GameObject child, Vector3 pos)
 {
     if (gameObject != null)
     {
         Vector3 orginScale = child.transform.localScale;
         child.transform.parent        = gameObject.transform;
         child.transform.localScale    = orginScale;
         child.transform.localPosition = pos;
     }
     else
     {
         GGDebug.Log("=================mGrid是空的,哪里出了问题了==================");
     }
 }
Esempio n. 10
0
 //销毁一个节点
 public void DelSnakeUnit()
 {
     GGDebug.Log("销毁蛇!!" + mSnakeList.Count);
     if (mSnakeList.Count > 0)
     {
         mSnakeList.RemoveAt(0);
         SetLifeNumText();
     }
     else
     {
         GGDebug.Log("Stop!!!!");
         LogicPartController.GetInstance().isPause = true;
     }
 }
Esempio n. 11
0
    void Awake()
    {
        if (instance)
        {
            GGDebug.LogError("Constructor twice!!!");
        }
        instance = this;

        for (int i = 0; i < this.initSnakeCouts; i++)
        {
            mInitPos.Add(new Vector3(0f, 0f, 0f));
        }

        //计算

        //测试
        this.InitSnake();
    }
Esempio n. 12
0
    //单格栅栏
    private void CreateFrance1()
    {
        //1.确定数目
        int num = this.GetRateNum(franceNum, franceNumRate);

        GGDebug.Log("==================单格栅栏===================" + num);
        //2.确定位置
        List <int> francePos = new List <int>();

        for (int i = 0; i < num; i++)
        {
            while (true)
            {
                int  randPos = Random.Range(1, 5);
                bool isSame  = false;
                for (int j = 0; j < francePos.Count; j++)
                {
                    if (francePos[j] == randPos)
                    {
                        isSame = true;
                        break;
                    }
                }

                if (!isSame)
                {
                    francePos.Add(randPos);
                    break;
                }
            }
        }
        //3.添加GameObject
        for (int i = 0; i < francePos.Count; i++)
        {
            FranceUnitController script = FranceUnitController.Create(Global.WallHorizontalType.FRANCE_1);
            this.AddWallUnit(script.gameObject, this.GetWallPos(fFrancePosX[i] - 1));
        }

        this.loopIndexNum++;
        this.curCreateWallIndex++;
        this.JudgeIsNewFullWall();
    }
Esempio n. 13
0
 void OnTriggerEnter2D(Collider2D cell)
 {
     GGDebug.Log("-----墙:---开始碰撞-------");
     DelLifeNum();
 }
Esempio n. 14
0
    void FixedUpdate()
    {
        Vector3 unitV = new Vector2(Mathf.Lerp(lastX, DragEventListener.xSpeed, lerpRate), speed);

        if (IsTriggerWall)
        {
            unitV = new Vector3(0f, unitV.y);
        }
        lastX = unitV.x;
        SnakeUnitController.moveSpeed = unitV.magnitude * Time.fixedDeltaTime;
        List <SnakeUnitController> snakeList = SnakeManage.GetInstance().GetSnakeList(); //头节点

        //游戏结束!
        if (isPause || snakeList.Count == 0)
        {
            GGDebug.Log("游戏结束!");
            return;
        }
        SnakeUnitController firstSnake = snakeList[0];

        firstSnake.transform.localPosition += unitV.normalized * SnakeUnitController.moveSpeed;
        Vector3 pos = firstSnake.transform.localPosition;

        //生命数目text
        SnakeManage.GetInstance().lifeNumText.transform.localPosition = pos + new Vector3(0f, 40f, 0);

        //Debug.Log(SnakeUnit.moveSpeed);
        for (int i = 0; i < snakeList.Count; i++)
        {
            snakeList[i].MyUpdate();
        }

        //创造障碍物
        Vector3 curSnakePos = SnakeManage.GetInstance().GetLifeNumTextPos();

        if ((WallManage.GetInstance().curCreateWallIndex *Global.wallHeight - curSnakePos.y - Global.wallHeight) <= Screen.height / 2) //创建新的一排障碍物
        {
            if (WallManage.GetInstance().curHorizontalType == Global.WallHorizontalType.INIT)                                          //初始第一排
            {
                WallManage.GetInstance().CreateInitHorizontalWall();
            }
            else
            {
                if (WallManage.GetInstance().curHorizontalType == Global.WallHorizontalType.NONE) //空墙
                {
                    GGDebug.Log("=====================怎么创建空墙了==========================");
                    //WallManage.GetInstance().CreateNoneWall();
                }
                else if (WallManage.GetInstance().curHorizontalType == Global.WallHorizontalType.SINGLE_WALL) //零散墙
                {
                    WallManage.GetInstance().CreateSingleWall();
                }
                else if (WallManage.GetInstance().curHorizontalType == Global.WallHorizontalType.FRANCE) //单格栅栏 双格栅栏
                {
                    WallManage.GetInstance().CreateFrance();
                }
                else if (WallManage.GetInstance().curHorizontalType == Global.WallHorizontalType.FULL_WALL) //满墙
                {
                    WallManage.GetInstance().CreateFullWall();
                }
            }
        }
    }