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 run_game(): pygame.init() ai_settings = Settings() screen = pygame.display.set_mode( (ai_settings.screen_width, ai_settings.screen_height)) pygame.display.set_caption("Space Invaders") pygame.mixer.music.load("sounds/loop.mp3") play_button = Button(ai_settings, screen, "Play") start_screen = StartScreen(ai_settings, screen, play_button) stats = GameStats(ai_settings) sb = Scoreboard(ai_settings, screen, stats) start_screen.makescreen(ai_settings) ship = Ship(ai_settings, screen) bullets = Group() lazers = Group() aliens = Group() 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)) gf.create_fleet(ai_settings, screen, aliens) pygame.mixer.music.play(-1, 0.0) # Start the main loop for the game. gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, lazers, play_button, bunkers) while True: pygame.time.delay(15) gf.check_events(ai_settings, screen, stats, sb, play_button, ship, aliens, bullets) if stats.game_active: ship.update() gf.update_bullets(ai_settings, screen, stats, sb, aliens, bullets) gf.update_bullets_lazers(ai_settings, lazers, bullets) gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens, bullets, lazers) gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets, lazers, play_button, bunkers)