def run_game():

    pygame.init()

    music.play_menu_music()

    game_settings = Settings()

    screen = pygame.display.set_mode(game_settings.get_screen_size())

    pygame.display.set_caption('Alien Invasion')

    stats = GameStats(game_settings)

    ship = Ship(game_settings, screen)

    ufos = Group()

    bullets = Group()

    stars = Group()

    explosions = Group()

    play_button = Button(game_settings, screen, 'Play')

    current_score = CurrentScore(game_settings, screen, stats)

    hi_score = HiScore(game_settings, screen, stats)

    level = Level(game_settings, screen, stats)

    lifes = Group()

    while True:

        game_functions.check_events(game_settings, screen, stats, ship, ufos,
                                    bullets, play_button, lifes)

        game_functions.star_creation(game_settings, screen, stars)

        if stats.game_active:

            ship.update()
            game_functions.update_bullets(bullets, ufos)
            game_functions.update_ufos(game_settings, screen, stats, ship,
                                       ufos, bullets, explosions, lifes)

        game_functions.update_screen(game_settings, screen, stats, ship, ufos,
                                     bullets, stars, explosions, play_button,
                                     current_score, hi_score, level, lifes)

        game_functions.update_collisions(game_settings, screen, stats, ship,
                                         ufos, bullets, explosions,
                                         current_score)
        game_functions.update_explosions(game_settings, explosions)

        game_functions.update_stars(stars, game_settings)
示例#2
0
def run_game():
    """Initialize a game, display."""
    pygame.init()
    game_settings = Settings()
    screen = pygame.display.set_mode(
        (game_settings.screen_width, game_settings.screen_height))
    pygame.display.set_caption(game_settings.game_name)

    # Make the Play button.
    play_button = Button(game_settings, screen, "Play")
    # Make describtion.
    description = Description(game_settings, screen, "Project by Andrii Dykyi")
    # Create an instance to store game statistics.
    stats = GameStats(game_settings)
    score_board = Scoreboard(game_settings, screen, stats)

    background_image = pygame.image.load(
        game_settings.background_image).convert()

    # Create rocket.
    rocket = Rocket(game_settings, screen)

    # Make a group to store bullets in.
    bullets = Group()
    # Make a meteorite.
    meteorites = Group()
    # Make a star.
    stars = Group()
    # Make an explosion.
    explosions = Group()

    while True:
        game_functions.check_event(game_settings, screen, stats, play_button,
                                   rocket, meteorites, stars, bullets,
                                   score_board, explosions)

        if stats.game_active:
            rocket.update()

            game_functions.update_bullets(bullets, screen, meteorites)

            game_functions.update_meteorites(game_settings, stats, screen,
                                             rocket, meteorites, score_board,
                                             explosions)

            game_functions.update_explosions(explosions)

            game_functions.update_stars(game_settings, stats, screen, rocket,
                                        stars, score_board)

        game_functions.update_screen(background_image, game_settings, screen,
                                     stats, score_board, rocket, stars,
                                     meteorites, bullets, play_button,
                                     explosions, description)
示例#3
0
def run_game():
    # Initialize game, settings, and create a screen object.
    pygame.init()
    settings = Settings.getInstance()
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption(settings.window_caption)

    # Make the Play button.
    play_button = Button(screen, "Play")

    # Make Groupmanager
    em = EntityManager.getInstance()

    # Make ship
    ship = Ship(screen)
    em.add_single("ship", ship)

    # Make a group to store bullets in.
    em.add_group("bullets")

    # Make a group to store aliens in
    em.add_group("aliens")

    # Create statistics and scoreboard
    stats = GameStats()
    sb = Scoreboard(settings, screen, stats)

    # Load background.
    bg = BackGround()

    # Create explosions group
    em.add_group("explosions")

    # Start background music
    SoundManager.getInstance().play_music()

    # Make power up group
    em.add_group("power_ups")

    # Start the main loop for the game.
    while True:

        # Watch for keyboard and mouse events.
        gf.check_events(screen, stats, sb, play_button)

        if stats.game_active:
            em.update_singles()
            gf.update_bullets(screen, stats, sb)
            gf.update_aliens(screen, stats, sb)
            gf.update_explosions()
            gf.update_power_ups()

        gf.update_screen(screen, bg, stats, sb, play_button)
def run_game():
    # Initialize pygame, settings, and screen object
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Inveders")
    clock = pygame.time.Clock()
    # make a ship
    ship = Ship(ai_settings, screen)
    ufo = UFO(ai_settings, screen)

    play_button = Button(screen, "Play", 200)
    score_button = Button(screen, "High Scores", 300)
    screen_rect = screen.get_rect()
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    bullets = Group()
    lasers = Group()
    aliens = Group()
    explosions = Group()
    bunkers = [
        Bunker(screen_rect.width / 4, screen_rect.bottom - 150, screen, 1),
        Bunker(screen_rect.width / 2, screen_rect.bottom - 150, screen, 2),
        Bunker(3 * screen_rect.width / 4, screen_rect.bottom - 150, screen, 3),
        Bunker(screen_rect.width, screen_rect.bottom - 150, screen, 4)
    ]

    # Start the main loop for the game.
    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button,
                        score_button, ship, aliens, bullets)

        if stats.game_active:

            pygame.mixer.music.load('sounds/bgm.wav')
            pygame.mixer.music.set_volume(400)
            pygame.mixer.music.play(-1)
            ship.update()

            gf.update_ufo(ufo, ai_settings)
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, lasers, ufo, explosions, bunkers)
            gf.update_aliens(ai_settings, stats, screen, sb, ship, ufo, aliens,
                             bullets, lasers)
            gf.update_explosions(explosions)

        gf.update_screen(ai_settings, stats, screen, sb, ship, ufo, aliens,
                         bullets, lasers, play_button, score_button,
                         explosions, bunkers)
        clock.tick(60)
