A better method is to collide like a square.
The key to doing this is to check in front of the CORNERS of the player's hit-box instead of checking in front of the player's center.
For example, when moving right, you would check two locations. First, you figure out where the top-right corner is, then you add the horizontal movement speed to see where that corner WILL BE on the next frame. If that location is a wall, you set the horizontal movement to Zero, preventing movement in that direction. You also check to see where the bottom-right corner will be on the next frame. Basically, if either one of those corners is about to hit a wall, you tell the player to stop moving horizontally.
If the player is moving up, you check where the top-left and top-right corners are going to be on the next frame. If either of those locations is a wall, you set their vertical movement to zero, which makes them stop before entering a wall.
Because each check involves looking at two points. I sometimes call this "2-point collision"Use arrow keys to move the box.Download Source