public bool EnvironmentCollisions(Point position, IMapSquare square, ref Point offset) { offset.X = 0; offset.Y = 0; // some optimizations var tileBox = square.BlockBox; if (box.Right + position.X < tileBox.Left) { return(false); } if (box.Left + position.X > tileBox.Right) { return(false); } var boundBox = BoxAt(position); return(EnvironmentContact(square, tileBox, boundBox, out offset)); }
private bool EnvironmentContact(IMapSquare square, RectangleF tileBox, RectangleF boundBox, out PointF offset) { // can't use intersection, use epsilon offset = PointF.Empty; if (tileBox.Top < boundBox.Top) { if (tileBox.Bottom - boundBox.Top + Const.PixelEpsilon <= 0) return false; } else { if (boundBox.Bottom - tileBox.Top + Const.PixelEpsilon <= 0) return false; } if (tileBox.Left < boundBox.Left) { if (tileBox.Right - boundBox.Left + Const.PixelEpsilon <= 0) return false; } else { if (boundBox.Right - tileBox.Left + Const.PixelEpsilon <= 0) return false; } bool down = (!parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable); bool up = (parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable); if (parentComponent.MovementSrc != null) offset = GetIntersectionOffset(tileBox, boundBox, parentComponent.MovementSrc.VelocityX, parentComponent.MovementSrc.VelocityY, up, down); else offset = GetIntersectionOffset(tileBox, boundBox, 0, 0, up, down); // Quicksand sinking property tells us not to push the hitbox outward if (square.Properties.Sinking > 0) { // don't clip left or right at all offset.X = 0; if (parentComponent.Parent.Container.IsGravityFlipped) { // don't clip them downward out of the collision if (offset.Y > 0) { offset.Y = 0; } } else { // don't clip them upward out of the collision if (offset.Y < 0) { offset.Y = 0; } } } return true; }
public bool EnvironmentCollisions(PointF position, IMapSquare square, ref PointF offset) { offset.X = 0; offset.Y = 0; // some optimizations RectangleF tileBox = square.BlockBox; if (box.Right + position.X < tileBox.Left) return false; if (box.Left + position.X > tileBox.Right) return false; RectangleF boundBox = BoxAt(position); return EnvironmentContact(square, tileBox, boundBox, out offset); }
private bool EnvironmentContact(IMapSquare square, Rectangle tileBox, Rectangle boundBox, out Point offset) { // can't use intersection, use epsilon offset = Point.Empty; if (tileBox.Top < boundBox.Top) { if (tileBox.Bottom - boundBox.Top + Const.PixelEpsilon <= 0) { return(false); } } else { if (boundBox.Bottom - tileBox.Top + Const.PixelEpsilon <= 0) { return(false); } } if (tileBox.Left < boundBox.Left) { if (tileBox.Right - boundBox.Left + Const.PixelEpsilon <= 0) { return(false); } } else { if (boundBox.Right - tileBox.Left + Const.PixelEpsilon <= 0) { return(false); } } bool down = (!parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable); bool up = (parentComponent.Parent.Container.IsGravityFlipped && square.Properties.Climbable); if (parentComponent.MovementSrc != null) { offset = GetIntersectionOffset(tileBox, boundBox, parentComponent.MovementSrc.VelocityX, parentComponent.MovementSrc.VelocityY, up, down); } else { offset = GetIntersectionOffset(tileBox, boundBox, 0, 0, up, down); } // Quicksand sinking property tells us not to push the hitbox outward if (square.Properties.Sinking > 0) { // don't clip left or right at all offset.X = 0; if (parentComponent.Parent.Container.IsGravityFlipped) { // don't clip them downward out of the collision if (offset.Y > 0) { offset.Y = 0; } } else { // don't clip them upward out of the collision if (offset.Y < 0) { offset.Y = 0; } } } return(true); }