Exemplo n.º 1
0
def steady_rain(ai_settings, screen, ship, raindrops):
    # Create a raindrop and find the number of raindrop in a row
    raindrop = Raindrop(ai_settings, screen)
    number_column = get_number_column(ai_settings, ship.rect.width,
                                      raindrop.rect.width)

    # Create a row of raindrops
    for column_number in range(number_column):
        raindrop = Raindrop(ai_settings, screen)
        # Create a random number to randomize the position of the raindrops
        random_number = randint(-60, 60)
        create_item(raindrop, raindrops, 0, column_number, random_number)
Exemplo n.º 2
0
 def _create_drop(self, drop_number, row_number):
     drop = Raindrop(self)
     drop_width, drop_height = drop.rect.size
     drop.rect.x = drop_width + 2 * drop_width * drop_number
     drop.y = 2 * drop.rect.height * row_number
     drop.rect.y = drop.y
     self.raindrops.add(drop)
Exemplo n.º 3
0
def update_screen(ai_settings, screen, raindrops):
    """Update screen."""
    screen.fill(ai_settings.bg_color)
    for raindrop in raindrops.sprites():
        new_raindrop = Raindrop(screen)
    raindrops.draw(screen)
    pygame.display.flip()
def change_grid_direction(ai_settings, raindrops, screen):
    """Move the grid back to the top edge."""
    Raindrop(ai_settings, screen)
    for raindrop in raindrops.sprites():
        if raindrop.rect.y >= ai_settings.screen_height:
            raindrop.y = -raindrop.rect.height
            raindrop.rect.y = raindrop.y
Exemplo n.º 5
0
def create_raindrop(r_settings, screen, raindrops, raindrop_number):
    """Create an raindrops and place it in the row."""
    raindrop = Raindrop(r_settings, screen)
    raindrop_width = raindrop.rect.width
    raindrop.x = raindrop_width + 2 * raindrop_width * raindrop_number
    raindrop.rect.x = raindrop.x
    raindrops.add(raindrop)
Exemplo n.º 6
0
def create_raindrop(ai_settings, screen, raindrops, number):
    # 创建一个雨滴并加入当前行
    raindrop = Raindrop(ai_settings, screen)
    raindrop_width = raindrop.rect.width
    raindrop.x = raindrop_width + 2 * raindrop_width * number
    raindrop.rect.x = raindrop.x
    raindrop.rect.y = raindrop.rect.height
    raindrops.add(raindrop)
Exemplo n.º 7
0
def create_raindrop(ai_settings, screen, raindrops, raindrop_number):
    """Create raindrop object at its location."""
    raindrop = Raindrop(screen)
    raindrop_width = raindrop.rect.width
    raindrop_height = raindrop.rect.height
    raindrop.x = raindrop_width + 2 * raindrop_width * raindrop_number
    raindrop.rect.x = raindrop.x
    raindrops.add(raindrop)
Exemplo n.º 8
0
def create_raindrops(ai_settings, screen, ship, raindrops):
    # Create a grid of raindrops
    # Create a raindrop and find the number of raindrop in a column
    raindrop = Raindrop(ai_settings, screen)
    number_raindrops_y = get_number_items_y(ai_settings, raindrop.rect.height)
    number_column = get_number_column(ai_settings, ship.rect.width,
                                      raindrop.rect.width)

    # Create a grid of raindrops
    for column_number in range(number_column):
        # Create a raindrop and place it in the column
        for raindrop_number in range(number_raindrops_y):
            raindrop = Raindrop(ai_settings, screen)
            # Create a random number to randomize the position of the raindrops
            random_number = randint(-30, 30)
            create_item(raindrop, raindrops, raindrop_number, column_number,
                        random_number)
Exemplo n.º 9
0
def create_grid(ai_settings, screen, raindrops):
    raindrop = Raindrop(screen)
    raindrop_width = raindrop.rect.width
    available_space_x = ai_settings.screen_width - 2 * raindrop_width
    number_raindrops_x = available_space_x // (2 * raindrop_width)
    for raindrop_number in range(number_raindrops_x):
        create_raindrop(ai_settings, screen, raindrops, raindrop_number)
    ai_settings.new_grid = False
Exemplo n.º 10
0
 def _create_drop(self, drop_number, row_number):
     """Create an drop and place it in the row."""
     drop = Raindrop(self)
     drop_width, drop_height = drop.rect.size
     drop.rect.x = drop_width + 2 * drop_width * drop_number
     drop.y = 2 * drop.rect.height * row_number
     drop.rect.y = drop.y
     self.raindrops.add(drop)
 def _create_droplets(self):
     raindrop = Raindrop(self)
     raindrop_width, raindrop_height = raindrop.rect.size
     available_space_horizontally = self.screen_width - (2 * raindrop_width)
     number_drops_fit_horizontally = available_space_horizontally // (
         2 * raindrop_width)
     for drops in range(number_drops_fit_horizontally):
         self._create_drop(drops)
