コード例 #1
0
ファイル: LineDrawer.cs プロジェクト: kerimdeveci/flip
    void Update()
    {
        /*
         * print(listenForSwipes);
         *
         * if (!listenForSwipes)
         * {
         *  return;
         * }
         */

        if (Input.GetMouseButtonDown(0))
        {
            RaycastHit hit;
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

            if (Physics.Raycast(ray, out hit, worldMask))
            {
                if (Vector3.Distance(player.transform.position, hit.point) > MAX_PLAYER_DIST)
                {
                    return;
                }

                drawnLine = lineFactory.GetLine(player.transform.position, hit.point, 0.1f, Color.black);
                drawnLine.transform.SetParent(lineContainer, true);

                player.RemoveAllWaypoints();
                player.AddWaypoint(drawnLine);
            }
        }
        else if (Input.GetMouseButton(0))
        {
            if (drawnLine != null)
            {
                RaycastHit hit;
                Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);

                if (Physics.Raycast(ray, out hit, worldMask))
                {
                    if (Vector3.Distance(drawnLine.start, drawnLine.end) > LINE_MAX_LENGTH)
                    {
                        drawnLine = lineFactory.GetLine(drawnLine.end, hit.point, 0.1f, Color.black);
                        drawnLine.transform.SetParent(lineContainer, true);

                        player.AddWaypoint(drawnLine);
                    }
                    else
                    {
                        drawnLine.end = hit.point;
                    }
                }
            }
        }
        else if (Input.GetMouseButtonUp(0))
        {
            drawnLine = null;
        }
    }
コード例 #2
0
    private void BuildGrid(int cols, int rows)
    {
        Vector3 currentPosition = Vector3.zero;

        float tileSize = TileObject.GetComponent <BoxCollider2D>().size.x;

        float totalWidth  = tileSize * cols;
        float totalHeight = tileSize * rows;


        Vector2 halfTileOffset = new Vector2(tileSize / 2f, tileSize / 2f);
        Vector2 halfGridOffset = new Vector2(totalWidth / 2f, totalHeight / 2f);
        Vector2 positionOffset = gridPosition.position;

        Vector3 topLeftOffset = Vector3.zero;

        int id = 0;

        for (int y = rows - 1; y >= 0; y--)
        {
            for (int x = 0; x < cols; x++)
            {
                currentPosition = new Vector2(x * tileSize, y * tileSize) + halfTileOffset - halfGridOffset + positionOffset;
                GameObject newTileObject = Instantiate(TileObject, currentPosition, Quaternion.identity, gridParent) as GameObject;
                newTileObject.tag = "GridTile";

                Tile newTile = newTileObject.GetComponent <Tile>();
                newTile.id = id++;
                //newTile.canDrawBorder = true;
            }
        }

        minBound = (Vector2)gridPosition.position - halfGridOffset;
        maxBound = (Vector2)gridPosition.position + halfGridOffset;

        Vector3 topLeft = transform.position - new Vector3(halfGridOffset.x, halfGridOffset.y, 0f) + new Vector3(positionOffset.x, positionOffset.y, 0f);

        for (int i = 0; i <= rows; i++)
        {
            Vector3 a = new Vector3(topLeft.x, topLeft.y + (i * tileSize), topLeft.z);

            lineFactory.GetLine(a, a + (Vector3.right * totalWidth), lineWidth, gridColor);
        }

        for (int i = 0; i <= cols; i++)
        {
            Vector3 a = new Vector3(topLeft.x + (i * tileSize), topLeft.y, topLeft.z);

            lineFactory.GetLine(a, a + (Vector3.up * totalHeight), lineWidth, gridColor);
        }
    }
