def run_game(): pygame.init() ai_settings = Settings() # Setup pygame, settings, and display screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption('Space Invaders') clock = pygame.time.Clock() # Setup game stats and scoreboard stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # Setup ship, bullets, alien bullets, aliens, and background ship = Ship(ai_settings, screen) bullets = pygame.sprite.Group() alien_bullets = pygame.sprite.Group() aliens = pygame.sprite.Group() ufo = pygame.sprite.Group() background = Background('images/background.png', [0, 0], screen) gf.create_fleet(ai_settings, screen, ship, aliens) bunkers = pygame.sprite.Group(make_bunker(ai_settings, screen, 0), make_bunker(ai_settings, screen, 1), make_bunker(ai_settings, screen, 2), make_bunker(ai_settings, screen, 3)) while True: clock.tick(120) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, alien_bullets, bullets, bunkers, ufo, background) gf.play_bgm(ai_settings, stats) if not stats.game_active: quit_game = not gf.startup_screen(ai_settings, stats, screen) if quit_game: pygame.quit() break gf.start_new_game(ai_settings, screen, stats, sb, ship, aliens, alien_bullets, bullets) gf.check_events(ai_settings, screen, stats, ship, bullets) if stats.game_active: ship.update() gf.update_bullets_alien_bullet(ai_settings, screen, stats, sb, ship, aliens, alien_bullets, bullets, ufo) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, alien_bullets, bullets, ufo)
def run_game(): pygame.init() ai_settings = Settings() # Setup pygame, settings, and display screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption('Pokemon Invasion') clock = pygame.time.Clock() # Setup game stats and scoreboard stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) # Setup ship, bullets, beams, aliens, background stars ship = Ship(ai_settings, screen) bullets = pygame.sprite.Group() beams = pygame.sprite.Group() aliens = pygame.sprite.Group() ufo = pygame.sprite.Group() stars = gf.create_stars(ai_settings, screen) gf.create_fleet(ai_settings, screen, ship, aliens) bunkers = pygame.sprite.Group(make_bunker(ai_settings, screen, 0), make_bunker(ai_settings, screen, 1), make_bunker(ai_settings, screen, 2), make_bunker(ai_settings, screen, 3)) while True: clock.tick(70) # 70 fps limit if not stats.game_active: quit_game = not gf.startup_screen(ai_settings, stats, screen) if quit_game: pygame.quit() break gf.start_new_game(ai_settings, screen, stats, sb, ship, aliens, beams, bullets) gf.check_events(ai_settings, screen, stats, ship, bullets) if stats.game_active: ship.update() gf.update_bullets_beams(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, ufo) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, ufo) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, beams, bullets, bunkers, stars, ufo) gf.play_bgm(ai_settings, stats)
def play(self): while True: gf.check_events(settings=self.settings, screen=self.screen, stats=self.stats, play_button=self.play_button, ship=self.ship, bullets=self.bullets) if self.stats.game_active: self.ship.update() self.bullets.update() self.aliens.update() self.ufos.update() self.alienBullets.update() self.barrier.update() time.sleep(0.01) self.screen.fill(self.settings.bg_color) self.ship.draw() self.bullets.draw() self.aliens.draw() self.ufos.draw() self.alienBullets.draw() self.barrier.draw() self.sb.show_score() if not self.stats.game_active: self.play_button.draw() self.sound.pause_bg() # self.menu_aliens.draw() quit_game = not gf.startup_screen(settings=self.settings, stats=self.stats, screen=self.screen, menu_aliens=self.menu_aliens, menu_ufos=self.menu_ufos) if quit_game: pg.quit() break else: if not self.sound.playing_bg: self.sound.unpause_bg() pg.display.flip()
def run_game(): # initial game setup pygame.init() config = Config() clock = pygame.time.Clock() screen = pygame.display.set_mode( (config.screen_width, config.screen_height) ) pygame.display.set_caption('Pong - No Walls') # setup players/AI player_data = game.setup_players(config, screen) # setup scoreboards gs = GameStats(config) scoreboard_1 = Scoreboard(config, screen, player=False) scoreboard_2 = Scoreboard(config, screen, player=True) goal_board = GoalBoard(config, screen) goal_board.prep_board() # setup center divider divider = Divider(config, screen) # setup ball ball = Ball(config, screen) winner = None while True: clock.tick(60) # 60 fps limit if not gs.game_active and not winner: quit_game = not game.startup_screen(config, gs, screen) if quit_game: pygame.quit() break gs.game_active, winner = game.check_scores(gs, config) if not gs.game_active and winner: # if game over, display winner for 5 seconds if game.check_winner_display(gs, ball, scoreboard_1, scoreboard_2, player_data['paddles']): winner = None continue game.check_events(player_data['player_v'], player_data['player_h1'], player_data['player_h2']) game.update_screen(config, screen, scoreboard_1, scoreboard_2, player_data['paddles'], ball, player_data['ai_player'], divider, gs, goal_board, winner or None)