Exemple #1
0
    def handle_collisions(self):

        # Between bullets and asteroids
        for i, bullet in reverse_enumerate(self.bullets):
            for j, asteroid in reverse_enumerate(self.asteroids):
                if collisions.do_collide(bullet, asteroid):

                    self.bullets = self.bullets[:i] + self.bullets[i + 1:]
                    self.asteroids = self.asteroids[
                        :j] + self.asteroids[j + 1:]

                    self.score += 1
                    break

        if not self.ship.invincible:
            for i, asteroid in enumerate(self.asteroids):
                if collisions.do_collide(self.ship, asteroid):
                    self.ship_collision(i)
                    break  # Do not collide with anymore asteroids
Exemple #2
0
 def maintain_asteroids(self):
     for i, asteroid in reverse_enumerate(self.asteroids):
         if asteroid.time_alive > 1000.0 and not asteroid.in_bounds():
             self.asteroids = self.asteroids[:i] + self.asteroids[i + 1:]
Exemple #3
0
 def maintain_bullets(self):
     for i, bullet in reverse_enumerate(self.bullets):
         if not bullet.in_bounds():
             self.bullets = self.bullets[:i] + self.bullets[i + 1:]