public bool IntersectsHorizontalWith(Box2d box2d) { if (this.Right < box2d.X) { return(false); } if (box2d.Right < this.X) { return(false); } return(true); }
internal bool IntersectsVerticalWith(Box2d box2d) { if (this.Bottom < box2d.Y) { return(false); } if (box2d.Bottom < this.Y) { return(false); } return(true); }
public bool IntersectsWith(Box2d box2d) { if (this.Right < box2d.X) { return(false); } if (box2d.Right < this.X) { return(false); } if (this.Bottom < box2d.Y) { return(false); } if (box2d.Bottom < this.Y) { return(false); } return(true); }
public override void OnCollideWithStaticBody(float elapsedTime, Body body, Body staticBody) { Vector2d position = body.Position; Vector2d velocity = body.Velocity; Box2d bodyBox = body.Box2D; Box2d stBdBox = staticBody.Box2D; double elasticity = body.Elasticity + staticBody.Elasticity; if (velocity.X > 0) { double b = bodyBox.Right - stBdBox.X; if ((bodyBox.Width * bodyBox.Width) > (b * b)) { position.X = position.X - b; velocity.X = velocity.X * -elasticity; velocity.Y = velocity.Y * (1 - staticBody.Friction); } } else if (velocity.X < -4) { double b = stBdBox.Right - bodyBox.X; if ((bodyBox.Width * bodyBox.Width) > (b * b)) { position.X = position.X + b; velocity.X = velocity.X * -elasticity; velocity.Y = velocity.Y * (1 - staticBody.Friction); } } else { double b = stBdBox.Right - bodyBox.X; if ((bodyBox.Width * bodyBox.Width) > (b * b)) { position.X = position.X + b; velocity.X = 0; velocity.Y = velocity.Y * (1 - staticBody.Friction); } } if (velocity.Y > 0) { double b = bodyBox.Bottom - stBdBox.Y; if ((bodyBox.Height * bodyBox.Height) > (b * b)) { position.Y = position.Y - b; velocity.Y = velocity.Y * -elasticity; velocity.X = velocity.X * (1 - staticBody.Friction); } } else if (velocity.Y < -4) { double b = stBdBox.Bottom - bodyBox.Y; if ((bodyBox.Height * bodyBox.Height) > (b * b)) { position.Y = position.Y + b; velocity.Y = velocity.Y * -elasticity; velocity.X = velocity.X * (1 - staticBody.Friction); } } else { double b = stBdBox.Bottom - bodyBox.Y; if ((bodyBox.Height * bodyBox.Height) > (b * b)) { position.Y = position.Y + b; velocity.Y = 0; velocity.X = velocity.X * (1 - staticBody.Friction); } } body.Position = position; body.Velocity = velocity; //body.Velocity = new Vector2d( // body.Velocity.X * (1 - staticBody.Friction), // body.Velocity.Y > 0 ? body.Velocity.Y * -0.8d : body.Velocity.Y // ); }