コード例 #3
0
    /// <summary>
    /// Draw field. Need saved screen position.
    /// </summary>
    void DrawField()
    {
        var heightInWorldPoint = Mathf.Abs(screenBottom) + Mathf.Abs(screenTop);

        //Drawing horizontal lines
        var startPoint = new Vector2(screenLeft, screenTop);
        var endPoint   = new Vector2(screenLeft + heightInWorldPoint, screenTop);

        while (startPoint.y >= screenBottom)
        {
            lineFactory.GetLine(startPoint, endPoint, drawingLineWidth, drawingLineColor);
            startPoint.y -= drawingLineStep;
            endPoint.y   -= drawingLineStep;
        }

        //Drawing vertical lines and create field[,]
        startPoint.x = screenLeft;
        startPoint.y = screenTop;
        endPoint.x   = screenLeft;
        endPoint.y   = screenBottom;

        var countHorizontalLine = lineFactory.GetActive().Count;

        field = new FieldSquare[countHorizontalLine - 1, countHorizontalLine - 1];

        for (var i = 0; i < countHorizontalLine; i++)
        {
            lineFactory.GetLine(startPoint, endPoint, drawingLineWidth, drawingLineColor);
            startPoint.x += drawingLineStep;
            endPoint.x   += drawingLineStep;

            if (i == countHorizontalLine - 1)
            {
                break; //Last line. Doesn't need spawn squares
            }
            //Create square of field
            //1)Down half of drawingStep
            var spawnPositionForSquare = new Vector2(startPoint.x - 0.5f * drawingLineStep, startPoint.y - 0.5f * drawingLineStep);
            //2) And spawn
            for (var j = 0; j < countHorizontalLine - 1; j++)
            {
                var square = Instantiate(squareOfField, spawnPositionForSquare, Quaternion.identity, this.transform);
                field[i, j] = new FieldSquare(square.GetComponent <SpriteRenderer>());

                spawnPositionForSquare.y -= drawingLineStep;
            }
        }
    }
コード例 #4
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);              // Start line drawing
            if (ball != null && ball.isCollidingWith(pos.x, pos.y))
            {
                drawnLine = lineFactory.GetLine(pos, pos, 0.02f, Color.black);
                drawnLine.EnableDrawing(true);
            }
        }
        else if (Input.GetMouseButtonUp(0) && drawnLine != null)
        {
            drawnLine.EnableDrawing(false);
            //update the vel of the white ball.


            ball.mVel = new HVector2D((drawnLine.start.x - drawnLine.end.x) * 0.2f, (drawnLine.start.y - drawnLine.end.y) * 0.2f);
            drawnLine = null; // End line drawing
        }

        if (drawnLine != null)
        {
            drawnLine.end = Camera.main.ScreenToWorldPoint(Input.mousePosition);              // Update line end
        }
    }
コード例 #5
0
    public void StartLine()
    {
        if (drawnLine != null && lineDrawPermission == 1)     // check that the line is not connecting the same object
        {
            drawnLine = null;
            outgoingLines[--countOutLines].gameObject.SetActive(false);
        }
        else if (drawnLine != null && countInLines < maxInLines)                                       //check if line drawing is process and incoming no. lines has not exceeded
        {
            if (connectingGears.Count < 2 || connectingGears[connectingGears.Count - 2] != gameObject) //To prevent out of bounds error and To ensure that the gear is not connecting to the previous gear
            {
                EndLine();
            }
        }

        else if (countOutLines == maxOutLines && drawnLine == null)
        {
            Clear();
        }
        else if (lineDrawPermission == 1)
        {
            var pos = Camera.main.ScreenToWorldPoint(transform.position);
            startPos  = pos;
            drawnLine = lineFactory.GetLine(pos, pos, 0.03f, Color.white);

            outgoingLines[countOutLines++] = drawnLine.GetComponent <Line>();
        }
    }
コード例 #6
0
    public void DrawLine()
    {
        Vector2 start = postions[0].position;
        Vector2 end   = postions[1].position;

        line = lineFactory.GetLine(start, end, lineWidth, Color.white);
    }
