Beispiel #1
0
        //这个方法我其实不太懂,某个color的数组遍历后,为什么就变成3段了呢
        void ThreeSnake(Color[] colors)
        {
            snakeNode = new SnakeNode(snakePrefab, new Vector3(3, 0.5f, 0), colors[0], null);

            for (int i = 1; i < colors.Length; i++)
            {
                snakeNode.eatFood(snakeNode, colors[i], null);
            }
        }
Beispiel #2
0
        public void Move(SnakeNode node, Vector3 _pos)
        {
            if (node == null)
            {
                return;
            }

            Move(node.nextNode, node.snakeObj.transform.position);
            node.snakeObj.transform.position = _pos;
        }
Beispiel #3
0
 //想让蛇头和每个食物判断位置距离是不是接近,然后新长出的身体是灰色,但是水果们没有颜色
 public void SnakeGrow(SnakeNode node, List <Food> Snakes)
 {
     for (int i = 0; i < Snakes.Count; i++)
     {
         foreach (Food food in Snakes)
         {
             if (Vector3.Distance(Snakes[i].GetPosition(), node.GetPosition()) < 0.5f)
             {
                 snakeNode.eatFood(node, Color.gray, null);
                 Snakes.Remove(food);
                 return;
             }
         }
     }
 }
Beispiel #4
0
 public void eatFood(SnakeNode node, Color color, Texture t)
 {
     if (node.nextNode == null)
     {
         node.nextNode = new SnakeNode(snakeObj, snakeObj.transform.position, color, t);
         if (t != null)
         {
             Snakebody += 1;
         }
     }
     else
     {
         eatFood(node.nextNode, color, t);
     }
 }