当前位置: 首页>>代码示例>>Python>>正文


Python pygame.init方法代码示例

本文整理汇总了Python中pygame.init方法的典型用法代码示例。如果您正苦于以下问题:Python pygame.init方法的具体用法?Python pygame.init怎么用?Python pygame.init使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在pygame的用法示例。


在下文中一共展示了pygame.init方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ale_load_from_rom

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def ale_load_from_rom(rom_path, display_screen):
    rng = get_numpy_rng()
    try:
        from ale_python_interface import ALEInterface
    except ImportError as e:
        raise ImportError('Unable to import the python package of Arcade Learning Environment. ' \
                           'ALE may not have been installed correctly. Refer to ' \
                           '`https://github.com/mgbellemare/Arcade-Learning-Environment` for some' \
                           'installation guidance')

    ale = ALEInterface()
    ale.setInt(b'random_seed', rng.randint(1000))
    if display_screen:
        import sys
        if sys.platform == 'darwin':
            import pygame
            pygame.init()
            ale.setBool(b'sound', False) # Sound doesn't work on OSX
        ale.setBool(b'display_screen', True)
    else:
        ale.setBool(b'display_screen', False)
    ale.setFloat(b'repeat_action_probability', 0)
    ale.loadROM(str.encode(rom_path))
    return ale 
开发者ID:awslabs,项目名称:dynamic-training-with-apache-mxnet-on-aws,代码行数:26,代码来源:atari_game.py

示例2: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self, dt=0.2, res=(32, 32), init_pos=(3, 3), init_std=0, wall=None, gravity=(0.0, 0.0)):
        pygame.init()

        self.dt = dt
        self.res = res
        if os.environ.get('SDL_VIDEODRIVER', '') == 'dummy':
            pygame.display.set_mode(res, 0, 24)
            self.screen = pygame.Surface(res, pygame.SRCCOLORKEY, 24)
            pygame.draw.rect(self.screen, (0, 0, 0), (0, 0, res[0], res[1]), 0)
        else:
            self.screen = pygame.display.set_mode(res, 0, 24)
        self.gravity = gravity
        self.initial_position = init_pos
        self.initial_std = init_std
        self.space = pymunk.Space()
        self.space.gravity = self.gravity
        self.draw_options = pymunk.pygame_util.DrawOptions(self.screen)
        self.clock = pygame.time.Clock()
        self.wall = wall
        self.static_lines = None

        self.dd = 2 
开发者ID:simonkamronn,项目名称:kvae,代码行数:24,代码来源:box_gravity.py

示例3: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self, dt=0.2, res=(32, 32), init_pos=(3, 3), init_std=0, wall=None):
        pygame.init()

        self.dt = dt
        self.res = res
        if os.environ.get('SDL_VIDEODRIVER', '') == 'dummy':
            pygame.display.set_mode(res, 0, 24)
            self.screen = pygame.Surface(res, pygame.SRCCOLORKEY, 24)
            pygame.draw.rect(self.screen, (0, 0, 0), (0, 0, res[0], res[1]), 0)
        else:
            self.screen = pygame.display.set_mode(res, 0, 24)
        self.gravity = (0.0, 0.0)
        self.initial_position = init_pos
        self.initial_std = init_std
        self.space = pymunk.Space()
        self.space.gravity = self.gravity
        self.draw_options = pymunk.pygame_util.DrawOptions(self.screen)
        self.clock = pygame.time.Clock()
        self.wall = wall
        self.static_lines = None

        self.dd = 2 
开发者ID:simonkamronn,项目名称:kvae,代码行数:24,代码来源:pong.py

示例4: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main(argv):
  config = {'width': FLAGS.width,
            'height': FLAGS.height,
            'field_of_view': FLAGS.field_of_view,
            'graph_width': FLAGS.width,
            'graph_height': FLAGS.height,
            'graph_zoom': 1,
            'full_graph': True,
            'proportion_of_panos_with_coins': 0.0,
            'action_spec': 'streetlearn_fast_rotate',
            'observations': ['view_image', 'graph_image', 'yaw']}
  with open(FLAGS.list_pano_ids_yaws, 'r') as f:
    lines = f.readlines()
    pano_ids_yaws = [(line.split('\t')[0], float(line.split('\t')[1]))
                     for line in lines]
  config = default_config.ApplyDefaults(config)
  game = coin_game.CoinGame(config)
  env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
  env.reset()
  pygame.init()
  screen = pygame.display.set_mode((FLAGS.width, FLAGS.height * 2))
  loop(env, screen, pano_ids_yaws) 
开发者ID:deepmind,项目名称:streetlearn,代码行数:24,代码来源:scan_agent.py

