MiningGameServer.Shapes.ShapeAABB.CollideAABB C# (CSharp) Method

CollideAABB() public method

public CollideAABB ( ShapeAABB bound2 ) : AABBCollisionResult
bound2 ShapeAABB
return AABBCollisionResult
        public override AABBCollisionResult CollideAABB(ShapeAABB bound2)
        {
            ShapeAABB bound1 = this;

            Vector2 bound1HalfWidths = new Vector2(bound1.Width / 2, bound1.Height / 2);
            Vector2 bound2HalfWidths = new Vector2(bound2.Width / 2, bound2.Height / 2);

            float yMove = 0;
            float xMove = 0;
            float multY = (bound1.Center.Y < bound2.Center.Y) ? -1 : 1;
            float multX = (bound1.Center.X < bound2.Center.X) ? -1 : 1;

            int xCDist = (int)Math.Abs(bound2.Center.X - bound1.Center.X);
            int yCDist = (int)Math.Abs(bound2.Center.Y - bound1.Center.Y);
            xMove = bound1HalfWidths.X + bound2HalfWidths.X - xCDist;
            yMove = bound1HalfWidths.Y + bound2HalfWidths.Y - yCDist;
            //Not colliding. SAT.
            if (yMove < 0 || xMove < 0) return new AABBCollisionResult(0, 0, false, false);

            //if (yMove < xMove && yMove > 0) xMove = 0;
            //else if (xMove < yMove && xMove > 0) yMove = 0;

            return new AABBCollisionResult((int)(xMove * multX), (int)(yMove * multY), xMove < yMove, true);
        }