Search code examples
pythonpgzero

How to add wrapping in pygame/pygame zero


If you can I would like the wrapping to be an add-on to the code I have already, as this code I know works seamlessly and smoothing going from one side to the other. Basically the code I have allows wrapping from the bottom side to the top and from the right side to the left but NOT the left side to the right and the top side to the bottom. I have tried several things based off of what I have already and all seem to either effect the code I have already or just not work. Here's the code:

    if player.left > WIDTH: #if player hits right side of screen it takes the player to the left
        player.right = 0
    elif player.top > HEIGHT: #if player hits bottom it goes to top
        player.bottom = 0

All help is appreciated thankyou!


Solution

  • you need to add conditions for these cases:

        if player.left > WIDTH:
            player.right = 0
        elif player.right < 0:  # if the player leaves to the left
            player.left = WIDTH
        elif player.top > HEIGHT:
            player.bottom = 0
        elif player.bottom < 0:  # if the player leaves to the right
            player.top = HEIGHT