示例5: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main(argv):
  config = {'width': FLAGS.width,
            'height': FLAGS.height,
            'field_of_view': FLAGS.field_of_view,
            'graph_width': FLAGS.width,
            'graph_height': FLAGS.height,
            'graph_zoom': FLAGS.graph_zoom,
            'goal_timeout': FLAGS.frame_cap,
            'frame_cap': FLAGS.frame_cap,
            'full_graph': (FLAGS.start_pano == ''),
            'start_pano': FLAGS.start_pano,
            'min_graph_depth': FLAGS.graph_depth,
            'max_graph_depth': FLAGS.graph_depth,
            'proportion_of_panos_with_coins':
                FLAGS.proportion_of_panos_with_coins,
            'action_spec': 'streetlearn_fast_rotate',
            'observations': ['view_image', 'graph_image', 'yaw', 'pitch']}
  config = default_config.ApplyDefaults(config)
  game = courier_game.CourierGame(config)
  env = streetlearn.StreetLearn(FLAGS.dataset_path, config, game)
  env.reset()
  pygame.init()
  screen = pygame.display.set_mode((FLAGS.width, FLAGS.height * 2))
  loop(env, screen) 
开发者ID:deepmind,项目名称:streetlearn,代码行数:26,代码来源:oracle_agent.py

示例6: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main():
	pygame.init()
	pygame.mixer.init()
	pygame.mixer.music.load('resource/audios/1.mp3')
	pygame.mixer.music.play(-1, 0.0)
	pygame.mixer.music.set_volume(0.25)
	screen = pygame.display.set_mode((WIDTH, HEIGHT))
	pygame.display.set_caption("塔防游戏-公众号: Charles的皮卡丘")
	clock = pygame.time.Clock()
	# 调用游戏开始界面
	start_interface = START.START(WIDTH, HEIGHT)
	is_play = start_interface.update(screen)
	if not is_play:
		return
	# 调用游戏界面
	while True:
		choice_interface = CHOICE.CHOICE(WIDTH, HEIGHT)
		map_choice, difficulty_choice = choice_interface.update(screen)
		game_interface = GAMING.GAMING(WIDTH, HEIGHT)
		game_interface.start(screen, map_path='./maps/%s.map' % map_choice, difficulty_path='./difficulty/%s.json' % difficulty_choice)
		end_interface = END.END(WIDTH, HEIGHT)
		end_interface.update(screen) 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:24,代码来源:Game8.py

示例7: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main(cfg):
	# 游戏初始化
	pygame.init()
	pygame.mixer.init()
	screen = pygame.display.set_mode((cfg.WIDTH, cfg.HEIGHT))
	pygame.display.set_caption(cfg.TITLE)
	# 加载游戏素材
	sounds = {}
	for key, value in cfg.AUDIO_PATHS.items():
		sounds[key] = pygame.mixer.Sound(value)
		sounds[key].set_volume(1)
	# 开始界面
	is_dual_mode = gameStartInterface(screen, cfg)
	# 关卡数
	levelfilepaths = [os.path.join(cfg.LEVELFILEDIR, filename) for filename in sorted(os.listdir(cfg.LEVELFILEDIR))]
	# 主循环
	for idx, levelfilepath in enumerate(levelfilepaths):
		switchLevelIterface(screen, cfg, idx+1)
		game_level = GameLevel(idx+1, levelfilepath, sounds, is_dual_mode, cfg)
		is_win = game_level.start(screen)
		if not is_win: break
	is_quit_game = gameEndIterface(screen, cfg, is_win)
	return is_quit_game 
开发者ID:CharlesPikachu,项目名称:Games,代码行数:25,代码来源:Game5.py

示例8: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main():
    pygame.init()
    display = (800,600)
    pygame.display.set_mode(display, DOUBLEBUF|OPENGL)

    gluPerspective(45, (display[0]/display[1]), 0.1, 50.0)

    glTranslatef(0.0,0.0, -5)

    while True:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                pygame.quit()
                quit()

        glRotatef(1, 3, 1, 1)
        glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT)
        Cube()
        pygame.display.flip()
        pygame.time.wait(10) 
开发者ID:geohot,项目名称:twitchslam,代码行数:22,代码来源:test_pyopengl.py

示例9: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self):
        # 实例化pygame
        pygame.init()

        # 创建游戏窗口[宽,高] -> 窗口对象
        self.window = pygame.display.set_mode([WINDOW_WIDTH,WINDOW_HEIGHT])

        # 设置窗口的title
        pygame.display.set_caption("飞机大战")

        # 设置窗口的图标icon,加载一个图片对象
        logo_image = pygame.image.load("res/app.ico")
        pygame.display.set_icon(logo_image)

        # 创建一个地图对象,渲染背景图片
        self.game_map = GameMap()

        # 创建一个英雄飞机对象
        self.hero_plane = HeroPlane()

    # 运行游戏程序 
开发者ID:HaoZhang95,项目名称:Python24,代码行数:23,代码来源:六个类合一.py

示例10: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main():
    pygame.init()
    screen = pygame.display.set_mode(SCR_RECT.size)
    pygame.display.set_caption(u"PyRPG 01 プレイヤーの描画")
    
    playerImg = load_image("player1.png", -1)  # プレイヤー
    
    while True:
        screen.fill((0,0,255))
        screen.blit(playerImg, (0,0))  # プレイヤーを描画
        pygame.display.update()
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit()
            if event.type == KEYDOWN and event.key == K_ESCAPE:
                sys.exit() 