コード例 #7
0
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);              // Start line drawing
            if (ball != null && ball.isCollidingWith(pos.x, pos.y))
            {
                drawnLine = lineFactory.GetLine(pos, pos, 2.0f, Color.black);
                drawnLine.EnableDrawing(true);

                drawnLine2 = lineFactory.GetLine(pos, pos, 2.0f, Color.red);
                drawnLine2.EnableDrawing(true);
            }
        }
        else if (Input.GetMouseButtonUp(0) && drawnLine != null)
        {
            Vector3 tableCenter = new Vector3(GlobalVariable.SCREEN_WIDTH / 2.0f, GlobalVariable.SCREEN_HEIGHT / 2.0f, 0);

            AudioSource.PlayClipAtPoint(hitSound, tableCenter);

            drawnLine.EnableDrawing(false);
            drawnLine2.EnableDrawing(false);

            //update the vel of the white ball.
            HVector2D v = new HVector2D(drawnLine.start.x - drawnLine.end.x, drawnLine.start.y - drawnLine.end.y);
            //  v.normalize();

            ball.mVel = v * 3.0f;
            drawnLine = null; // End line drawing

            drawnLine2 = null;
        }

        if (drawnLine != null)
        {
            drawnLine.end = Camera.main.ScreenToWorldPoint(Input.mousePosition);              // Update line end
        }

        if (drawnLine2 != null)
        {
            Vector2 v          = new Vector2(drawnLine.start.x - drawnLine.end.x, drawnLine.start.y - drawnLine.end.y);
            Vector2 currentPos = new Vector2(drawnLine2.start.x, drawnLine2.start.y);
            drawnLine2.end = currentPos - v * -1.0f * 3.0f * (1.0f - GlobalVariable.PHYSICS_FRICTION * Time.deltaTime);;
        }
    }
コード例 #8
0
        public void TestDrawLine()
        {
            Line line = LineFactory.GetLine();

            line.FirstpointXCoordinate  = 100;
            line.FirstpointYCoordinate  = 200;
            line.SecondpointXCoordinate = 400;
            line.SecondpointYCoordinate = 300;
            ILineOperation lineOperation = LineOperationFactory.GetLineOperation();

            lineOperation.Draw(line);
        }
コード例 #9
0
ファイル: LineDraw.cs プロジェクト: b02902092/AnimalWar
    void Update()
    {
        if (Input.GetMouseButtonDown(0))
        {
            var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Start line drawing
            drawnLine = lineFactory.GetLine(pos, pos, 0.02f, Color.black);
        }
        else if (Input.GetMouseButtonUp(0))
        {
            drawnLine = null; // End line drawing
        }

        if (drawnLine != null)
        {
            drawnLine.end = Camera.main.ScreenToWorldPoint(Input.mousePosition); // Update line end
        }
    }
コード例 #10
0
    private void CreateStraightLines()
    {
        // A length of 1 translates to "100% of the game space"
        // var start1 = Camera.main.ScreenToWorldPoint(new Vector2(-1, -1));
        //var end1 = Camera.main.ScreenToWorldPoint(new Vector2(1, 1));

        GameObject canv  = GameObject.FindGameObjectsWithTag("MainCanvas")[0];
        var        scale = canv.GetComponent <RectTransform>().localScale;

        var gameOrigin = Camera.main.ScreenToWorldPoint(m_gameArea.GetComponent <RectTransform>().position);

        var realStart1 = (Vector2)gameOrigin + new Vector2(-10 / scale.x, -10 / scale.y);
        var realEnd1   = (Vector2)gameOrigin + new Vector2(10 / scale.x, 10 / scale.y);

        /*float height = Camera.main.orthographicSize * 2.0f;
         * float width = height * Camera.main.aspect;
         * float gameWidth = width * 0.3f; // TODO tweak
         * float gameHeight = height * 0.8f; // TODO tweak
         *
         * var realStart1 = (Vector2)gameOrigin + new Vector2(start1.x * gameWidth / 2, start1.y * gameHeight / 2);
         * var realEnd1 = (Vector2)gameOrigin + new Vector2(end1.x * gameWidth / 2, end1.y * gameHeight / 2);*/


        var line1 = lineFactory.GetLine(realStart1, realEnd1, 0.05f, Color.black);


        /*var start1 = new Vector2(-1, 1f);
         * var end1 = new Vector2(1, -1f);
         *
         * var gameOrigin = Camera.main.ScreenToWorldPoint(m_gameArea.GetComponent<RectTransform>().position);
         * float height = Camera.main.orthographicSize * 2.0f;
         * float width = height * Camera.main.aspect;
         * float gameWidth = width * 0.3f; // TODO tweak
         * float gameHeight = height * 0.8f; // TODO tweak
         *
         * var realStart1 = (Vector2)gameOrigin + new Vector2(start1.x * gameWidth / 2, start1.y * gameHeight / 2);
         * var realEnd1 = (Vector2)gameOrigin + new Vector2(end1.x * gameWidth / 2, end1.y * gameHeight / 2);
         * var line1 = lineFactory.GetLine(realStart1, realEnd1, 0.05f, Color.black);*/
    }
