I have created a small program in pygame where the player controls a blue square moving around the screen, but I want to stop the player from moving past the edge of the scr
if pressed[pygame.K_UP]:
if not (y > maxwidth or y < 0):
y += 5
And so on for the others. the maxwidth looks like 600 in your code but I'd put it at the top of your code so you dont keep having to change it in different places.