示例#5
0
def run_game():
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    # Make the Play button
    play_button = Button(screen, "Play")

    # Create an instance to store game statistics and create a scoreboard
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # Make a ship, a group of bullets, and a group of aliens
    ship = Ship(ai_settings, screen)
    bullets = Group()
    aliens = Group()
    alienbullets = Group()
    explosions = Group()
    ufos = Group()

    # Create the fleet of aliens
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # Start the main loop for the game
    while True:

        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets, alienbullets, explosions, ufos)

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, alienbullets, explosions, ufos)
            gf.update_alien_bullets(ai_settings, screen, stats, sb, ship,
                                    aliens, bullets, alienbullets, explosions,
                                    ufos)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, alienbullets, explosions, ufos)
            gf.update_explosions(explosions)

        gf.update_screen(ai_settings, screen, stats, sb, ship, aliens, bullets,
                         play_button, alienbullets, explosions, ufos)
def run_game():
    pygame.init()
    main_clock = pygame.time.Clock()
    ai_settings = Settings()
    screen = pygame.display.set_mode((ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")
    play_button = Button(screen, "Play", ai_settings.screen_width / 2, 700)
    scores_button = Button(screen, "High Scores", ai_settings.screen_width / 2, 800)
    back_button = Button(screen, "Back", 150, 75)
    ship = Ship(ai_settings, screen)
    bullets = Group()
    lasers = Group()
    explosions = Group()
    ufos = Group()
    bunkers = Group()
    aliens = Group()
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    gf.create_fleet(ai_settings, screen, aliens)

    # Main loop for the game
    while True:
        gf.check_events(ai_settings=ai_settings, screen=screen, stats=stats, ship=ship, sb=sb, play_button=play_button,
                        bullets=bullets, aliens=aliens, score_button=scores_button,
                        back_button=back_button, bunkers=bunkers)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings=ai_settings, screen=screen, stats=stats, sb=sb, aliens=aliens,
                              bullets=bullets, explosions=explosions, ufos=ufos, bunkers=bunkers)
            gf.update_aliens(ai_settings=ai_settings, stats=stats, screen=screen, sb=sb,
                             aliens=aliens, ship=ship, bullets=bullets, lasers=lasers)
            gf.update_explosions(explosions=explosions)
            gf.update_ufos(ufos=ufos, screen=screen, ai_settings=ai_settings)
            gf.update_lasers(lasers=lasers)
            gf.update_bunkers(bunkers=bunkers)

        gf.update_screen(ai_settings=ai_settings, screen=screen, ship=ship, sb=sb, aliens=aliens, bullets=bullets,
                         play_button=play_button, stats=stats, explosions=explosions, ufos=ufos,
                         score_button=scores_button, back_button=back_button, lasers=lasers, bunkers=bunkers)
        main_clock.tick(120)
示例#7
0
def run_game():
    # Initialize Pygame
    pygame.mixer.pre_init(frequency=44100)
    pygame.init()
    # Initialize settings, preload assets, and create a clock
    settings = Settings()
    sounds = Sounds(settings)
    images = Images()
    clock = pygame.time.Clock()
    # Set up the window
    pygame.display.set_icon(images.icon)
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Bullet Heck!")
    # Try to create a joystick object
    try:
        gamepad = Joystick(settings.gamepad_id)
        gamepad.init()
        settings.gamepad_connected = True
    except pygame.error:
        gamepad = None
        settings.gamepad_connected = False
    # Initialize the stats, HUD, and splash screen
    stats = Stats(settings)
    hud = HUD(settings, screen, stats, images)
    splash = SplashScreen(settings, images, screen)
    # Create the ship and groups for everything else
    ship = Ship(settings, screen, stats, images)
    stars = Group()
    bullets = Group()
    enemies = Group()
    enemy_bullets = Group()
    explosions = Group()
    pickups = Group()
    if not settings.mute_music:
        pygame.mixer.music.play(loops=-1)
    # Pause the music by default
    pygame.mixer.music.pause()
    # Main loop
    while stats.done is False:
        gf.check_events(settings, screen, ship, gamepad, bullets, stats,
                        sounds, enemies, images, enemy_bullets, splash, hud)
        gf.update_stars(settings, screen, stars, images)
        gf.manage_game_level(settings, stats)
        if stats.game_active:
            ship.update(settings, images)
            gf.spawn_enemies(settings, screen, enemies, images, id, stats)
            gf.update_bullets(settings, screen, ship, bullets, enemies, sounds,
                              enemy_bullets, images, stats, hud, explosions,
                              pickups, splash)
            gf.update_enemy_stuff(settings, screen, ship, enemies, sounds,
                                  stats, explosions, images, pickups, hud,
                                  bullets, enemy_bullets, splash)
        # Update the explosions even if the game is paused.
        gf.update_explosions(explosions)
        gf.update_screen(settings, screen, stars, ship, bullets, enemies,
                         explosions, pickups, hud, stats, enemy_bullets,
                         splash)
        clock.tick(settings.fps_limit)
        if settings.show_fps:
            stats.fps = clock.get_fps()