Ejemplo n.º 1
0
    /// <summary>
    /// Get a list of active lines and deactivates them.
    /// </summary>
    public void Clear()
    {
        var activeLines = lineFactory.GetActive();

        foreach (var line in activeLines)
        {
            line.gameObject.SetActive(false);
        }
    }
Ejemplo n.º 2
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;
            }
        }
    }
Ejemplo n.º 3
0
    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);
            }
        }
    }
Ejemplo n.º 4
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);
                }
            }
        }
    }