I am currently creating a top down shooter arcade game in Pygame and my player (the spaceship) is clipping through the corners of both my borders (where both boarders intersect). I have listed my code below and an image of the issue as well as the codes that I tried that didn't work.
Thanks.
#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
I have tried...
if playerhitbox.colliderect(boarder1) and playerhitbox.colliderect(boarder2):
#do something
and
if playerhitbox.colliderect(boarder1):
if playerhitbox.colliderect(boarder2):
#do something
Which didn't work