0

I am currently creating a top down shooter game in pygame and my player is clipping through the corners of both my borders. I have listed my code below and an image of the issue.

Image of problem

#The playerhitbox, boarder 1 and boarder 2

    playerhitbox = pygame.draw.rect(display, (TRANSPARENT), (375, 270, 100, 100), 2)
        boarder1 = pygame.draw.rect(display, (255, 255, 255), (-475-display_scroll[0], 875-display_scroll[1], 1750, 5))
        boarder2 = pygame.draw.rect(display, (255, 255, 255), (-475-display_scroll[0], -675-display_scroll[1], 5, 1550))


#If playerhitbox collides with boarder 's' key has no effect
    if playerhitbox.colliderect(boarder1):
    
                if keys[pygame.K_a]:
                    display_scroll[0] -=5
    
                    player.moving_left = True
    
                    for bullet in player_bullets:
                        bullet.x -= 5
    
                if keys[pygame.K_d]:
                    display_scroll[0] +=5
    
                    player.moving_right = True
    
                    for bullet in player_bullets:
                        bullet.x += 5
    
                if keys[pygame.K_w]:
                    display_scroll[1] -=5
    
                    for bullet in player_bullets:
                        bullet.x -= 5
    
                if keys[pygame.K_s]:
                    display_scroll[1] +=0
    
                    for bullet in player_bullets:
                        bullet.x += 5

#If playerhitbox collides with boarder 'a' key has no effect

    if playerhitbox.colliderect(boarder2):
    
                if keys[pygame.K_a]:
                    display_scroll[0] -=5
    
                    player.moving_left = True
    
                    for bullet in player_bullets:
                        bullet.x -= 5
    
                if keys[pygame.K_d]:
                    display_scroll[0] +=5
    
                    player.moving_right = True
    
                    for bullet in player_bullets:
                        bullet.x += 5
    
                if keys[pygame.K_w]:
                    display_scroll[1] -=5
    
                    for bullet in player_bullets:
                        bullet.x -= 5
    
                if keys[pygame.K_s]:
                    display_scroll[1] +=5
    
                    for bullet in player_bullets:
                        bullet.x += 5

#If there is no collision between boarder and playerhitbox all keys (W, S, A, D) do something.

    else:

            if keys[pygame.K_a]:
                display_scroll[0] -=5

                player.moving_left = True

                for bullet in player_bullets:
                    bullet.x -= 5

            if keys[pygame.K_d]:
                display_scroll[0] +=5

                player.moving_right = True

                for bullet in player_bullets:
                    bullet.x += 5

            if keys[pygame.K_w]:
                display_scroll[1] -=5

                for bullet in player_bullets:
                    bullet.x -= 5

            if keys[pygame.K_s]:
                display_scroll[1] +=5

                for bullet in player_bullets:
                    bullet.x += 5

            if keys[pygame.K_p]:
                pause()
            if keys[pygame.K_m]:
                main_menu()
Jan Wilamowski
  • 3,308
  • 2
  • 10
  • 23
  • 1
    Please provide a [minimal, reproducible example](https://stackoverflow.com/help/minimal-reproducible-example) of your problem, along with the current and expected behavior. At the moment, it's difficult to understand what the problem is. – Jan Wilamowski Sep 16 '22 at 02:14
  • Does this help? I added the code that moves the whole background making it look like the player is moving. Note that the code is the same for the other 3 boarders just with different key values. – Maddox Styles Sep 16 '22 at 02:19
  • Please read through the link I provided. It's currently unclear how your "borders" are set up. Try to reduce the problem as much as possible, i.e. remove everything that isn't necessary to reproduce the issue. By doing this, you may already find out what's going on. – Jan Wilamowski Sep 16 '22 at 02:22
  • Sorry for the late response. Hopefully this makes more sense. – Maddox Styles Sep 16 '22 at 04:13
  • Can anyone help? – Maddox Styles Sep 19 '22 at 08:07

0 Answers0