From efe263d6ac5c2e8fc08eb2e7781aef3622e48d95 Mon Sep 17 00:00:00 2001 From: Ike Hecht Date: Sun, 23 Aug 2026 15:32:49 -0400 Subject: [PATCH] Fix ZeroDivisionError in Particle.update() when particle lifetime reaches 0 Once a particle's countdown hit 0, the fade computation divided by zero, crashing the game during normal play after asteroid explosions. Clamp alpha to 0 once the particle is expired, matching the pattern already used in particle.py. Fixes SLOP-450 Co-authored-by: Cursor --- asteroids_game.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/asteroids_game.py b/asteroids_game.py index 0ce6218..92d9f0e 100644 --- a/asteroids_game.py +++ b/asteroids_game.py @@ -43,7 +43,10 @@ def update(self): self.position[1] += self.velocity[1] self.lifetime -= 1 # Fade out effect - self.alpha = max(0, self.alpha - (255 / self.lifetime)) + if self.lifetime > 0: + self.alpha = max(0, self.alpha - (255 / self.lifetime)) + else: + self.alpha = 0 def draw(self, surface): color_with_alpha = self.color + (self.alpha,) # Add alpha to color