Python pygame.init() Examples
The following are 30
code examples of pygame.init().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
pygame
, or try the search function
.

Example #1
Source File: polygon.py From kvae with MIT License | 8 votes |
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
Example #2
Source File: box.py From kvae with MIT License | 7 votes |
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
Example #3
Source File: atari_game.py From dynamic-training-with-apache-mxnet-on-aws with Apache License 2.0 | 6 votes |
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
Example #4
Source File: scan_agent.py From streetlearn with Apache License 2.0 | 6 votes |
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)
Example #5
Source File: oracle_agent.py From streetlearn with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: fig24_05.py From PythonClassBook with GNU General Public License v3.0 | 6 votes |
def main(): # check command line arguments if len( sys.argv ) != 2: sys.exit( "Incorrect number of arguments." ) else: file = sys.argv[ 1 ] # initialize pygame pygame.init() # initialize GUI movie, playImageSize = createGUI( file ) # wait until player wants to close program while 1: event = pygame.event.wait() # close window if event.type == QUIT or \ ( event.type == KEYDOWN and event.key == K_ESCAPE ): break # click play button and play movie pressed = pygame.mouse.get_pressed()[ 0 ] position = pygame.mouse.get_pos() # button pressed if pressed: if playImageSize.collidepoint( position ): movie.play()
Example #7
Source File: Game8.py From Games with MIT License | 6 votes |
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)
Example #8
Source File: Game5.py From Games with MIT License | 6 votes |
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
Example #9
Source File: test_pyopengl.py From twitchslam with MIT License | 6 votes |
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)
Example #10
Source File: 六个类合一.py From Python24 with MIT License | 6 votes |
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() # 运行游戏程序
Example #11
Source File: pyrpg01.py From pygame with MIT License | 6 votes |
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()
Example #12
Source File: 1945.py From pygame with MIT License | 6 votes |
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()
Example #13
Source File: chara_anime.py From pygame with MIT License | 6 votes |
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()
Example #14
Source File: move.py From pygame with MIT License | 6 votes |
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()
Example #15
Source File: __init__.py From Tkinter-GUI-Programming-by-Example with MIT License | 5 votes |
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')
Example #16
Source File: gen.py From insightocr with MIT License | 5 votes |
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()
Example #17
Source File: input.py From QPong with Apache License 2.0 | 5 votes |
def __init__(self): self.running = True pygame.init() pygame.joystick.init() self.num_joysticks = pygame.joystick.get_count() if self.num_joysticks > 0: self.joystick = pygame.joystick.Joystick(0) self.joystick.init() self.gamepad_repeat_delay = 200 self.gamepad_neutral = True self.gamepad_pressed_timer = 0 self.gamepad_last_update = pygame.time.get_ticks()
Example #18
Source File: box_gravity.py From kvae with MIT License | 5 votes |
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
Example #19
Source File: tank.py From Jtyoui with MIT License | 5 votes |
def __init__(self): if not os.path.exists(Tank_IMAGE_POSITION): os.makedirs(Tank_IMAGE_POSITION) pygame.init() pygame.font.init() self.display = pygame.display self.window = self.display.set_mode([SCREEN_WIDTH, SCREEN_HEIGHT], pygame.RESIZABLE, 32) self.display.set_caption('坦克世界') self.my_tank = MyTank(MY_BIRTH_LEFT, MY_BIRTH_TOP, self.window) self.creat_enemy_number = 10 self.my_tank_lift = 3 self.creat_enemy(self.creat_enemy_number) self.creat_walls() self.font = pygame.font.SysFont('kai_ti', 18) self.number = 1
Example #20
Source File: play.py From Performance-RNN-PyTorch with MIT License | 5 votes |
def display(): global entities, lock, width, height, done pygame.init() pygame.display.set_caption('generator') screen = pygame.display.set_mode((width, height)) clock = pygame.time.Clock() while not done: for event in pygame.event.get(): if event.type == pygame.QUIT: done = True screen.fill(pygame.color.Color('black')) lock.acquire() entities = [entity for entity in entities if not entity.done] for i, entity in enumerate(entities): if i + 1 < len(entities): next_ent = entities[i + 1] pygame.draw.line(screen, entity.get_color(), entity.position, next_ent.position) for entity in entities: entity.render(screen) entity.update() lock.release() pygame.display.flip() clock.tick(60) pygame.quit() #==================================================================== # Synth #====================================================================
Example #21
Source File: game.py From Games with MIT License | 5 votes |
def __init__(self, cfg, **kwargs): pygame.init() pygame.display.set_caption('Breakout clone-微信公众号: Charles的皮卡丘') pygame.mixer.init() self.screen = pygame.display.set_mode((cfg.SCREENWIDTH, cfg.SCREENHEIGHT)) self.font_small = pygame.font.Font(cfg.FONTPATH, 20) self.font_big = pygame.font.Font(cfg.FONTPATH, 30) self.hit_sound = pygame.mixer.Sound(cfg.HITSOUNDPATH) pygame.mixer.music.load(cfg.BGMPATH) pygame.mixer.music.play(-1, 0.0) self.cfg = cfg
Example #22
Source File: Game21.py From Games with MIT License | 5 votes |
def initGame(): pygame.init() pygame.mixer.init() screen = pygame.display.set_mode(cfg.SCREENSIZE) pygame.display.set_caption('Whac A Mole-微信公众号:Charles的皮卡丘') return screen
Example #23
Source File: Game10.py From Games with MIT License | 5 votes |
def main(): pygame.init() pygame.font.init() pygame.mixer.init() screen = pygame.display.set_mode((WIDTH, HEIGHT)) pygame.display.set_caption('飞机大战-公众号: Charles的皮卡丘') num_player = start_interface(screen) if num_player == 1: while True: GameDemo(num_player=1, screen=screen) end_interface(screen) else: while True: GameDemo(num_player=2, screen=screen) end_interface(screen)
Example #24
Source File: Game23.py From Games with MIT License | 5 votes |
def main(cfg): # 游戏初始化 pygame.init() screen = pygame.display.set_mode(cfg.SCREENSIZE) pygame.display.set_caption('2048 —— 微信公众号:Charles的皮卡丘') # 播放背景音乐 pygame.mixer.music.load(cfg.BGMPATH) pygame.mixer.music.play(-1) # 实例化2048游戏 game_2048 = Game2048(matrix_size=cfg.GAME_MATRIX_SIZE, max_score_filepath=cfg.MAX_SCORE_FILEPATH) # 游戏主循环 clock = pygame.time.Clock() is_running = True while is_running: screen.fill(pygame.Color(cfg.BG_COLOR)) # --按键检测 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]: game_2048.setDirection({pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'}[event.key]) # --更新游戏状态 game_2048.update() if game_2048.isgameover: game_2048.saveMaxScore() is_running = False # --将必要的游戏元素画到屏幕上 drawGameMatrix(screen, game_2048.game_matrix, cfg) start_x, start_y = drawScore(screen, game_2048.score, game_2048.max_score, cfg) drawGameIntro(screen, start_x, start_y, cfg) # --屏幕更新 pygame.display.update() clock.tick(cfg.FPS) return endInterface(screen, cfg)
Example #25
Source File: Game24.py From Games with MIT License | 5 votes |
def main(cfg): # 游戏初始化 pygame.init() screen = pygame.display.set_mode(cfg.SCREENSIZE) pygame.display.set_caption('Greedy Snake —— 微信公众号:Charles的皮卡丘') clock = pygame.time.Clock() # 播放背景音乐 pygame.mixer.music.load(cfg.BGMPATH) pygame.mixer.music.play(-1) # 游戏主循环 snake = Snake(cfg) apple = Apple(cfg, snake.coords) score = 0 while True: screen.fill(cfg.BLACK) # --按键检测 for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key in [pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]: snake.setDirection({pygame.K_UP: 'up', pygame.K_DOWN: 'down', pygame.K_LEFT: 'left', pygame.K_RIGHT: 'right'}[event.key]) # --更新贪吃蛇和食物 if snake.update(apple): apple = Apple(cfg, snake.coords) score += 1 # --判断游戏是否结束 if snake.isgameover: break # --显示游戏里必要的元素 drawGameGrid(cfg, screen) snake.draw(screen) apple.draw(screen) showScore(cfg, score, screen) # --屏幕更新 pygame.display.update() clock.tick(cfg.FPS) return endInterface(screen, cfg)
Example #26
Source File: Game13.py From Games with MIT License | 5 votes |
def main(): # 初始化 pygame.init() pygame.display.set_caption(u'外星人入侵-Charles的皮卡丘') screen = pygame.display.set_mode([WIDTH, HEIGHT]) pygame.mixer.init() pygame.mixer.music.load('./music/bg.mp3') pygame.mixer.music.set_volume(0.4) pygame.mixer.music.play(-1) while True: is_win = startGame(screen) endInterface(screen, BLACK, is_win)
Example #27
Source File: Game14.py From Games with MIT License | 5 votes |
def initialize(): pygame.init() icon_image = pygame.image.load(ICONPATH) pygame.display.set_icon(icon_image) screen = pygame.display.set_mode([606, 606]) pygame.display.set_caption('Pacman-微信公众号Charles的皮卡丘') return screen
Example #28
Source File: Game1.py From Games with MIT License | 5 votes |
def initGame(): # 初始化pygame, 设置展示窗口 pygame.init() pygame.mixer.init() screen = pygame.display.set_mode(cfg.SCREENSIZE) pygame.display.set_caption('Bunnies and Badgers —— 微信公众号: Charles的皮卡丘') # 加载必要的游戏素材 game_images = {} for key, value in cfg.IMAGE_PATHS.items(): game_images[key] = pygame.image.load(value) game_sounds = {} for key, value in cfg.SOUNDS_PATHS.items(): if key != 'moonlight': game_sounds[key] = pygame.mixer.Sound(value) return screen, game_images, game_sounds
Example #29
Source File: Game6.py From Games with MIT License | 5 votes |
def initGame(): pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((cfg.SCREENWIDTH, cfg.SCREENHEIGHT)) pygame.display.set_caption('Flappy Bird-微信公众号: Charles的皮卡丘') return screen
Example #30
Source File: Game17.py From Games with MIT License | 5 votes |
def main(): # 初始化 pygame.init() pygame.mixer.init() screen = pygame.display.set_mode((config.WIDTH, config.HEIGHT)) pygame.display.set_caption('pingpong - 微信公众号: Charles的皮卡丘') # 开始游戏 while True: score_left, score_right = runDemo(screen) endInterface(screen, score_left, score_right)