static public BoxOverlap GetOverlapOfBox(VertexBox a, VertexBox b)
    {
        float   xOverlap;
        float   yOverlap;
        Vector2 mtv;

        xOverlap = a.Collider.bounds.extents.x + b.Collider.bounds.extents.x - Mathf.Abs(a.transform.position.x - b.transform.position.x);
        yOverlap = a.Collider.bounds.extents.y + b.Collider.bounds.extents.y - Mathf.Abs(a.transform.position.y - b.transform.position.y);

        if (a.transform.position.x < b.transform.position.x)
        {
            xOverlap = -xOverlap;
        }

        if (a.transform.position.y < b.transform.position.y)
        {
            yOverlap = -yOverlap;
        }

        if (Mathf.Abs(xOverlap) < Mathf.Abs(yOverlap))
        {
            mtv = new Vector2(xOverlap, 0);
        }
        else
        {
            mtv = new Vector2(0, yOverlap);
        }

        return(new BoxOverlap(xOverlap, yOverlap, mtv));
    }
Exemplo n.º 2
0
        public void Draw(IList <Chunk> chunks, Camera camera)
        {
            if (chunks.Count > 0)
            {
                if (Game.RenderSolid)
                {
                    _solidEffectDefinition.Use(_device);
                    foreach (var chunk in chunks)
                    {
                        chunk.Buffers.BufferSolid?.Draw(_device);
                    }
                }

                if (Game.RenderSprites)
                {
                    _spriteEffectDefinition.Use(_device);
                    foreach (var chunk in chunks)
                    {
                        if (chunk.BuildingContext.SpriteBlocks.Count > 0)
                        {
                            chunk.Buffers.BufferSprite?.Draw(_device);
                        }
                    }
                }

                if (Game.RenderWater)
                {
                    _device.ImmediateContext.OutputMerger.SetBlendState(_waterBlendState);
                    _waterEffectDefinition.Use(_device);
                    foreach (var chunk in chunks)
                    {
                        chunk.Buffers.BufferWater?.Draw(_device);
                    }
                    _device.ImmediateContext.OutputMerger.SetBlendState(null);
                }

                if (Game.RenderBoxes)
                {
                    var boxVertices = new VertexBox[(camera.CurrentCursor != null ? 1 : 0) + (Game.ShowChunkBoundingBoxes ? chunks.Count : 0)];
                    if (camera.CurrentCursor != null)
                    {
                        boxVertices[^ 1] = new VertexBox(camera.CurrentCursor.BoundingBox, new Color3(0.713f, 0.125f, 0.878f));
Exemplo n.º 3
0
 private void Awake()
 {
     m_VertexBox = GetComponent <VertexBox>();
     m_Collider  = GetComponent <BoxCollider2D>();
 }
 static public bool AreBoxesIntersecting(VertexBox a, VertexBox b)
 {
     return(Mathf.Abs(a.GetWorldPositionOfBox().x - b.GetWorldPositionOfBox().x) < a.Collider.bounds.extents.x + b.Collider.bounds.extents.x &&
            Mathf.Abs(a.GetWorldPositionOfBox().y - b.GetWorldPositionOfBox().y) < a.Collider.bounds.extents.y + b.Collider.bounds.extents.y);
 }