0

I'm a newbie at pygame [and python as a whole] and I have been recently playing around with sprites and collision, and currently I'm not sure if you can check for a collision with one sprite going into another instead of just checking for two sprites intersecting.

Is it possible to check for a sprite thats moving/colliding into another sprite with pygame?

EDIT: Heres the collision code that just checks for two sprites intersecting which i dont want, as i cannot specify which hit the other first

        collision = pygame.sprite.collide_rect(player1, player2)
    if collision == True:
            group1.remove(player1, player2)
            pygame.display.set_caption("They destroyed eachother! Press space to retry")
            player1.rect.x = 5
            player1.rect.y = 5
            player2.rect.x = 445
            player2.rect.y = 445
            startanew = True
    if startanew == True and keys[pygame.K_SPACE]:
            group1.add(player1, player2)
            pygame.display.set_caption("Squares Fight!")
Mercury Platinum
  • 1,549
  • 1
  • 15
  • 28
  • Can you show us some of what you've tried? – mypetlion Nov 01 '17 at 17:23
  • Please clarify your specific problem or add additional details to highlight exactly what you need. As it's currently written, it’s hard to tell exactly what you're asking. See the [How to Ask](https://stackoverflow.com/help/how-to-ask) page for help clarifying this question. – skrx Nov 01 '17 at 17:24
  • alright one second – Mercury Platinum Nov 01 '17 at 17:29
  • "as i cannot specify which hit the other first". Colliding sprites don't hit each other first. One frame they were apart and the next they are colliding. You can take the speed of the sprites into account and you can check if the Player sprite hit another sprite. However what you're asking at the moment still isn't fully clear. – Micheal O'Dwyer Nov 01 '17 at 17:46
  • If sprite A hits sprite B first, sprite B will disappear, if sprite B hits sprite A first, sprite A will disappear. – Mercury Platinum Nov 01 '17 at 18:17
  • 1
    All collisions happen simultaneously for all parties involved. That's not pygame, that's just how things work. Are you looking for which one was moving at the time of the collision? Or which was moving faster? – mypetlion Nov 01 '17 at 18:18
  • Alright, then never mind. – Mercury Platinum Nov 01 '17 at 18:22

0 Answers0