def run_game():
    # Initializes game and creates a screen object
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Space Invaders")
    # Game statistic and scoreboard creation
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    # Button creation
    play_button = Button(ai_settings, screen, "Play")
    # Ship creation
    ship = Ship(ai_settings, screen)
    # Make a group of lasers and enemies
    lasers = Group()
    enemies = Group()
    # Make enemies
    gf.create_fleet(ai_settings, screen, ship, enemies)
    # Main game loop
    while True:
        # Keyboard/Mouse event listener
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        enemies, lasers)
        if stats.game_active:
            ship.update()
            gf.update_lasers(ai_settings, screen, stats, sb, ship, lasers,
                             enemies)
            gf.update_enemies(ai_settings, stats, screen, sb, ship, enemies,
                              lasers)

        # Screen re-draw
        gf.update_screen(ai_settings, screen, stats, sb, ship, enemies, lasers,
                         play_button)
def play():
    pygame.init()
    settings = Settings()
    # Create Window
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption("Alien Invasion")

    button = Button(screen, "Play")
    stats = GameStats(settings)
    ship = Ship(settings, screen)
    score = Scoreboard(settings, screen, stats)
    lasers = Group()
    aliens = Group()
    gf.create_aliens(settings, screen, ship, aliens)
    # Game loop
    while True:

        gf.check_user(settings, screen, stats, score, button, ship, aliens,
                      lasers)

        if stats.game_active:
            ship.update()
            gf.update_lasers(settings, screen, stats, score, ship, aliens,
                             lasers)
            gf.update_aliens(settings, screen, stats, score, ship, aliens,
                             lasers)
        gf.update_screen(settings, screen, stats, score, ship, aliens, lasers,
                         button)
Beispiel #3
0
def run_game():
    #  Initialize game and create a screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    pygame.display.set_caption("Sky Intruders")

    clock = pygame.time.Clock()

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

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

    #  Make a ship
    plane = Plane(ai_settings, screen)
    #  Make an alien
    alien = Alien(ai_settings, screen)
    #  Make a group to store bullets in
    bullets = Group()
    #  Make a group to store aliens in
    aliens = Group()
    #  Make a lasers group
    lasers = Group()

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

    #  Start the main loop for the game.

    while True:
        gf.check_events(ai_settings, screen, stats, sb, play_button, plane,
                        aliens, bullets)

        if stats.game_active:
            plane.update()
            gf.update_bullets(ai_settings, screen, stats, sb, plane, aliens,
                              bullets)
            gf.update_aliens(ai_settings, stats, sb, screen, plane, aliens,
                             bullets, lasers)
            gf.update_lasers(ai_settings, stats, sb, screen, plane, aliens,
                             bullets, lasers)

        gf.update_screen(ai_settings, screen, stats, sb, plane, aliens,
                         bullets, play_button, lasers)

        #  What for keyboard and mouse events.
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

        #  Make the most recently drawn screen visible.
        pygame.display.flip()
        clock.tick(60)
def runGame():
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screenWidth, ai_settings.screenHeight))
    pygame.display.set_caption("Alien Invasion")
    clock = pygame.time.Clock()

    # Play button
    play_button = Button(ai_settings, screen, "Play Game")
    high = highScore(ai_settings, screen, "High Score")

    # game stats
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)

    # ship and bullets
    ship = Ship(ai_settings, screen)
    bullets = Group()

    # aliens and lasers
    aliens = Group()
    lasers = Group()
    ufo = GroupSingle()

    #Bunker
    bunkers = Group()
    gf.create_fleet(ai_settings, screen, ship, aliens)

    startScreen = Start(ai_settings, screen)
    soundFile = vlc.MediaPlayer("files/SpaceInvaders.mp3")

    while True:
        clock.tick(62)
        gf.check_events(ai_settings, screen, stats, sb, play_button, ship,
                        aliens, bullets, bunkers, high, ufo)
        if stats.game_active:
            soundFile.play()
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, aliens,
                              bullets, lasers, bunkers, ufo)
            gf.update_aliens(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, lasers, bunkers, ufo)
            gf.fire_laser(ai_settings, screen, aliens, lasers)
            gf.update_lasers(ai_settings, screen, stats, sb, ship, aliens,
                             bullets, lasers, bunkers, ufo)
            gf.updateBunkers(bullets, lasers, bunkers, aliens)
            gf.spawnUFO(ai_settings, screen, ufo)
            gf.updateUFO(ai_settings, ufo)
            gf.updateScreen(ai_settings, screen, stats, sb, ship, aliens,
                            bullets, play_button, lasers, bunkers, ufo)
        elif not stats.game_active and not stats.menu:
            gf.startGame(play_button, high, startScreen)
            soundFile.stop()
        elif stats.menu:
            gf.printHighScores(screen)
            soundFile.stop()
def run_game():
    # Initialize pygame, settings, and screen object
    pygame.mixer.pre_init(44100, -16, 1, 512)
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height)
    )
    game_master = GameMaster(screen)
    title_screen = TitleScreen(screen)
    pygame.display.set_caption("Space Invaders")

    # 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, group of bunkers, a group of bullets, and a group of aliens
    ship = Ship(ai_settings, screen)
    bunkers = Group()
    bullets = Group()
    aliens = Group()
    lasers = Group()

    game_master.last_laser_shot = pygame.time.get_ticks()
    game_master.next_laser_shot = game_master.last_laser_shot + random.randrange(250, 2000)

    gf.create_bunkers(bunkers, screen)
    gf.create_fleet(ai_settings, screen, aliens)

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

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, game_master, screen, stats, sb, bunkers, aliens, bullets)
            gf.update_aliens(ai_settings, stats, screen, sb, ship, aliens, bullets)
            gf.update_lasers(ai_settings, screen, game_master, aliens, lasers, ship, bunkers, stats, sb, bullets)
            gf.update_screen(ai_settings, screen, sb, ship, bunkers, aliens, game_master.alien_explosions,
                             lasers, bullets, game_master.ufo)
            game_master.check_ufo_spawn(screen, bullets, stats, sb)
        else:
            gf.update_title_screen(play_button, title_screen)