Exemplo n.º 12
0
def create_raindrop(ai_settings, screen, raindrops, raindrop_number, row_number):
    """Create a raindrop and place it in the row."""
    raindrop = Raindrop(ai_settings, screen)
    raindrop_width = raindrop.rect.width
    raindrop.x = raindrop_width + 2 * raindrop_width * raindrop_number
    raindrop.rect.x = raindrop.x
    raindrop.rect.y = raindrop.rect.height + 2 * raindrop.rect.height * row_number
    raindrops.add(raindrop)
Exemplo n.º 13
0
def creat_line_rain(ai_settings, screen, raindrops):
    """Создает дождь."""
    # Создание пришельца и вычисление количества пришельцев в ряду
    drop = Raindrop()
    number_drop_x = get_number_drop_x(ai_settings, drop.rect.width)
    # Создание первого ряда пришельцев.
    for drop_number in range(number_drop_x):
        create_drop(ai_settings, screen, raindrops, drop_number)
def create_raindrop_fleet(screen, raindrops):
    raindrop = Raindrop(screen)
    number_raindrops_x = get_number_raindrops_x(screen, raindrop.rect.width)
    number_raindrops_y = get_number_raindrops_y(screen, raindrop.rect.height)

    for line_number in range(number_raindrops_y):
        for row_number in range(number_raindrops_x):
            create_raindrop(screen, raindrops, row_number, line_number)
def create_raindrop(ayarlar, screen, raindrops, raindrop_number, row_number):
    """Create a raindrop and place it in the row."""
    raindrop = Raindrop(ayarlar, screen)
    raindrop_width = raindrop.rect.width
    raindrop.x = 0.5 * raindrop_width + raindrop_width * raindrop_number
    raindrop.rect.x = raindrop.x
    raindrop.y = 0.5 * raindrop.rect.height + raindrop.rect.height * row_number
    #raindrop.rect.y = raindrop.y # look at line 38 we need to store x direction but why we do not need y direction.
    raindrops.add(raindrop)
Exemplo n.º 16
0
 def _create_raindrop(self, raindrop_number):
     #Create a raindrop and place it in the game surface.
     raindrop = Raindrop(self)
     raindrop_width, raindrop_height = raindrop.rect.size
     raindrop.x = (randint(0, self.settings.screen_width - raindrop_width))
     raindrop.rect.x = raindrop.x
     raindrop.rect.y = randint(
         0, (self.settings.screen_height - raindrop_height))
     self.raindrops.add(raindrop)
Exemplo n.º 17
0
    def _create_raindrop(self, raindrops_num, raindrop_row):
        raindrop = Raindrop(self)
        raindrop_width, raindrop_height = raindrop.rect.size

        raindrop.x = raindrop_width + 2 * raindrop_width * raindrops_num
        raindrop.rect.x = raindrop.x

        raindrop.rect.y = raindrop.rect.height + 2 * raindrop.rect.height * raindrop_row
        self.raindrops.add(raindrop)
def create_raindrop(screen, raindrops, row_number, line_number):
    raindrop = Raindrop(screen)
    raindrop_width = raindrop.rect.width
    raindrop_height = raindrop.rect.height
    raindrop.x = raindrop_width + 2 * raindrop_width * row_number
    raindrop.y = raindrop_height + 2 * raindrop_height * line_number
    raindrop.rect.x = raindrop.x
    raindrop.rect.y = raindrop.y
    raindrops.add(raindrop)
Exemplo n.º 19
0
def create_row(r_settings, screen, raindrops):
    """Create a full row of raindrops."""
    # Create an raindrop and find the number of raindrops in a row.
    raindrop = Raindrop(r_settings, screen)
    number_raindrops_x = get_number_raindrops_x(r_settings,
                                                raindrop.rect.width)
    # Create the row of raindrops.
    for raindrop_number in range(number_raindrops_x):
        create_raindrop(r_settings, screen, raindrops, raindrop_number)
Exemplo n.º 20
0
    def handle_event(self, event):
        if event.type == self.ADDRAINDROP:
            new_raindrop = Raindrop()
            self.raindrops.add(new_raindrop)
            self.all_sprites.add(new_raindrop)
            self.obstacles.add(new_raindrop)

        pressed_keys = pygame.key.get_pressed()
        self.player.handle_keys(pressed_keys)
Exemplo n.º 21
0
    def _create_drop(self, drop_number):
        new_drop = Raindrop(self)
        drop_width, drop_height = new_drop.rect.size
        new_drop.x = drop_number * drop_width * 2 + self._get_raincloud_buffer(
        ) // 2 + 2 * drop_width

        new_drop.rect.x = int(new_drop.x)
        new_drop.rect.y = self._get_drop_start_y()

        self.drops.add(new_drop)
Exemplo n.º 22
0
def create_raindrop(screen, myset, raindrops, x_number, y_number):
    """ 创建单个雨滴 """
    raindrop = Raindrop(screen, myset)
    h = raindrop.rect.height
    w = raindrop.rect.width
    raindrop.rect.x = w + 2 * x_number * w
    raindrop.x = raindrop.rect.x
    raindrop.rect.y = h + 2 * y_number * h
    raindrop.y = raindrop.rect.y
    raindrops.add(raindrop)
