Beispiel #1
0
    void Connect(int x, int y, int dx, int dy, Color pixel)
    {
        if (pixel == Color.white)
        {
            return;
        }
        IActiveElement otherBlock  = null;
        IActiveElement thisBlock   = null;
        bool           willConnect = _elements.TryGetValue(new Vector2(x + dx, y + dy), out otherBlock);

        willConnect = willConnect && _elements.TryGetValue(new Vector2(x, y), out thisBlock);
        if (willConnect)
        {
            thisBlock.AddBlock(otherBlock);
        }
    }
Beispiel #2
0
    void ConnectLogic(int x, int y)
    {
        var x2    = x;
        var y2    = y;
        var pixel = Map.GetPixel(x + 1, y);

        if (pixel != Color.white)
        {
            x2++;
        }
        pixel = Map.GetPixel(x, y + 1);
        if (pixel != Color.white)
        {
            y2++;
        }
        pixel = Map.GetPixel(x - 1, y);
        if (pixel != Color.white)
        {
            x2--;
        }
        pixel = Map.GetPixel(x, y - 1);
        if (pixel != Color.white)
        {
            y2--;
        }
        IActiveElement otherBlock  = null;
        IActiveElement thisBlock   = null;
        bool           willConnect = _elements.TryGetValue(new Vector2(x2, y2), out otherBlock);

        willConnect = willConnect && _elements.TryGetValue(new Vector2(x, y), out thisBlock);
        if (willConnect)
        {
            thisBlock.AddBlock(otherBlock);
        }

        // Connect inputs
        if (x2 > x)
        {
            if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) &&
                _elements.TryGetValue(new Vector2(x - 1, y + 1), out thisBlock))
            {
                thisBlock.AddBlock(otherBlock);
            }
            if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) &&
                _elements.TryGetValue(new Vector2(x - 1, y - 1), out thisBlock))
            {
                thisBlock.AddBlock(otherBlock);
            }
        }
        else if (x2 < x)
        {
            if (_elements.TryGetValue(new Vector2(x, y), out otherBlock) &&
                _elements.TryGetValue(new Vector2(x + 1, y + 1), out thisBlock))
            {
                thisBlock.AddBlock(otherBlock);
            }
            if (_elements.TryGetValue(new Vector2(x + 1, y - 1), out thisBlock))
            {
                thisBlock.AddBlock(otherBlock);
            }
        }
    }