I suspect you are using a tile map, in which case on of the solution would be to do it based on tile indices. You need to find on what tile your monster currently is on, with the following formulas:
int tileX = (int)(monster.Position.X / TILE_WIDTH);
int tileY = (int(monster.Position.Y / TILE_HEIGHT);
Once you know these, you have to find in which X direction you're going (in order to check for blocks ahead):
int direction = 0;
if (monster.Velocity > 0f)
direction = 1;
if (monster.Velocity < 0f)
direction = -1;
Now you have a normalized X direction to work with.
Next, you'll want to check the blocks around to see if you should change direction:
if (GetTileCollision(tileX + direction, tileY) == TileCollision.Impassable || // going into a wall
GetTileCollision(tileX + direction, tileY) == TIleCollision.Passable &&
GetTileCollision(tileX + direction, tileY + 1) == TileCollision.Passable)) // we're going to fall down a block
ChangeDirection(); // we change direction
You get the general idea. Make sure that you return
TileCollision.Impassable (or whatever) if the tile indices are outside the map, to prevent your program from crashing with an invalid index, and it also prevents monsters from going outside of the map.
I guess it really depends on the way you handle tiles but this is the solution that worked for me.
Based on the tutorials off http://www.sgtconker.com/ (although the website is down as I write this)