Thanks.
void HandleCollisions() {
Rectangle bounds = BoundingRectangle;
int topTile = (int)Math.Floor((float)bounds.Top / World.PixelTileSize);
int bottomTile = (int)Math.Ceiling((float)bounds.Bottom / World.PixelTileSize) - 1;
int leftTile = (int)Math.Floor((float)bounds.Left / World.PixelTileSize);
int rightTile = (int)Math.Ceiling((float)bounds.Right / World.PixelTileSize) - 1;
isOnGround = false;
for(int x = leftTile; x <= rightTile; x++) {
for(int y = topTile; y <= bottomTile; y++) {
if(world.Map[y, x].Collidable == true) {
Rectangle tileBounds =
Rectangle tileBounds = new Rectangle(x * World.PixelTileSize, y * World.PixelTileSize,
World.PixelTileSize, World.PixelTileSize);
Vector2 depth = RectangleExtensions.GetIntersectionDepth(bounds,
tileBounds);
if(depth != Vector2.Zero) {
if(Math.Abs(depth.Y) < Math.Abs(depth.X)) {
isOnGround = true;
position = new Vector2(position.X, position.Y + depth.Y);
}
else {
position = new Vector2(position.X + depth.X, position.Y);
}
bounds = BoundingRectangle;
}
}
}
}
...
}