I have a Background Class, that looks like this:
class Background(pygame.sprite.Sprite):
def __init__(self):
super().__init__()
self.left = Background_Line(10, WIN_HEIGHT, 175, 0)
self.right = Background_Line(10, WIN_HEIGHT, 450, 0)
self.base = Background_Line(275, 5, 175, WIN_HEIGHT - 5)
background.add(self.left, self.right, self.base)
It is composed of three lines, that form a shape like this |_|
I am trying to implement a collision, such that when the player collides with one of these I am able to respond differently. e.g, if the left line is collided with, the player cannot move left, etc. This is my Background_Line class:
class Background_Line(pygame.sprite.Sprite):
def __init__(self, width, height, posX, posY):
super().__init__()
self.image = pygame.Surface([width, height])
self.image.fill(RED)
self.rect = self.image.get_rect()
self.rect.x = posX
self.rect.y = posY
Currently I am using sprite groups to detect collision between the player and the background. Each background line is stored as an individual sprite in a sprite group. However, my specific issue is that upon collision I do not know how to determine which of these lines have been collided with. I have looked through the Pycharm debugger but am finding it very confusing. A possible solution I have come up with is to just store them separately in individual sprite groups (e.g, left_background sprite group, right_background sprite group) but this doesn't seem very elegant, and would not be viable if I wanted to expand the size of the background.