Beispiel #1
0
def run_game():
    # 初始化游戏并创建一个屏幕对象
    pygame.init()
    pygame.display.set_caption('Alien Invasion')

    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.screen_width, ai_settings.screen_height))
    ship = Ship(ai_settings, screen)
    play_button = Button(ai_settings, screen, 'Play')

    bullets = Group()
    aliens = Group()
    gf.create_fleet(ai_settings, screen, aliens, ship)
    stats = GameStats(ai_settings)
    sb = Scoreboard(ai_settings, screen, stats)
    # 开始游戏的主循环
    while True:
        gf.check_events(ai_settings, screen, ship, bullets, stats, play_button,
                        aliens, sb)
        if not stats.game_over:
            ship.update()
            gf.update_bullets(ai_settings, screen, bullets, aliens, ship,
                              stats, sb)
            gf.update_aliens(ai_settings, screen, aliens, bullets, ship, stats,
                             sb)
        gf.update_screen(ai_settings, screen, ship, bullets, aliens, stats,
                         play_button, sb)
Beispiel #2
0
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("Alien Invasion")

    # 创建一艘飞船
    ship = Ship(ai_settings, screen)

    # 创建一个用于存储子弹的编组
    bullets = Group()

    aliens = Group()

    # 创建外星人群
    gf.create_fleet(ai_settings, screen, ship, aliens)

    # 开始游戏的主循环
    while True:
        # 监视键盘和鼠标事件
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullets(ai_settings, screen, ship, aliens, bullets)
        gf.update_aliens(ai_settings, ship, aliens)
        gf.update_screen(ai_settings, screen, ship, aliens, bullets)
        time.sleep(0.01)
Beispiel #3
0
def run_game():
    pygame.init()
    screen_settings = Settings()
    stats = GameStats(screen_settings)

    screen = pygame.display.set_mode(
        (screen_settings.screen_width, screen_settings.screen_height))
    ship = Ship(screen)
    pygame.display.set_caption('Alien Inv')
    screen_y = 0
    background = Background(screen_settings.bg_image, [0, 0])
    play_button = Button(screen_settings, screen, "Play")
    bullets = Group()
    enemies = Group()

    while True:  # Game Loop
        gf.check_events(
            screen_settings,
            screen,
            ship,
            bullets,
            stats,
            play_button,
            enemies,
        )
        if stats.game_active:
            ship.update()
            gf.update_bullets(bullets, enemies)
            gf.update_enemies(enemies, ship, screen_settings, stats, screen,
                              bullets)
        gf.update_screen(screen_settings, screen, ship, screen_y, background,
                         bullets, enemies, play_button, stats)
        screen_y += screen_settings.bg_speed
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("Alien Invasion")
    ship = Ship(ai_settings, screen)
    bullets = Group()
    alien = Alien(ai_settings, screen)
    while True:
        gf.check_events(ai_settings, screen, ship, bullets)
        ship.update()
        gf.update_bullet(bullets)
        gf.update_screen(ai_settings, screen, ship, alien, bullets)
Beispiel #5
0
def run_game():
    """Main entry point for Py-Climber"""

    # Startup pygame object
    pygame.init()

    random.seed()

    # Load our settings object and image resources, disk I/O that can be done in advance
    settings = Settings()
    image_res = ImageResources(settings)
    # Add to the cache so it's accessible where needed
    settings.image_res = image_res

    # Create the main screen to render to based on settings
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption(settings.caption)

    # Create a 2D tilemap - this takes a list of indices and an image list to produce a tiled surface
    tile_map = Tilemap(settings, screen, settings.map_indicies,
                       image_res.tile_images, image_res.block_image,
                       image_res.blob_exit_images,
                       image_res.player_sprite_images,
                       image_res.enemy_blob_images)

    # Overwrite default indices with generated map
    tile_map.generate_basic_map(settings.map_number_floors,
                                settings.map_number_subfloors)

    # Reset the game
    gf.reset_game(tile_map)

    # Use pygame's simple loop management for a fixed 30 FPS
    clock = pygame.time.Clock()
    while True:
        # Should make sure each frame spends at least 1/30 seconds in this loop
        # downside is wasted sleep on fast hardware and slow hardware will lag
        # but slow hardware will always lag and implementing a time-delta based
        # loop for this simple game is IMHO overkill.
        clock.tick(30)

        # Process system events (key-presses, joystick, etc)
        gf.check_events(settings, screen, tile_map)

        # Update the game (this will update all sub-object and render them to the screen)
        gf.update_screen(settings, screen, tile_map)
def run_game():
    """The function opens the game and creates a screen"""
    # Initialize pygame, settings, and screen object.
    pygame.init()
    ai_settings = Settings()
    screen = pygame.display.set_mode(
        (ai_settings.display_width, ai_settings.display_height))
    pygame.display.set_caption("Alien Invasion")

    # Make a rocket ship
    rocket_ship = RocketShip(screen, ai_settings)

    # Make a group to store bullets in.
    bullets = Group()

    # Make a group of Aliens and the fleet.
    aliens = Group()
    game_functions.create_fleet(ai_settings, screen, rocket_ship, aliens)

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

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

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

        if stats.game_active:
            rocket_ship.update()
            game_functions.update_bullets(ai_settings, screen, stats, sb,
                                          rocket_ship, aliens, bullets)
            game_functions.update_aliens(ai_settings, stats, sb, screen,
                                         rocket_ship, aliens, bullets)

        game_functions.update_screen(ai_settings, screen, stats, sb,
                                     rocket_ship, aliens, bullets, play_button,
                                     empty_ship)
