python - How to get both colliding sprite objects in pygame? -


if collision occurs, there way both objects?

for example:

allsprite = pygame.sprite.group() bullets = pygame.sprite.group() enemies = pygame.sprite.group()  bullet = bullet() enemy = enemy() bullets.add(bullet) enemies.add(enemy)  hits = pygame.sprite.collide(enemies,bullets) hit in hits:     hit.damage() 

this gets enemy object, want both objects because need bullet damage, too.

you can use groupcollide function this: http://www.pygame.org/docs/ref/sprite.html#pygame.sprite.groupcollide

you dictionary of enemies (keys) , each enemy, list of bullets hit (values). can this:

hits = pygame.sprite.groupcollide(enemies, bullets, false, true) enemy in hits:     bullet in hits[enemy]:         enemy.damage(bullet.damage) 

Comments

Popular posts from this blog

ubuntu - PHP script to find files of certain extensions in a directory, returns populated array when run in browser, but empty array when run from terminal -

php - How can i create a user dashboard -

javascript - How to detect toggling of the fullscreen-toolbar in jQuery Mobile? -