Пример #1
0
    public Line SplitLine(Vector3 splitPosition, GameController gameController)
    {
        /*
         * Split the current line into two lines along with a corner.
         * The given position is where the line will be split.
         * The function will always shorten the current line
         * from it's end position and keep it's start position unchanged.
         */
        Line   newLine   = null;
        Corner newCorner = null;

        /* Check if the given position is on this line, exclusing the corners */
        if (PointOnLine(splitPosition, false))
        {
            /* Create a new line that goes from the given position to the current line's end */
            newLine = NewLine(splitPosition.x, splitPosition.y, end.x, end.y);

            /* Link the new line to the end corner of this line */
            newCorner = endCorner;
            newCorner.RemoveLine(this);
            newCorner.AddLine(newLine);

            /* Reposition the end point of this line to match the new line's starting position */
            end = splitPosition;

            /* Create a new corner that connects this line with the new line */
            newCorner = Corner.NewCorner(splitPosition);
            newCorner.AddLine(this);
            newCorner.AddLine(newLine);

            /* Re-create the vertices that make up the two lines */
            newLine.GenerateVertices(gameController);
            GenerateVertices(gameController);

            /* Add the line and corner to the gameController and it's lineDrawer */
            gameController.AddLine(newLine);
            gameController.AddCorner(newCorner);
        }

        if (linkedPlayers.Count > 0)
        {
            Debug.Log("Split line with players on it");
        }

        return(newLine);
    }
Пример #2
0
    public void NewDrawingLine(OrthogonalDirection direction, bool addCorner)
    {
        /*
         * Put the player onto a new drawing line from their given position. The given
         * boolean determines whether we need to create a corner at the player's position.
         */

        /* Add a corner to the end of the current line if needed */
        if (addCorner)
        {
            if (currentLine.end.Equals(gamePosition))
            {
                /* Create the line and attach it to the corner */
                Corner newCorner = Corner.NewCorner(gamePosition);
                newCorner.AddLine(currentLine);

                /* Add the corner to the gameController so it can be rendered */
                gameController.AddCorner(newCorner);
            }
            else
            {
                Debug.Log("WARNING: Trying to add a corner not on the end of a line");
            }
        }

        /* Create a new line that the player will use to draw. Place the end point of
         * the line slightly forward to the line's a direction and not a point */
        Line drawLine = Line.NewLine(gamePosition, gamePosition);

        /* Once the line is added to the drawing list, change it's end point to move forward
         * so that it's no longer a point but a line. This will keep it's visuals unchanged
         * so that we cannot see the line but it's treated as such. */
        gameController.AddLine(drawLine);
        drawLine.end += Corner.DirectionToVector(direction);

        /* Link the new line's start corner to the corner's direction side */
        GetCorner().LinkLineStart(drawLine, direction);

        /* Move the player to the new line */
        ChangeCurrentLine(drawLine);
    }