I think it sounds strange that <> has a higher priority than + -.
Try this:
Code:
if (Position.Y <mViewport.Y)
{
mDirection.Y =-mDirection.Y;
}
if (Position.X <mViewport.X)
{
mDirection.X =-mDirection.X;
}
if (Position.Y> mViewport.Y + mViewport.Height)
{
Position.Y-= 5;
mDirection.Y =-mDirection.Y;
}
if (Position.X> mViewport.X + mViewport.Width)
{
Position.X-= 5;
mDirection.X =-mDirection.X;
}
I can imagine that the problem is that when PX is larger than mV.X + mV.Width, so it stays there even if the direction is changed. Thus, it will only go into the lower block, over and over again, and change direction.
Bookmarks