I implemented a game mode in my alien onslaught game made with python and pygame and the concept is like this: Players are fighting aliens but each player has a limited number of bullets. When a player remains out of bullets he becomes inactive and, the game ends when both players run out of bullets. The method that handles what happens with the players when they run out of bullets is like this:
def last_bullet(self, thunderbird, phoenix):
"""Starts the Last Bullet game mode in which the players must fight aliens
but they have a limited number of bullets, when a player remains with no bullets
he dies, when both players are out of bullets, the game is over."""
for player in [thunderbird, phoenix]:
if player.remaining_bullets <= 0:
player.state.alive = False
if all(not player.state.alive for player in [thunderbird, phoenix]):
self.stats.game_active = False
But there is the case in which the player shoots his last bullet to kill the last alien remaining on the screen and if that alien is destroyed, the player should not become inactive and I don't know how to implement that. What kind of condition I should add to determine if the player becomes inactive beside the number of bullets? I tried to check the number of aliens remaining, and if it is higher than 1, the player should become inactive because he can t kill them with the last bullet. I also had the idea of reviving the player if after shooting his last bullet, the last alien died and the level progressed. Any ideas of how should I go about this?