From 883e7de77e9268383cb1f5879f4499256795cccb Mon Sep 17 00:00:00 2001 From: Raghuram Subramani Date: Sun, 30 Jul 2023 15:03:53 +0530 Subject: use cockroaches_copy --- game.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'game.py') diff --git a/game.py b/game.py index d041444..0ec5ce0 100644 --- a/game.py +++ b/game.py @@ -57,8 +57,10 @@ class MyGame: self.asteroids.remove(asteroid) def detect_collision(self, x, y): + cockroaches_copy = self.cockroaches.copy() + # Iterate through the list of cockroaches - for cockroach in self.cockroaches: + for cockroach in cockroaches_copy: # Check if the detection rectangle intersects with the cockroach if x < cockroach.x < x + self.w and y < cockroach.y < y + self.h: # Remove the cockroach from the list -- cgit v1.2.3