def create_fleet(ai_settings, screen, raindrops):
    """Create a full fleet of raindrops."""
    # Create an raindrop and find the number of raindrops in a row. 
    raindrop = Raindrop(ai_settings, screen)
    number_raindrops_x = get_number_raindrops_x(ai_settings, raindrop.rect.width)
    number_rows = get_number_rows(ai_settings, raindrop.rect.height)

    # Create the fleet of raindrops.
    for row_number in range(number_rows):
        for raindrop_number in range(number_raindrops_x):
            create_raindrop(ai_settings, screen, raindrops, raindrop_number, row_number)
Exemplo n.º 24
0
def create_raindrop(ai_settings, screen, storm, raindrop_number,
                    raindrop_width, row_number):
    # Create alien and place it in a row
    raindrop = Raindrop(ai_settings, screen)
    raindrop.x = raindrop_width + 2 * raindrop_width * raindrop_number
    # x stores where the raindrop should be, raindrop rect object will move it on the screen
    raindrop.rect.x = raindrop.x
    # Need to update raindrop y, alien does not have a y attribute
    raindrop.y = raindrop.rect.height + 2 * raindrop.rect.height * row_number
    raindrop.rect.y = raindrop.y
    storm.add(raindrop)
def create_one_row_fleet(ayarlar, screen, raindrops):
    """Create a only one row raindrop fleet."""
    for row_number in range(1):
        for raindrop_number in range(7):
            raindrop = Raindrop(ayarlar, screen)
            raindrop_width = raindrop.rect.width
            raindrop.x = 0.5 * raindrop_width + raindrop_width * raindrop_number
            raindrop.rect.x = raindrop.x
            raindrop.y = 0  #0.1 * raindrop.rect.height #+ raindrop.rect.height * row_number
            #raindrop.rect.y = raindrop.y # look at line 38 we need to store x direction but why we do not need y direction.
            raindrops.add(raindrop)
Exemplo n.º 26
0
def create_storm(ai_settings, screen, storm):
    """Create a full fleet of alieans."""
    # Create an alien and find the number of aliens in a row
    # Spacing between each alien is euqal to one alien width
    raindrop = Raindrop(ai_settings, screen)
    raindrop_width = raindrop.rect.width
    number_raindrops_x = get_number_raindrops_x(ai_settings, raindrop_width)
    number_rows = get_number_rows(ai_settings, raindrop.rect.height)

    for row_number in range(number_rows):
        for raindrop_number in range(number_raindrops_x):
            create_raindrop(ai_settings, screen, storm, raindrop_number,
                            raindrop_width, row_number)
def create_grid(ai_settings, screen, ship, raindrops):
    """Create a grid of raindrops."""
    # Create a raindrop and find the number of raindrops in a row.
    # Spacing between each raindrop is equal to one raindrop width.
    raindrop = Raindrop(ai_settings, screen)
    number_raindrops_x = get_number_raindrops_x(ai_settings,
                                                raindrop.rect.width)
    number_rows = get_number_rows(ai_settings, ship.rect.height)

    for row_number in range(number_rows):
        for raindrop_number in range(number_raindrops_x):
            create_raindrop(ai_settings, raindrops, screen, raindrop_number,
                            row_number)
Exemplo n.º 28
0
    def _create_drops(self):
        drop = Raindrop(self)
        drop_width, drop_height = drop.rect.size
        available_space_x = self.settings.screen_width - drop_width

        self.number_drops_x = available_space_x // (2 * drop_width)

        available_space_y = self.settings.screen_height

        number_rows = available_space_y // (2 * drop_height)

        for row_number in range(number_rows):
            self._create_row(row_number)
Exemplo n.º 29
0
def creatd_fleet(myset, screen, raindrops, noline=True):
    """ 创建雨滴群 默认生成全屏雨滴,如果noline = false, 则生成一行雨滴 """
    raindrop = Raindrop(screen, myset)
    rain_width = raindrop.rect.width
    rain_height = raindrop.rect.height
    x_number = get_raindrop_x_number(rain_width, myset)
    if noline:
        y_number = get_raindrop_y_number(rain_height, myset)
    else:
        y_number = 1

    for y in range(y_number):
        for x in range(x_number):
            create_raindrop(screen, myset, raindrops, x, y)
Exemplo n.º 30
0
def create_fleet(screen, settings, raindrops):
    """Create a full fleet of raindrops."""
    # Create an raindrop and find the number of raindrops in a row.
    # Spacing between each raindrop is equal to one raindrop width.
    raindrop = Raindrop(screen, settings)
    number_raindrops_x = get_number_raindrops_x(settings, raindrop.rect.width)
    number_rows = get_number_rows(settings, raindrop.rect.height)

    # Create the first row of raindrops.
    for row_number in range(number_rows):
        for raindrop_number in range(number_raindrops_x):
            # Create an raindrop and place it in the row.
            create_raindrop(screen, settings, raindrops, raindrop_number,
                            row_number)