Skip to content
Advertisement

Pygame, Collision between 2 objects in the same group

So, i am trying to create a game where aliens spawn from 3 specific places. Each Alien will spawn randomly in one of the 3. But there will always be at least one alien, that will spawn on top of another one. I want to delete that alien and spawn him randomly in another spawn point. If it is empty he will stay if not the process will be repeated. The thing is that i cannot find a way to detect collision of 2 objects that are in the same group.

I just started learning pygame so 1) My question may be stupid 2) My way of spawning probably is very inefficient

Here is the Alien class:

JavaScript

And here is the part where i detect collision(This part doesnt work)

JavaScript

Advertisement

Answer

Here is an implementation of the Bounding Box test.

JavaScript
User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement