Exemple #1
0
    bool MakeSnake(Point3 newSnakePos)
    {
        if (head != null)
        {
            DisableGuidelines();
        }

        if (_board.SetVoxel(newSnakePos, "Snake"))
        {
            if (head != null)
            {
                head.RendMat = baseSnakeMat;
            }
            head         = _board.GetVoxelAt(newSnakePos);
            head.RendMat = snakeHeadMat;

            LinkedListNode <Point3> lln = new LinkedListNode <Point3>(newSnakePos);
            _snakeList.AddFirst(lln);
            if (_snakeList.Count > 1)
            {
                var neckPoint = lln.Next.Value;
                var neck      = _board.GetVoxelAt(neckPoint);

                if (neckPoint.x > newSnakePos.x)
                {
                    // East
                    head.ExtendEast = true;
                    neck.ExtendWest = true;
                }
                else if (neckPoint.x < newSnakePos.x)
                {
                    // West
                    head.ExtendWest = true;
                    neck.ExtendEast = true;
                }
                else if (neckPoint.y > newSnakePos.y)
                {
                    // North
                    head.ExtendNorth = true;
                    neck.ExtendSouth = true;
                }
                else if (neckPoint.y < newSnakePos.y)
                {
                    // South
                    head.ExtendSouth = true;
                    neck.ExtendNorth = true;
                }
                else if (neckPoint.z > newSnakePos.z)
                {
                    // Above
                    head.ExtendTop    = true;
                    neck.ExtendBottom = true;
                }
                else if (neckPoint.z < newSnakePos.z)
                {
                    // Below
                    head.ExtendBottom = true;
                    neck.ExtendTop    = true;
                }
            }

            return(true);
        }
        return(false);
    }