Python settings.Settings() Examples
The following are 30
code examples of settings.Settings().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
settings
, or try the search function
.
Example #1
Source File: game_functions.py From alien-invasion-game with MIT License | 6 votes |
def ship_hit(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Respond to ship being hit by an alien.""" if stats.ships_left > 0: # Decrement ships left. stats.ships_left -= 1 # Update scorecard. game_items.sb.prep_ships() # Empty bullets and aliens. game_items.bullets.empty() game_items.aliens.empty() # Create a new fleet and center the ship. create_fleet(ai_settings, game_items) game_items.ship.center_ship() # Pause. time.sleep(0.5) else: stats.game_active = False pygame.mouse.set_visible(True)
Example #2
Source File: game_functions.py From alien-invasion-game with MIT License | 6 votes |
def check_bullet_alien_collision(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update the game when a bullet hits an alien(s).""" # Get rid of bullet and aliens that have collided. collision = pygame.sprite.groupcollide(game_items.bullets, game_items.aliens, True, True) if collision: for aliens_hit_list in collision.values(): stats.score += ai_settings.alien_points * len(aliens_hit_list) game_items.sb.prep_score() check_high_score(stats, game_items) # Create new fleet after fleet is empty. if len(game_items.aliens.sprites()) == 0: game_items.bullets.empty() ai_settings.increase_speed() stats.level += 1 game_items.sb.prep_level() create_fleet(ai_settings, game_items)
Example #3
Source File: scorecard.py From alien-invasion-game with MIT License | 6 votes |
def __init__(self, ai_settings: Settings, stats: GameStats, screen: pygame.SurfaceType): self.screen = screen self.screen_rect = screen.get_rect() self.ai_settings = ai_settings self.stats = stats self.score_ship_size = self.ai_settings.score_ship_size # size of ship in the scoreboard. self.dur_highscore_msg = 3000 # duration of highscore msg = 3 sec # Font settings. font_name = 'fonts/PoiretOne.ttf' # try changing the font self.font_color = self.ai_settings.score_font_color self.font = pygame.font.Font(font_name, self.ai_settings.score_font_size) # Prepare the initial score image. self.prep_images()
Example #4
Source File: plugin.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 6 votes |
def __init__(self, reader, writer, token): super().__init__(Platform.HumbleBundle, __version__, reader, writer, token) self._api = AuthorizedHumbleAPI() self._download_resolver = HumbleDownloadResolver() self._app_finder = AppFinder() self._settings = Settings() self._library_resolver = None self._subscription_months: List[ChoiceMonth] = [] self._owned_games: t.Dict[str, HumbleGame] = {} self._trove_games: t.Dict[str, TroveGame] = {} self._choice_games: t.Dict[str, ChoiceGame] = {} self._local_games = {} self._cached_game_states = {} self._getting_owned_games = asyncio.Lock() self._owned_check: asyncio.Task = asyncio.create_task(asyncio.sleep(8)) self._statuses_check: asyncio.Task = asyncio.create_task(asyncio.sleep(4)) self._installed_check: asyncio.Task = asyncio.create_task(asyncio.sleep(4)) self._rescan_needed = True self._under_installation = set()
Example #5
Source File: game_functions.py From alien-invasion-game with MIT License | 6 votes |
def check_keydown_events(event: EventType, ai_settings: Settings , stats: GameStats, game_items: GameItems): """Respond when key is being pressed.""" if event.key == pygame.K_RIGHT: # Move ship to the right. game_items.ship.moving_right = True elif event.key == pygame.K_LEFT: # Move ship to the left. game_items.ship.moving_left = True elif event.key == pygame.K_SPACE: fire_bullet(ai_settings, game_items) elif event.key == pygame.K_q: quit_game(stats) elif event.key == pygame.K_RETURN: # ENTER key start_new_game(ai_settings, stats, game_items)
Example #6
Source File: game_stats.py From alien-invasion-game with MIT License | 6 votes |
def __init__(self, ai_settings: Settings): self.ai_settings = ai_settings self.ships_left = self.ai_settings.ship_left self.score = 0 self.level = 1 self.time_to_blit = None self.broke_highscore = False self.game_active = False filename = 'save/highscore.txt' try: with open(filename, 'r') as f: self.prev_high_score = int(f.read()) except FileNotFoundError: print('No save file found.') print("Creating new save file 'save/highscore.txt'") if not os.path.exists('save'): os.makedirs('save') with open('save/highscore.txt', 'w+') as f: f.write('0') self.prev_high_score = 0 self.high_score = self.prev_high_score self.time_passed = 0.0
Example #7
Source File: game_functions.py From alien-invasion-game with MIT License | 6 votes |
def check_events(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Respond to keypresses and mouse events.""" # Watch for keyboard and mouse events. for event in pygame.event.get(): if event.type == pygame.QUIT: quit_game(stats) elif event.type == pygame.KEYDOWN: check_keydown_events(event, ai_settings, stats, game_items) elif event.type == pygame.KEYUP: check_keyup_events(event, game_items.ship) elif event.type == pygame.MOUSEBUTTONDOWN: check_mousedown_events(ai_settings, stats, game_items)
Example #8
Source File: bullets.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, screen: pygame.SurfaceType, ship: Ship): """Create a bullet object at the ship's current position.""" super().__init__() self.screen = screen # Create a bullet rect at (0, 0) and then set its position. self.rect = pygame.Rect(0, 0, ai_settings.bullet_width, ai_settings.bullet_height) self.rect.centerx = ship.rect.centerx self.rect.top = ship.rect.centery # Store the bullet's position as float. self.y = float(self.rect.y) self.color = ai_settings.bullet_color self.speed_factor = ai_settings.bullet_speed_factor
Example #9
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def get_number_rows(ai_settings: Settings, ship_height: int, alien_height: int): """Return number of rows of aliens that can fit vertically.""" available_space_y = (ai_settings.screen_height - alien_height * ai_settings.alien_ship_dist_factor - alien_height - ship_height) number_rows = available_space_y / (alien_height * ai_settings.alien_density_factor_y) return int(number_rows)
Example #10
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def change_fleet_directions(ai_settings: Settings, aliens: Group, direction: int): """Drop down the fleet and change the direction.""" for alien in aliens: if alien.y <= alien.drop_dist: ai_settings.alien_direction_y = 1 ai_settings.alien_direction_x = 0 else: ai_settings.alien_direction_y = 0 ai_settings.alien_direction_x = direction
Example #11
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def check_fleet_edges(ai_settings: Settings, aliens: Group): """Respond appropriately when any alien reaches edge.""" for alien in aliens: if alien.check_edges('left'): change_fleet_directions(ai_settings, aliens, direction=+1) break elif alien.check_edges('right'): change_fleet_directions(ai_settings, aliens, direction=-1) break
Example #12
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def create_fleet(ai_settings: Settings, game_items: GameItems): """Create a full fleet of aliens.""" alien = Alien(ai_settings, game_items.screen) number_aliens_x = get_number_aliens_x(ai_settings, alien.rect.width) number_rows = get_number_rows(ai_settings, game_items.ship.rect.height, alien.rect.height) for row_number in range(number_rows): for alien_number in range(number_aliens_x): create_alien(ai_settings, game_items, alien_number, row_number)
Example #13
Source File: ship.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, screen: pygame.SurfaceType , size=(0, 0), image_name="images/ship1.png"): """Initialize the ship and set its starting position.""" super().__init__() self.screen = screen self.ai_settings = ai_settings # Load the ship image and get its rect. # fullname = os.path.join(os.getcwd(), image_name try: self.image = pygame.image.load(image_name) except pygame.error as e: print('Cannot load image: ', image_name) print(e) raise SystemExit if size == (0, 0): size = ai_settings.ship_size self.image = pygame.transform.scale(self.image, size) self.rect = self.image.get_rect() self.screen_rect = screen.get_rect() # Start each new ship at the bottom center of the screen. self.rect.centerx = self.screen_rect.centerx self.rect.bottom = self.screen_rect.bottom # Store a float value for the ship's center. self.center = float(self.rect.centerx) # Movement Flags. self.moving_right = False self.moving_left = False
Example #14
Source File: game_items.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, stats: GameStats, **kwargs: game_items_types): """Initialize with default items unless specified in kwargs.""" # Default initializations for game items. # Initialize screen. flags = pygame.HWSURFACE | pygame.DOUBLEBUF # | pygame.FULLSCREEN self.screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height), flags) pygame.display.set_caption("Alien Invasion Game") # Initialize ship. self.ship = Ship(ai_settings, self.screen) # Initialize aliens group. self.aliens = Group() # Initialize bullets group. self.bullets = Group() # Initialize buttons. self.play_button = Button(self.screen, "Play!") # TODO implement Restart and Cancel buttons. # self.restart_button = Button(self.screen, "Restart") # self.cancel_button = Button(self.screen, "Cancel", (255, 0, 0, 80)) # self.set_button_pos() # Initialize scorecard. self.sb = Scorecard(ai_settings, stats, self.screen) # Set the game items for those default values are given. for game_item in kwargs: if game_item in self.acceptable_game_items: self.__setattr__(game_item, kwargs[game_item])
Example #15
Source File: options.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 5 votes |
def __init__(self, mode: OPTIONS_MODE, changelog_path: pathlib.Path): self._mode = mode self._changelog_path = changelog_path self._cfg = Settings(suppress_initial_change=True) super().__init__(self.NAME, self.SIZE, has_menu=False)
Example #16
Source File: options.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 5 votes |
def _library_section(self) -> toga.Widget: desc = "Choose HumbleBundle game types to be shown in your GOG Galaxy library.\n" \ "Subscription games settings are placed in Galaxy Settings->Features" source_help = { SOURCE.DRM_FREE: "Games from www.humblebundle.com/home/library that have direct download for Windows, Mac or Linux", SOURCE.KEYS: "Game keys to be redeemed in foreign services like Steam or Origin." } show_revealed_help = 'Check to show all game keys as separate games.\n' \ 'Uncheck to show only game keys that are already revealed\n' \ '(redeemed keys are usually reported by other Galaxy plugins).' description = toga.Label(desc, style=Pack(font_size=self.TEXT_SIZE_BIG, padding_bottom=12)) rows = [description] self.show_revealed_sw = toga.Switch( 'show_revealed_keys', on_toggle=self._on_revealed_switch, is_on=self._cfg.library.show_revealed_keys, enabled=SOURCE.KEYS in self._cfg.library.sources, style=Pack(padding_left=20, padding_top=2) ) for s in SOURCE: sw = toga.Switch(s.value, on_toggle=self._on_source_switch, is_on=(s in self._cfg.library.sources)) sw.style.padding_bottom = 2 set_tooltip(sw, source_help[s]) rows.append(sw) set_tooltip(self.show_revealed_sw, show_revealed_help) rows.append(self.show_revealed_sw) if IS_MAC: # workaround for not working tooltip inp = toga.MultilineTextInput(readonly=True, style=Pack(padding_top=10)) inp.MIN_WIDTH = self.SIZE[0] - 50 for k, v in source_help.items(): inp.value += f'{k.value}: {v}\n' inp.value += f'show_revealed_help: {show_revealed_help}' rows.append(inp) lib_box = toga.Box(children=rows) lib_box.style.direction = 'column' lib_box.style.padding_bottom = 15 return lib_box
Example #17
Source File: conftest.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 5 votes |
def settings(mocker): mocker.patch('plugin.Settings._load_config_file') mock = Settings() mock.save_config = Mock() return mock
Example #18
Source File: conftest.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 5 votes |
def plugin(api_mock, settings, mocker): mocker.patch('plugin.AuthorizedHumbleAPI', return_value=api_mock) mocker.patch('settings.Settings', return_value=settings) plugin = HumbleBundlePlugin(Mock(), Mock(), "handshake_token") plugin.push_cache = Mock(spec=()) plugin._installed_check.cancel() plugin._statuses_check.cancel() plugin.handshake_complete() yield plugin await plugin.shutdown()
Example #19
Source File: test_settings.py From galaxy-integration-humblebundle with GNU General Public License v3.0 | 5 votes |
def test_settings_default_config(): """Default values comes directly from specific settings classes""" Settings()._config == { 'library': LibrarySettings().serialize(), 'installed': InstalledSettings().serialize() }
Example #20
Source File: kadenzeclient.py From kadenze-dl with MIT License | 5 votes |
def __init__(self): self.conf = Settings() self.base_url = "https://www.kadenze.com" self.session = Session() self.browser = RoboBrowser(history=True, session=self.session, parser="lxml", allow_redirects=True)
Example #21
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def get_number_aliens_x(ai_settings: Settings, alien_width: int): """Return number of aliens that can fit horizontally.""" available_space_x = ai_settings.screen_width - 2 * alien_width number_aliens_x = available_space_x / (alien_width * ai_settings.alien_density_factor_x) return int(number_aliens_x)
Example #22
Source File: event_task.py From sublime-gulp with MIT License | 5 votes |
def on_post_save(self, view): settings = Settings() self.view = view self.run_kill = settings.get('kill_before_save_tasks', False) self.run_tasks(settings.get("tasks_on_save", {})) self.run_tasks(settings.get("silent_tasks_on_save", {}), silent=True) self.view.run_command("gulp_update_status_bar")
Example #23
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def fire_bullet(ai_settings: Settings, game_items: GameItems): """Fire a bullet if limit not reached.""" # Create a new bullet and add it to the bullets group. if len(game_items.bullets) < ai_settings.bullets_allowed: new_bullet = Bullet(ai_settings, game_items.screen, game_items.ship) game_items.bullets.add(new_bullet)
Example #24
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def update_aliens(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update position for each alien.""" check_fleet_edges(ai_settings, game_items.aliens) game_items.aliens.update(stats) # Collision between ship and aliens. if pygame.sprite.spritecollideany(game_items.ship, game_items.aliens): ship_hit(ai_settings, stats, game_items) check_aliens_bottom(ai_settings, stats, game_items)
Example #25
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def update_bullets(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update the status and position of bullets.""" game_items.bullets.update(stats) # Get rid of bullets that have disappeared. for bullet in game_items.bullets.copy(): if bullet.rect.bottom <= 0: game_items.bullets.remove(bullet) check_bullet_alien_collision(ai_settings, stats, game_items)
Example #26
Source File: game_functions.py From alien-invasion-game with MIT License | 5 votes |
def update_screen(ai_settings: Settings, stats: GameStats, game_items: GameItems): """Update images on the screen and flip to the new screen.""" # Redraw the screen during each pass through the loop. game_items.screen.fill(ai_settings.bg_color) # Redraw all bullets behind ship and aliens. for bullet in game_items.bullets.sprites(): bullet.draw_bullet() # Draw ship. game_items.ship.blitme() # Draw alien. game_items.aliens.draw(game_items.screen) # Display scorecard. game_items.sb.show_score() # Draw button. if not stats.game_active: game_items.play_button.draw_button() # game_items.restart_button.draw_button() # game_items.cancel_button.draw_button() # Make the most recent screen visible. pygame.display.flip()
Example #27
Source File: game.py From alien-invasion-game with MIT License | 5 votes |
def run_game(): FPS = 60 # Initialize game, settings and create a screen object. pygame.init() fps_clock = pygame.time.Clock() ai_settings = Settings() # Create statistics. stats = GameStats(ai_settings) # Create game items. game_items = GameItems(ai_settings, stats) # Create a fleet of aliens. gf.create_fleet(ai_settings, game_items) # Start the main loop for the game. while True: stats.time_passed = fps_clock.tick(FPS) / 1000 # Time in seconds since previous loop. gf.check_events(ai_settings, stats, game_items) if stats.game_active: game_items.ship.update(stats) gf.update_bullets(ai_settings, stats, game_items) gf.update_aliens(ai_settings, stats, game_items) gf.update_screen(ai_settings, stats, game_items)
Example #28
Source File: alien.py From alien-invasion-game with MIT License | 5 votes |
def __init__(self, ai_settings: Settings, screen: pygame.SurfaceType, image_name='images/alien1.png'): """Initialize the alien and set its starting position.""" super().__init__() self.screen = screen self.ai_settings = ai_settings self.screen_rect = screen.get_rect() # Load the alien image and set its rect attribute. fullname = os.path.join('.', image_name) try: self.image = pygame.image.load(fullname) except pygame.error: print('Cannot load image:', image_name) raise SystemExit self.image = pygame.transform.scale(self.image, ai_settings.alien_size) self.rect = self.image.get_rect() # Start each new alien near the top left of the screen. self.rect.x = self.rect.width self.rect.y = self.rect.height self.x = float(self.rect.x) self.y = float(self.rect.y) self.drop_dist = self.y + self.ai_settings.alien_drop_dist
Example #29
Source File: __main__.py From ceph-backup with Apache License 2.0 | 5 votes |
def main(): parser = argparse.ArgumentParser(description='Backup tool for ceph') default_cephbackup_cfg = '/etc/cephbackup/cephbackup.conf' parser.add_argument('-c', '--conf', help="path to the configuration file (default: {})".format(default_cephbackup_cfg), type=str, default=default_cephbackup_cfg) args = parser.parse_args() settings = Settings(args.conf) settings.start_backup()
Example #30
Source File: cxk.py From osmo.sessdsa with GNU General Public License v3.0 | 5 votes |
def __init__(self, id, arg = None): self.id = id print("MUSIC!!!") if Settings["ENABLE_JNTM"]: from pygame import mixer self.mixer = mixer self.mixer.init() self.mixer.music.load(os.path.join(os.getcwd(), "code/jntm.mp3")) else: self.mixer = None