I have an image of a car. I want it to stay inside the game window when I move it around. But it seems like there's an invisible extension to the top and the left. I use KEYUP and KEYDOWN events to set the flags true or false. I expected this code to work:
if car_r and red_rect.right < screen_rect.right:
red_rect.centerx += 10
if car_l and red_rect.left > screen_rect.left:
red_rect.centerx -= 10
if car_u and red_rect.top > screen_rect.top:
red_rect.centery -= 10
if car_d and red_rect.bottom < screen_rect.bottom:
red_rect.centery += 10
but instead I had to correct it to work properly:
if car_r and red_rect.centerx + 64 < screen_rect.right:
red_rect.centerx += 10
if car_l and red_rect.centerx > screen_rect.left:
red_rect.centerx -= 10
if car_u and red_rect.centery > screen_rect.top:
red_rect.centery -= 10
if car_d and red_rect.centery + 130 < screen_rect.bottom:
red_rect.centery += 10
What am I missing here?