I'd rather not read through all of this code so I'll tell you this.
1. This code is really sloppy, there are lots of tips on making a game with pygame in the pygame tutorials here on this forum, I'd recommend you to go check those out.
2. To keep a player from going outside the screen, it depends on if they're left, right, up, or down, but for up, just check if the second value of they're rect, y-value, is less than 0, if so then set it back to 0. This creates the effect that they can't move beyond the walls of the pygame window.
1. This code is really sloppy, there are lots of tips on making a game with pygame in the pygame tutorials here on this forum, I'd recommend you to go check those out.
2. To keep a player from going outside the screen, it depends on if they're left, right, up, or down, but for up, just check if the second value of they're rect, y-value, is less than 0, if so then set it back to 0. This creates the effect that they can't move beyond the walls of the pygame window.