Beispiel #7
0
def run_game():
    """Initialize game, settings and create a screen object"""
    pygame.init()
    sounds = Sounds()
    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(ai_settings, screen, 'Play')

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

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

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

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

        if stats.game_active:
            ship.update()
            gf.update_bullets(ai_settings, screen, stats, sb, ship, sounds,
                              aliens, bullets)
            gf.update_aliens(ai_settings, stats, sb, screen, ship, aliens,
                             bullets)
            gf.update_screen(ai_settings, screen, sb, ship, aliens, bullets)
        else:
            gf.display_menu_screen(ai_settings, screen, play_button)
def rungame():
    # Initialize game,settings and create screen object.
    pygame.init()
    sett = Settings()
    screen = pygame.display.set_mode((sett.screen_width, sett.screen_height))
    pygame.display.set_caption("Alien Invasion")
    """"Instance initialization"""
    # Make instance of game stats.
    stats = GameStats(sett)
    # Make instance of scoreboard.
    sb = ScoreBoard(sett, screen, stats)
    # Make the play button.
    b_play = Button(sett, screen, "PLAY")

    # Make instance of ship.
    ship = Ship(sett, screen)
    # Make a group to store bullets and aliens.
    aliens = Group()
    bullets = Group()
    # Make instance of alien.
    alien = Alien(sett, screen)
    gf.create_fleet(sett, screen, ship, aliens)

    # Start the main loop for the game.
    while True:
        # Watch for keyboard and mouse events.
        gf.check_events(sett, screen, stats, sb, b_play, ship, aliens, bullets)

        if stats.game_active:
            ship.update()
            gf.update_bullets(sett, screen, stats, sb, ship, aliens, bullets)
            gf.update_aliens(sett, stats, sb, screen, ship, aliens, bullets)

        # Redraw the screen during each pass through the loop.
        gf.update_screen(sett, screen, stats, sb, ship, aliens, bullets,
                         b_play)
Beispiel #9
0
def run_game():
    """Main entry point for Progmind"""

    pygame.init()

    pygame.mixer.init()

    pygame.mixer.music.load('Jason Farnham No Copyright Music.mp3')
    pygame.mixer.music.set_volume(0.03)

    pygame.mixer.music.play(-1)

    # Startup pygame object
    root = Tk()
    root.title("PROGMIND")
    root.configure(background='#24235c')
    w = 600
    h = 600
    ws = root.winfo_screenwidth()
    hs = root.winfo_screenheight()
    x = (ws / 2) - (w / 2) - 30
    y = (hs / 2) - (h / 2) - 30
    root.geometry('%dx%d+%d+%d' % (w, h, x, y))
    root.resizable(width=False, height=False)

    # CONTEÚDO
    img = PhotoImage(file="images/progmind-logo.gif")
    img = img.subsample(2, 2)

    label_imagem = Label(root, image=img).grid(row=1)

    # Create a Button
    Button(root,
           text='COMEÇAR',
           bd='2',
           font=("Arial", 12),
           fg='#24235c',
           bg='#ffffff',
           command=root.destroy,
           width=20).place(x=200, y=350)

    root.mainloop()

    random.seed()

    # Load our settings object and image resources, disk I/O that can be done in advance
    settings = Settings()
    image_res = ImageResources(settings)
    # Add to the cache so it's accessible where needed
    settings.image_res = image_res

    # Create the main screen to render to based on settings
    screen = pygame.display.set_mode(
        (settings.screen_width, settings.screen_height))
    pygame.display.set_caption(settings.caption)

    # Create a 2D tilemap - this takes a list of indices and an image list to produce a tiled surface
    tile_map = Tilemap(settings, screen, settings.map_indicies,
                       image_res.tile_images, image_res.block_image,
                       image_res.box_image, image_res.blob_exit_images,
                       image_res.player_sprite_images,
                       image_res.enemy_blob_images)

    # Overwrite default indices with generated map
    tile_map.generate_basic_map(settings.map_number_floors,
                                settings.map_number_subfloors)

    # Reset the game
    gf.reset_game(tile_map)

    # Use pygame's simple loop management for a fixed 30 FPS
    clock = pygame.time.Clock()

    while True:
        # Deve certificar-se de que cada quadro gasta pelo menos 1/30 segundos neste loop
        # desvantagem é o sono desperdiçado em hardware rápido e hardware lento vai atrasar
        # mas o hardware lento sempre vai atrasar e implementar um baseado em time delta
        # loop para este jogo simples é um exagero IMHO.
        clock.tick(30)

        # Processar eventos do sistema (pressionamentos de tecla, joystick, etc)
        gf.check_events(settings, screen, tile_map)

        # Atualize o PROGMIND (isso atualizará todos os subobjetos e os renderizará na tela)
        gf.update_screen(settings, screen, tile_map, Settings.level_number)