So i want my player to not be able to pass through the block, but it teleports to the other side, any idea why? here's my code:
def update(self, collidable):
self.rect.x += self.hspeed
collision_list = pygame.sprite.spritecollide(self, collidable, False)
for collided_object in collision_list:
if (self.hspeed > 0):
# right direction
self.rect.right = collided_object.rect.left
elif (self.hspeed < 0):
# left direction
self.rect.left = collided_object.rect.right
self.rect.y += self.vspeed
collision_list = pygame.sprite.spritecollide(self, collidable, False)
for collided_object in collision_list:
if (self.vspeed > 0):
# down direction
self.rect.bottom = collided_object.rect.up
elif (self.vspeed < 0):
# up direction
self.rect.top = collided_object.rect.bottom
Thanks alot in advance!