コード例 #11
0
ファイル: MapScript.cs プロジェクト: MartinTaTTe/Esbospelet
    public void ReDrawMetroConnections()
    {
        var activeLines = lineFactory.GetActive();

        foreach (var line in activeLines)
        {
            line.gameObject.SetActive(false);
        }

        foreach (MetroStation fromStation in map.metroStations)
        {
            foreach (MetroStation toStation in fromStation.GetMetroConnections())
            {
                Vector3 fromVector;
                Vector3 toVector;
                if (fromStation.y % 2 == 0)
                {
                    fromVector = new Vector3(fromStation.x * tileWidth, fromStation.y * tileHeight, 2);
                }
                else
                {
                    fromVector = new Vector3(fromStation.x * tileWidth + tileWidth / 2, fromStation.y * tileHeight, 2);
                }

                if (toStation.y % 2 == 0)
                {
                    toVector = new Vector3(toStation.x * tileWidth, toStation.y * tileHeight, 2);
                }
                else
                {
                    toVector = new Vector3(toStation.x * tileWidth + tileWidth / 2, toStation.y * tileHeight, 2);
                }

                Line drawnLine = lineFactory.GetLine(fromVector, toVector, 0.08f, Color.red);
            }
        }
    }
コード例 #12
0
    void Update()
    {
        //only draw lines on map
        if (Map.GetComponent <Collider2D>().OverlapPoint(Camera.main.ScreenToWorldPoint(Input.mousePosition)) == true)
        {
            if (Erase == false && CharacterPlacement == false)
            {
                if (Input.GetMouseButtonDown(0) && placed == false)
                {
                    //start line drawing
                    var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                    drawnLine = lineFactory.GetLine(pos, pos, width, col);

                    placed = true;
                }

                else if (Input.GetMouseButtonDown(0) && placed == true)
                {
                    placed = false;

                    //end line drawing
                    drawnLine = null;
                }

                if (drawnLine != null)
                {
                    //update the line size as the player draws
                    drawnLine.end = Camera.main.ScreenToWorldPoint(Input.mousePosition);
                }
            }

            else if (Erase == true)
            {
                if (Input.GetMouseButton(0))
                {
                    var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                    var activeLines = lineFactory.GetActive();

                    foreach (var line in activeLines)
                    {
                        if (line.gameObject.GetComponent <BoxCollider2D>().OverlapPoint(pos))
                        {
                            line.gameObject.SetActive(false);
                        }
                    }

                    for (int i = 0; i < InstantiatedPictures.Count; i++)
                    {
                        if (InstantiatedPictures[i].GetComponent <BoxCollider2D>().OverlapPoint(pos))
                        {
                            Destroy(InstantiatedPictures[i]);
                            InstantiatedPictures.RemoveAt(i);
                        }
                    }
                }
            }

            else if (CharacterPlacement == true)
            {
                if (Input.GetMouseButtonDown(0))
                {
                    var pos = Camera.main.ScreenToWorldPoint(Input.mousePosition);

                    GameObject c = Instantiate(characterPrefab, new Vector3(pos.x, pos.y, 0), Quaternion.identity);
                    c.GetComponent <SpriteRenderer>().sprite = characterSprite;
                    InstantiatedPictures.Add(c);
                }
            }
        }
    }
