Esempio n. 1
0
        //三节身体小蛇
        public Snake(GameObject _prefab, Vector3 _pos,
                     Vector3 _dir, float _moveSpan, float _moveWait, float _scale, Control _controller) : base(_prefab, _pos, null, null)
        {
            active     = false;
            controller = _controller;
            preFab     = _prefab;

            this.direction = _dir;
            this.moveSpan  = _moveSpan;
            this.moveWait  = _moveWait;
            this.dest      = direction * moveSpan + Position;
            this.timer     = _moveWait;
            this.scale     = _scale;

            this.Ob.name = "head";
            this.SetColor(new Color(0.3f, 0.1f, 0.1f));

            bodyBegain = new SnakeNode(_prefab, this.Position - this.Ob.transform.forward * _scale, this, null);
            bodyBegain.SetColor(Color.gray);
            bodyBegain.Ob.name = "bodybegain";

            tail         = new SnakeNode(_prefab, bodyBegain.Ob.transform.position - bodyBegain.Ob.transform.forward * _scale, bodyBegain, null);
            tail.Ob.name = "tail";
            tail.SetColor(new Color(0.3f, 0.0f, 0.3f));

            this.SetNext(bodyBegain);
            bodyBegain.SetNext(tail);

            //Component
            Ob.AddComponent <SnakeCollision>();

            //Bodynum & Effected
            effectbodyNum = 0;
        }
Esempio n. 2
0
        public SnakeNode(GameObject _prefab, Vector3 _pos, SnakeNode _pre, SnakeNode _next)
        {
            this.position = _pos;
            this.previous = _pre;
            this.next     = _next;

            ob = GameObject.Instantiate(_prefab, this.position, Quaternion.identity);
            ob.transform.GetComponent <Renderer>().material.SetFloat("_Effect", 0.0f);
        }
Esempio n. 3
0
        public void Win()
        {
            if (effectbodyNum >= 7)
            {
                Debug.Log("小蛇变成了七彩艾希,像彩虹一般出现在Hank眼前");
                controller.SetActiveState(false);

                SnakeNode current = this;

                while (current != null)
                {
                    GameObject.Destroy(current.Ob);
                    current = current.Next;
                }
            }
        }
Esempio n. 4
0
        /*移动完子节点位置后,才更新自己*/
        public void MoveBody(SnakeNode node)
        {
            if (node == null)
            {
                return;
            }

            if (node.Previous != null)
            {
                node.MoveTo(node.Previous.Position);
                node.Previous.SetPosInfo();
                this.tail.SetPosInfo();
            }
            else
            {
                node.MoveTo(dest);
            }

            MoveBody(node.Next);
        }
Esempio n. 5
0
 public void SetPrevious(SnakeNode _previous)
 {
     this.previous = _previous;
 }
Esempio n. 6
0
 public void SetNext(SnakeNode _next)
 {
     this.next = _next;
 }
Esempio n. 7
0
        //在尾部位置添加,并将尾部后移
        public void AddBody(FRUITKIND fruitKind)
        {
            switch (fruitKind)
            {
            case FRUITKIND.Apple:

                isEatApple     = true;
                effectbodyNum += 1;

                SnakeNode newTail = new SnakeNode(preFab, tail.Position, tail.Previous, tail);
                tail.Previous.SetNext(newTail);
                tail.SetPrevious(newTail);
                newTail.SetEffect(1.0f);

                tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale);
                tail.SetPosInfo();
                break;

            case FRUITKIND.Mango:
                SnakeNode newTail2 = new SnakeNode(preFab, tail.Position, tail.Previous, tail);
                tail.Previous.SetNext(newTail2);
                tail.SetPrevious(newTail2);
                if (isEatApple)
                {
                    newTail2.SetEffect(1.0f);
                    effectbodyNum += 1;
                }
                else
                {
                    newTail2.SetColor(new Color(0.77f, 0.46f, 0.03f));
                }

                tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale);
                tail.SetPosInfo();
                break;

            case FRUITKIND.Peach:
                SnakeNode newTail3 = new SnakeNode(preFab, tail.Position, tail.Previous, tail);
                tail.Previous.SetNext(newTail3);
                tail.SetPrevious(newTail3);

                if (isEatApple)
                {
                    newTail3.SetEffect(1.0f);
                    effectbodyNum += 1;
                }
                else
                {
                    newTail3.SetColor(new Color(0.89f, 0.51f, 0.63f));
                }

                tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale);
                tail.SetPosInfo();

                break;

            case FRUITKIND.Strawberry:
                SnakeNode newTail4 = new SnakeNode(preFab, tail.Position, tail.Previous, tail);
                tail.Previous.SetNext(newTail4);
                tail.SetPrevious(newTail4);
                if (isEatApple)
                {
                    newTail4.SetEffect(1.0f);
                    effectbodyNum += 1;
                }
                else
                {
                    newTail4.SetColor(new Color(80, 0.0f, 0.23f));
                }

                tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale);
                tail.SetPosInfo();
                break;

            case FRUITKIND.Watermelon:
                SnakeNode newTail5 = new SnakeNode(preFab, tail.Position, tail.Previous, tail);
                tail.Previous.SetNext(newTail5);
                tail.SetPrevious(newTail5);
                if (isEatApple)
                {
                    newTail5.SetEffect(1.0f);
                    effectbodyNum += 1;
                }
                else
                {
                    newTail5.SetColor(new Color(0.06f, 0.42f, 0.23f));
                }

                tail.MoveTo(tail.Position - tail.Ob.transform.forward * scale);
                tail.SetPosInfo();
                break;

            default:
                break;
            }

            Win();
        }