Beispiel #6
0
def run_game():
    # Initialize game properly and create a screen object
    pygame.init()
    game_settings = Settings()

    # Declaring screen variable that contains display content
    screen = pygame.display.set_mode(
        (game_settings.screen_width,
         game_settings.screen_height))  # 1200 wide, 800 high
    # Setting background color
    # background_color = (0, 120, 230)
    # Setting caption of game
    pygame.display.set_caption("Alien Invasion")
    # Creates ship
    ship = Ship(game_settings, screen)
    # Makes a group to store lasers in
    lasers = Group()
    # Creating Alien
    alien = Alien(game_settings, screen)
    # Makes a group of Aliens
    aliens = Group()

    # Create the fleet of aliens
    gf.create_fleet(game_settings, screen, ship, aliens)
    # Settings stats
    stats = GameStats(game_settings)
    # Creating play/start button
    play_button = Button(game_settings, screen, "Play!")
    sb = Scoreboard(game_settings, screen, stats)

    # Main loop for the game.
    while True:
        # For loop that watches for keyboard and mouse events
        gf.check_events(game_settings, screen, stats, sb, play_button, ship,
                        aliens, lasers)
        if stats.game_active:
            ship.update()
            gf.update_lasers(game_settings, screen, stats, sb, ship, aliens,
                             lasers)
            gf.update_aliens(game_settings, stats, screen, sb, ship, aliens,
                             lasers)

        # Takes 3 parameters and uses them to update the screen illusion
        gf.update_screen(game_settings, screen, stats, sb, ship, aliens,
                         lasers, play_button)
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)
Beispiel #8
0
def run_game():
    #start the main loop of the game
    ship = Ship(screen)
    bg = Background(screen)
    lasers = Group()
    fighters = Group()
    mines = Group()
    settings = Settings()
    explosions = Group()

    while settings.game_active == True:
        gf.check_events(ship, screen, lasers)
        ship.update(settings)
        gf.update_fighters(fighters, ship, screen_rect, explosions)
        gf.update_mines(mines, screen_rect, ship, explosions)
        gf.update_lasers(lasers, screen_rect, fighters, mines, explosions)
        explosions.update()
        bg.update()

        #draw the screen and ships/etc.
        gf.update_screen(bg, ship, fighters, mines, lasers, explosions, screen)
        pygame.display.flip()
        gf.make_mob(fighters, mines, settings, screen)
        clock.tick(60)
def run_game():
    """Create the game and run it."""
    pygame.init()

    # Setup pygame, settings, display, and start button
    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(ai_settings=ai_settings, screen=screen, msg='Play')

    # Setup game stats and scoreboard
    stats = GameStats(ai_settings=ai_settings)
    sb = Scoreboard(ai_settings=ai_settings, screen=screen, stats=stats)

    # Setup ship, bullets, lasers, aliens, and ufo
    ship = Ship(ai_settings=ai_settings, screen=screen)
    bullets = pygame.sprite.Group()
    lasers = pygame.sprite.Group()
    aliens = pygame.sprite.Group()
    ufo = pygame.sprite.Group()

    # Create 4 bunkers
    bunker = pygame.sprite.Group(create_bunker(ai_settings, screen, 0),
                                 create_bunker(ai_settings, screen, 1),
                                 create_bunker(ai_settings, screen, 2),
                                 create_bunker(ai_settings, screen, 3))

    # Create a fleet of invaders
    gf.create_fleet(ai_settings=ai_settings,
                    screen=screen,
                    ship=ship,
                    aliens=aliens)

    while True:
        gf.check_events(ai_settings=ai_settings,
                        screen=screen,
                        stats=stats,
                        sb=sb,
                        play_button=play_button,
                        ship=ship,
                        aliens=aliens,
                        lasers=lasers,
                        bullets=bullets)
        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings=ai_settings,
                              screen=screen,
                              stats=stats,
                              sb=sb,
                              ship=ship,
                              aliens=aliens,
                              lasers=lasers,
                              bullets=bullets,
                              ufo=ufo)
            gf.update_lasers(ai_settings=ai_settings,
                             screen=screen,
                             stats=stats,
                             sb=sb,
                             ship=ship,
                             aliens=aliens,
                             lasers=lasers,
                             bullets=bullets,
                             ufo=ufo)
            gf.update_aliens(ai_settings=ai_settings,
                             screen=screen,
                             stats=stats,
                             sb=sb,
                             ship=ship,
                             aliens=aliens,
                             lasers=lasers,
                             bullets=bullets,
                             ufo=ufo)
        gf.update_screen(ai_settings=ai_settings,
                         screen=screen,
                         stats=stats,
                         sb=sb,
                         ship=ship,
                         aliens=aliens,
                         lasers=lasers,
                         bullets=bullets,
                         play_button=play_button,
                         bunkers=bunker,
                         ufo=ufo)