コード例 #13
0
        static void Main(string[] args)
        {
            log4net.Config.XmlConfigurator.Configure();

            int ChoiceOfShape = 0;

            do
            {
                Console.WriteLine("Enter Your Choice to Draw Shape");
                Console.WriteLine("1.Line");
                Console.WriteLine("2.Circle");
                Console.WriteLine("3.Rectangle");
                Console.WriteLine("4.Exit");

                ChoiceOfShape = int.Parse(Console.ReadLine());

                switch (ChoiceOfShape)
                {
                case 1:

                    Console.WriteLine("1.Line");
                    Line line = LineFactory.GetLine();

                    Console.WriteLine("Enter X Co-ordinate of First point");
                    int XLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of First point");
                    int YLineFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X Co-ordinate of Second point");
                    int XLineSecond = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter Y Co-ordinate of Second point");
                    int YLineSecond = int.Parse(Console.ReadLine());

                    line.FirstpointXCoordinate  = XLineFirst;    //100
                    line.FirstpointYCoordinate  = YLineFirst;    //200
                    line.SecondpointXCoordinate = XLineSecond;   //400
                    line.SecondpointYCoordinate = YLineSecond;   //300

                    ILineOperation lineOperation = LineOperationFactory.GetLineOperation();

                    //IShapeOperation lineOperation = ShapeOperationFactory.GetLineOperation();

                    lineOperation.Draw(line);
                    log.InfoFormat("Line Created");


                    break;

                case 2:

                    Console.WriteLine("2.Circle");

                    Circle circle = CircleFactory.GetCircle();

                    Console.WriteLine("Enter X & Y Co-ordinate of Centre point");
                    int XCircleFirst = int.Parse(Console.ReadLine());
                    int YCircleFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Equidistance Points of Radius");
                    int XCircleSecond = int.Parse(Console.ReadLine());
                    int YCircleSecond = int.Parse(Console.ReadLine());

                    circle.FirstpointXCoordinate  = XCircleFirst;      //10
                    circle.FirstpointYCoordinate  = YCircleFirst;      //10
                    circle.SecondpointXCoordinate = XCircleSecond;     //50
                    circle.SecondpointYCoordinate = YCircleSecond;     //50

                    ICircleOperation circleOperation = CircleOperationalFactory.GetCircleOperation();
                    circleOperation.Draw(circle);

                    log.InfoFormat("Circle Created");

                    break;

                case 3:

                    Console.WriteLine("3.Rectangle");

                    ERectangle rectangle = RectangleFactory.GetRectangle();

                    Console.WriteLine("Enter X & Y Co-ordinate of First point of Rectangle");
                    int XRectFirst = int.Parse(Console.ReadLine());
                    int YRectFirst = int.Parse(Console.ReadLine());

                    Console.WriteLine("Enter X & Y Co-ordinate of Second Point of Rectangle");
                    int XRectSecond = int.Parse(Console.ReadLine());
                    int YRectSecond = int.Parse(Console.ReadLine());

                    rectangle.FirstpointXCoordinate  = XRectFirst;
                    rectangle.FirstpointYCoordinate  = YRectFirst;
                    rectangle.SecondpointXCoordinate = XRectSecond;
                    rectangle.SecondpointYCoordinate = YRectSecond;

                    IRectangleOperation rectangleOperation = RectangleOperationFactory.GetRectangleOperation();
                    rectangleOperation.Draw(rectangle);

                    log.InfoFormat("Rectangle Created");

                    break;

                case 4:


                    Console.WriteLine("4.Exit");
                    Console.WriteLine("Welcome Again!!");

                    System.Environment.Exit(0);

                    break;

                default:

                    Console.WriteLine("Wrong Choice ! ");
                    break;
                }
            } while (ChoiceOfShape != 3);
        }
コード例 #14
0
 private void ConnectNodeToNode(Node node1, Node node2)
 {
     drawnLine = lineFactory.GetLine(node1.transformInstance.position, node2.transformInstance.position, 0.01f, Color.gray);
     node1.ConnectToNode(node2);
     node2.ConnectToNode(node1);
 }