-1

I have been trying to make to rectangles collide. I tried using a while loop in the 3rd statement of the method, but python would end up freezing. Any suggestions?

def update(self):
    """This method controls the movement of David."""

    if self.jump_up:
        self.jumping_animate()
        self.y -= self.settings.david_jump_height

    if self.jump_up == False:
        self.y += self.settings.david_fall_down
        self.fall_animate()

    if self.rect.colliderect(self.platform.rect):
        self.rect.y += 0


    if self.moving_left and self.rect.left > 0:
        self.animate_left()
        self.x -= self.settings.david_speed


    if self.moving_right and self.rect.right < self.screen_rect.right:
        self.animate_right()
        self.x += self.settings.david_speed

    self.rect.x = self.x
    self.rect.y = self.y
  • 1
    `self.rect.y` should be updated before the collision detection. – Rabbid76 Oct 18 '21 at 20:18
  • when doing `self.rect.y += 0` you are not changing anything. if you want to move David to the top of the platform when he collides, you should do `self.rect.bottom = self.platform.rect.top` – Kesslwovv Oct 23 '21 at 18:57

0 Answers0