Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //NOTE: THE BELOW WILL ONLY WORK in POSITIVE Y quadrants
- foreach (Entities.Mobile mobile in Game1.registry.Mobiles)
- {
- if (mobile.bounds.Contains((int)Position.X, (int)Position.Y))
- {
- if (LastPos.X > mobile.bounds.Right)
- {
- if (mobile.bounds.Top < LastPos.Y && LastPos.Y < mobile.bounds.Bottom)
- {
- BounceVert(mobile.bounds.Right);
- }
- else
- {
- Vector2 crosspoint = new Vector2();
- crosspoint.X = mobile.bounds.Right;
- crosspoint.Y = (Position.X / crosspoint.X) * Position.Y;
- if (crosspoint.Y > mobile.bounds.Top)
- {
- if (crosspoint.Y < mobile.bounds.Bottom)
- BounceVert(mobile.bounds.Right);
- else
- BounceHorz(mobile.bounds.Bottom);
- }
- else
- BounceHorz(mobile.bounds.Top);
- }
- }
- else if (LastPos.X < mobile.Position.X)
- {
- if (mobile.bounds.Top < LastPos.Y && LastPos.Y < mobile.bounds.Bottom)
- {
- BounceVert(mobile.bounds.Left);
- }
- else
- {
- Vector2 crosspoint = new Vector2();
- crosspoint.X = mobile.bounds.Left;
- crosspoint.Y = (crosspoint.X / Position.X) * Position.Y;
- if (crosspoint.Y > mobile.bounds.Top)
- {
- if (crosspoint.Y < mobile.bounds.Bottom)
- BounceVert(mobile.bounds.Left);
- else
- BounceHorz(mobile.bounds.Bottom);
- }
- else
- BounceHorz(mobile.bounds.Top);
- }
- }
- else
- {
- if (LastPos.Y < mobile.bounds.Top)
- {
- BounceHorz(mobile.bounds.Top);
- }
- else
- {
- BounceHorz(mobile.bounds.Bottom);
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement