def _create_raindrop(self, raindrop_number, row_number): """Create a raindrop and place it in the row.""" raindrop = RainDrop(self) raindrop_width, raindrop_height = raindrop.rect.size raindrop.y = raindrop_height + 2 * raindrop_height * row_number raindrop.rect.y = raindrop.y raindrop.rect.x = raindrop.rect.width + \ 2 * raindrop.rect.width * raindrop_number self.raindrops.add(raindrop)
def _create_rain(self): """Create a rain.""" # Create a raindrop and find the number of raindrops in a row. # Spacing between each raindrop is equal to one raindrop width. raindrop = RainDrop(self) raindrop_width, raindrop_height = raindrop.rect.size number_raindrops_x = self.settings.screen_width // (2 * raindrop_width) # Determine the number of rows of raindrops that fit on the screen. number_rows = self.settings.screen_height // (2 * raindrop_height) + 1 # Create a full rain. for row_number in range(number_rows): for raindrop_number in range(number_raindrops_x): self._create_raindrop(raindrop_number, row_number)
def _create_rain(self): """Create the rain 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(self) raindrop_width, raindrop_height = raindrop.rect.size available_space_x = self.settings.screen_width - (2 * raindrop_width) number_raindrops_x = available_space_x // raindrop_width # Determine the number of rows of raindrops that fit on the screen. available_space_y = self.settings.screen_height - 3 * raindrop_height number_rows = available_space_y // (2 * raindrop_height) # Create the full rain of raindrops. for row_number in range(number_rows): for raindrop_number in range(number_raindrops_x): self._create_raindrop(raindrop_number, row_number)
def game_loop(self): while not self.done: for event in pygame.event.get(): self.handle_event(event) if not self.game_over: self.score = pygame.time.get_ticks() - self.init_time collision = pygame.sprite.spritecollideany( (self.wetman.sprites())[0], self.raindrops) if collision is not None: self.game_over = True self.wetman.update(self.man_left, self.man_right) self.raindrops.update() self.raindrops.add(RainDrop(screen_width)) self.draw() self.clock.tick(FRAME_RATE) return self.reset