So I am trying to work a little bit with simple animations and collisions in pygame.I’m trying to make a rectangle appear at the beginning(or end) once it gets off the border, but even if my approach works when dealing with the y coordinate, it miserably fails with the x-axis.However I cannot quite get why.
This is the piece of code that probably causes trouble
def movement():
keys_pressed = pygame.key.get_pressed()
if keys_pressed[pygame.K_a]:
red_rect.x -= vel
if keys_pressed[pygame.K_d]:
red_rect.x += vel
if keys_pressed[pygame.K_w]:
red_rect.y -= vel
if keys_pressed[pygame.K_s]:
red_rect.y += vel
if (red_rect.x) == 600:
red_rect.x = 0
if red_rect.x == 0:
red_rect.x = 600
if red_rect.y == 600:
red_rect.y = 0
if red_rect.y == -40:
red_rect.y = 600
Could also someone tell me ho to make appear on the other side the portion off the other border(the rectangle shouldn't change immediately position so that the transition is smoother) Thank you for any tip or answer