开发者ID:aidiary,项目名称:pygame,代码行数:18,代码来源:pyrpg01.py

示例11: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self):
        pygame.init()
        screen = pygame.display.set_mode(SCR_RECT.size)
        pygame.display.set_caption("1945")
        # 素材のロード
        self.load_images()
        self.load_sounds()
        # ゲームの初期化
        self.init_game()
        clock = pygame.time.Clock()
        while True:
            clock.tick(60)
            screen.fill((255,0,0))
            self.update()
            self.draw(screen)
            pygame.display.update()
            self.key_handler() 
开发者ID:aidiary,项目名称:pygame,代码行数:19,代码来源:1945.py

示例12: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main():
    pygame.init()
    screen = pygame.display.set_mode(SCR_RECT.size)
    pygame.display.set_caption(u"キャラクターアニメーション")

    all = pygame.sprite.RenderUpdates()
    Character.containers = all
    
    player = Character("player4.png", 0, 0)
    king = Character("king4.png", 32, 0)
    soldier = Character("soldier4.png", 64, 0)
    
    clock = pygame.time.Clock()
    while True:
        clock.tick(60)
        screen.fill((0,0,255))
        all.update()
        all.draw(screen)
        pygame.display.update()
        for event in pygame.event.get():
            if event.type == QUIT:
                sys.exit() 
开发者ID:aidiary,项目名称:pygame,代码行数:24,代码来源:chara_anime.py

示例13: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self):
        pygame.init()
        screen = pygame.display.set_mode(SCR_RECT.size)
        pygame.display.set_caption("左右移動")
        
        # 画像のロード
        Python.left_image = load_image("python.png", -1)                     # 左向き
        Python.right_image = pygame.transform.flip(Python.left_image, 1, 0)  # 右向き
        
        # オブジェクとグループと蛇の作成
        self.all = pygame.sprite.RenderUpdates()
        Python.containers = self.all
        Python()
        
        # メインループ
        clock = pygame.time.Clock()
        while True:
            clock.tick(60)
            self.update()
            self.draw(screen)
            pygame.display.update()
            self.key_handler() 
开发者ID:aidiary,项目名称:pygame,代码行数:24,代码来源:move.py

示例14: __init__

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def __init__(self):
        pygame.init()
        self.sound_folder = os.path.join(assets_folder, 'sounds')
        self.place_sound = self.load_sound('cardPlace1.wav')
        self.shuffle_sound = self.load_sound('cardShuffle.wav')
        self.chip_sound = self.load_sound('chipsStack6.wav') 
开发者ID:PacktPublishing,项目名称:Tkinter-GUI-Programming-by-Example,代码行数:8,代码来源:__init__.py

示例15: main

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import init [as 别名]
def main():
    global mainDir, fontsChinese
    pygame.init()
    shutil.rmtree(OUTPUT_DIR, ignore_errors=True)
    os.makedirs(OUTPUT_DIR)
    labels = open(os.path.join(OUTPUT_DIR, "labels.txt"), 'w')
    labels.truncate()
    i = 0
    chiIdx = 0
    outDir = None

    # http://stackoverflow.com/questions/50499/how-do-i-get-the-path-and-name-of-the-file-that-is-currently-executing
    selfPath = os.path.abspath(inspect.getfile(inspect.currentframe()))
    mainDir, _ = os.path.split(selfPath)
    dirFonts = os.path.join(mainDir, 'fonts_Chinese')
    fnFonts = filter(lambda fn: os.path.splitext(fn)[1].lower() in [
                     '.ttf', '.otf'], os.listdir(dirFonts))
    fontsChinese = list(
        map(lambda fn: os.path.join(dirFonts, fn), fnFonts))

    chiFiles = sorted(glob.glob('newsgroup/corpus-*.txt'))
    outputPerChiFile = OUTPUT_NUM / len(chiFiles)
    initChineseSource(chiFiles[0])
    chiIdx += 1

    for im, text in generate(OUTPUT_NUM):
        if i % OUTPUT_BATCH == 0:
            outDir = os.path.join(OUTPUT_DIR, str(int(i/OUTPUT_BATCH)))
            os.makedirs(outDir)
        if i != 0 and i % outputPerChiFile == 0:
            initChineseSource(chiFiles[chiIdx])
            chiIdx += 1
        outf = os.path.join(outDir, '%s.jpg' % i)
        # pygame.image.save(im, outf) #pygame
        # im.save(outf) #PIL image
        io.imsave(outf, im)  # scikit-image
        labels.write('%s/%s.jpg\t%s\n' % (int(i/OUTPUT_BATCH),
                                          i, text))
        print('done %s.jpg, text: %s' % (i, text))
        i += 1
    labels.close() 
开发者ID:deepinsight,项目名称:insightocr,代码行数:43,代码来源:gen.py


注:本文中的pygame.init方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。