I'm creating a battle simulator of a game (a rip-off of Undertale) in Pygame, the 2D game is a heart that is able to choose stuff and run away from projectiles. I created a sprite class of a bullet. So a sequence of bullets is created without a name:
bullet_group = pygame.sprite.Group()
bullet_group.add(Bullet(blah, blah, blah))
-and has an initial x and y position and a velocity towards the end of the screen. When it touches the edge it gets killed, which is updated in the update function of the Bullet sprite class:
if self.direction == "right":
self.rect.x += self.speed
if self.rect.x >= WIDTH:
pygame.sprite.Sprite.kill(self)
I have a separate counter and delay time between each bullet and a quantity, speed, and direction.
I tried to make a function using those values, however it is incomplete as I do not know how I can detect if the last sprite (of this input quantity of sprites) is killed. I need to know this because I want to go back to the battle menu (for choosing stuff) after the battle (running away from projectiles). How do I know if the last sprite is killed without using len(bullet_group). len(bullet_group) doesnt work at high projectile speeds, or long delays. There are other processes (like the heart dodging the projectiles), functions like time.sleep() doesn't work in this case.