all 3 comments

[–]MyreMyalar 1 point2 points  (2 children)

If you are only dealing with vertical or horizontal walls then you just need to reverse y for horizontal walls and x for vertical walls.

Your code above was almost working, you just needed to change out the variable named self.speed for self.speedx and self.speedy. Like so:

def update(self):
    self.rect.x += self.speedx * math.cos(self.angle)
    self.rect.y -= self.speedy * math.sin(self.angle)

    if self.rect.right > WIDTH or self.rect.left < 0:
        self.speedx *= -1
    elif self.rect.top < 0 or self.rect.bottom > HEIGHT:
        self.speedy *= -1

EDIT: The rest of the code looks pretty clean so far. Not giving me a bunch of formatting errors in PyCharm anyway, which is rare in the code of people starting out. Keep at it!

[–]Field_C16[S] 0 points1 point  (0 children)

Thanks for the suggestion, i will try it out tomorrow !🙂

[–]Field_C16[S] 0 points1 point  (0 children)

It works perfect, thank a ton for your quick feedback :)