Thank you for also using the [ code ] tags, it makes it easier to read (and again easier to help you).
One of the reasons why your screen collision might not be working is this:
case SDLK_LEFT: if(player->get_x() >= 10) player->moveHorizontally(-10); break;
You're only checking it when the player clicks the key... but the player can move (from velocity from previous clicks) without clicking the key. You ought to check for screen collision after any position update from velocity, not after any keypress.
Also, when colliding, don't just undo the horizontal movement, but set the player back to a save place.
Imagine this:
- Player (from velocity) moves more than 10 units to the left. Let's say he moves 25 units.
- He goes past the edge of the screen by those 25 units.
- You undo 10 units of movement.
- He's still past the screen by 15!
This is example code that you'll need to adapt:
//Check if the player went past the boundry he wasn't supposed to cross.
if(player->get_x() > LeftScreenBoundry)
{
//Set the player's position to the right position.
player->set_x(LeftScreenBoundry);
//If the player still has velocity in the wrong direction...
if(player->get_x_velocity() > 0)
{
//...cancel further movement in that direction.
player->set_x_velocity(0);
}
}