Exemplo n.º 1
0
 def create_asteroids(self):
     """this function load asteroids into asteroids lst"""
     for i in range(self.__asteroids_amount):  # add asteroids to the list
         Asteroid.i = Asteroid(
             random.randint(self.__screen_min_x,self.__screen_max_x),
                     random.randint(self.__screen_min_y,self.__screen_max_y)
                               , random.randint(1, 4), random.randint(1, 4))
         #  if the asteroid has the same location in x add one
         if Asteroid.i.get_x() == self.__ship.get_x():
             Asteroid.i.set_x(Asteroid.get_x() + 1)
         #  if the asteroid has the same location in y add one
         if Asteroid.i.get_y() == self.__ship.get_y():
             Asteroid.i.set_x(Asteroid.get_y() + 1)
         self.__asteroid_lst.append(Asteroid.i)
     for asteroid in self.__asteroid_lst:  # register asteroids
         self.__screen.register_asteroid(asteroid, SIZE3)
Exemplo n.º 2
0
    def create_asteroids(self, asteroids_amnt):
        """
        This method create the asteroids, and check that they are in a
        different position that the ship
        :param asteroids_amnt: number of asteroid we want in the game
        """

        for i in range(asteroids_amnt):
            new_asteroid = Asteroid()

            # Generate a new asteroid until it's on an available place
            while new_asteroid.get_x() == self.ship.get_x() \
                    and new_asteroid.get_y() == self.ship.get_y():
                new_asteroid = Asteroid()

            # Adding the new asteroid
            self._screen.register_asteroid(new_asteroid, MAX_ASTEROID)
            self.asteroids_list.append(new_asteroid)