Python pygame.quit() Examples
The following are 30
code examples of pygame.quit().
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: video_looper.py From pi_video_looper with GNU General Public License v2.0 | 10 votes |
def _handle_keyboard_shortcuts(self): while self._running: event = pygame.event.wait() if event.type == pygame.KEYDOWN: # If pressed key is ESC quit program if event.key == pygame.K_ESCAPE: self._print("ESC was pressed. quitting...") self.quit() if event.key == pygame.K_k: self._print("k was pressed. skipping...") self._player.stop(3) if event.key == pygame.K_s: if self._playbackStopped: self._print("s was pressed. starting...") self._playbackStopped = False else: self._print("s was pressed. stopping...") self._playbackStopped = True self._player.stop(3)
Example #2
Source File: gamestart.py From Games with MIT License | 8 votes |
def GameStartInterface(screen, sounds, cfg): dino = Dinosaur(cfg.IMAGE_PATHS['dino']) ground = pygame.image.load(cfg.IMAGE_PATHS['ground']).subsurface((0, 0), (83, 19)) rect = ground.get_rect() rect.left, rect.bottom = cfg.SCREENSIZE[0]/20, cfg.SCREENSIZE[1] clock = pygame.time.Clock() press_flag = False while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_SPACE or event.key == pygame.K_UP: press_flag = True dino.jump(sounds) dino.update() screen.fill(cfg.BACKGROUND_COLOR) screen.blit(ground, rect) dino.draw(screen) pygame.display.update() clock.tick(cfg.FPS) if (not dino.is_jumping) and press_flag: return True
Example #3
Source File: Game17.py From Games with MIT License | 7 votes |
def startInterface(screen): clock = pygame.time.Clock() while True: screen.fill((41, 36, 33)) button_1 = Button(screen, (150, 175), '1 Player') button_2 = Button(screen, (150, 275), '2 Player') for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if button_1.collidepoint(pygame.mouse.get_pos()): return 1 elif button_2.collidepoint(pygame.mouse.get_pos()): return 2 clock.tick(10) pygame.display.update()
Example #4
Source File: startinterface.py From Games with MIT License | 7 votes |
def startInterface(screen, begin_image_paths): begin_images = [pygame.image.load(begin_image_paths[0]), pygame.image.load(begin_image_paths[1])] begin_image = begin_images[0] while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.MOUSEMOTION: mouse_pos = pygame.mouse.get_pos() if mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): begin_image = begin_images[1] else: begin_image = begin_images[0] elif event.type == pygame.MOUSEBUTTONDOWN: mouse_pos = pygame.mouse.get_pos() if event.button == 1 and mouse_pos[0] in list(range(419, 574)) and mouse_pos[1] in list(range(374, 416)): return True screen.blit(begin_image, (0, 0)) pygame.display.update()
Example #5
Source File: Game4.py From Games with MIT License | 7 votes |
def ShowStartInterface(screen, screensize): screen.fill((255, 255, 255)) tfont = pygame.font.Font(cfg.FONTPATH, screensize[0]//5) cfont = pygame.font.Font(cfg.FONTPATH, screensize[0]//20) title = tfont.render(u'滑雪游戏', True, (255, 0, 0)) content = cfont.render(u'按任意键开始游戏', True, (0, 0, 255)) trect = title.get_rect() trect.midtop = (screensize[0]/2, screensize[1]/5) crect = content.get_rect() crect.midtop = (screensize[0]/2, screensize[1]/2) screen.blit(title, trect) screen.blit(content, crect) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: return pygame.display.update()
Example #6
Source File: Game3.py From Games with MIT License | 7 votes |
def ShowEndInterface(screen, width, height): screen.fill(cfg.BACKGROUNDCOLOR) font = pygame.font.Font(cfg.FONTPATH, width//15) title = font.render('恭喜! 你成功完成了拼图!', True, (233, 150, 122)) rect = title.get_rect() rect.midtop = (width/2, height/2.5) screen.blit(title, rect) pygame.display.update() while True: for event in pygame.event.get(): if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() pygame.display.update()
Example #7
Source File: Game3.py From Games with MIT License | 7 votes |
def ShowStartInterface(screen, width, height): screen.fill(cfg.BACKGROUNDCOLOR) tfont = pygame.font.Font(cfg.FONTPATH, width//4) cfont = pygame.font.Font(cfg.FONTPATH, width//20) title = tfont.render('拼图游戏', True, cfg.RED) content1 = cfont.render('按H或M或L键开始游戏', True, cfg.BLUE) content2 = cfont.render('H为5*5模式, M为4*4模式, L为3*3模式', True, cfg.BLUE) trect = title.get_rect() trect.midtop = (width/2, height/10) crect1 = content1.get_rect() crect1.midtop = (width/2, height/2.2) crect2 = content2.get_rect() crect2.midtop = (width/2, height/1.8) screen.blit(title, trect) screen.blit(content1, crect1) screen.blit(content2, crect2) while True: for event in pygame.event.get(): if (event.type == pygame.QUIT) or (event.type == pygame.KEYDOWN and event.key == pygame.K_ESCAPE): pygame.quit() sys.exit() elif event.type == pygame.KEYDOWN: if event.key == ord('l'): return 3 elif event.key == ord('m'): return 4 elif event.key == ord('h'): return 5 pygame.display.update()
Example #8
Source File: pyrpg27.py From pygame with MIT License | 6 votes |
def title_handler(self, event): """タイトル画面のイベントハンドラ""" global game_state if event.type == KEYUP and event.key == K_UP: self.title.menu -= 1 if self.title.menu < 0: self.title.menu = 0 elif event.type == KEYDOWN and event.key == K_DOWN: self.title.menu += 1 if self.title.menu > 2: self.title.menu = 2 if event.type == KEYDOWN and event.key == K_SPACE: sounds["pi"].play() if self.title.menu == Title.START: game_state = FIELD self.map.create("field") # フィールドマップへ elif self.title.menu == Title.CONTINUE: pass elif self.title.menu == Title.EXIT: pygame.quit() sys.exit()
Example #9
Source File: Game10.py From Games with MIT License | 6 votes |
def end_interface(screen): clock = pygame.time.Clock() while True: button_1 = BUTTON(screen, (330, 190), '重新开始') button_2 = BUTTON(screen, (330, 305), '退出游戏') for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if button_1.collidepoint(pygame.mouse.get_pos()): return elif button_2.collidepoint(pygame.mouse.get_pos()): pygame.quit() sys.exit() clock.tick(60) pygame.display.update()
Example #10
Source File: Game10.py From Games with MIT License | 6 votes |
def start_interface(screen): clock = pygame.time.Clock() while True: button_1 = BUTTON(screen, (330, 190), '单人模式') button_2 = BUTTON(screen, (330, 305), '双人模式') for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if button_1.collidepoint(pygame.mouse.get_pos()): return 1 elif button_2.collidepoint(pygame.mouse.get_pos()): return 2 clock.tick(60) pygame.display.update()
Example #11
Source File: Game12.py From Games with MIT License | 6 votes |
def switchInterface(screen): screen.fill(Config.get('bg_color')) clock = pygame.time.Clock() while True: button_1 = BUTTON(screen, (95, 150), '进入下关') button_2 = BUTTON(screen, (95, 305), '退出游戏') for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.MOUSEBUTTONDOWN: if button_1.collidepoint(pygame.mouse.get_pos()): return elif button_2.collidepoint(pygame.mouse.get_pos()): quitGame() clock.tick(60) pygame.display.update()
Example #12
Source File: breakout01.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"Breakout 01 パドルを動かす") # スプライトグループを作成して登録 all = pygame.sprite.RenderUpdates() Paddle.containers = all # パドルを作成 paddle = Paddle() clock = pygame.time.Clock() while True: clock.tick(60) screen.fill((0,0,0)) all.update() all.draw(screen) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit()
Example #13
Source File: pyrpg26.py From pygame with MIT License | 6 votes |
def check_event(self): """イベントハンドラ""" for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit() # 表示されているウィンドウに応じてイベントハンドラを変更 if self.game_state == TITLE: self.title_handler(event) elif self.game_state == FIELD: self.field_handler(event) elif self.game_state == COMMAND: self.cmd_handler(event) elif self.game_state == TALK: self.talk_handler(event)
Example #14
Source File: pyrpg26.py From pygame with MIT License | 6 votes |
def title_handler(self, event): """タイトル画面のイベントハンドラ""" if event.type == KEYUP and event.key == K_UP: self.title.menu -= 1 if self.title.menu < 0: self.title.menu = 0 elif event.type == KEYDOWN and event.key == K_DOWN: self.title.menu += 1 if self.title.menu > 2: self.title.menu = 2 if event.type == KEYDOWN and event.key == K_SPACE: sounds["pi"].play() if self.title.menu == Title.START: self.game_state = FIELD self.map.create("field") # フィールドマップへ elif self.title.menu == Title.CONTINUE: pass elif self.title.menu == Title.EXIT: pygame.quit() sys.exit()
Example #15
Source File: pyrpg27.py From pygame with MIT License | 6 votes |
def check_event(self): """イベントハンドラ""" global game_state for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() if event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit() # 表示されているウィンドウに応じてイベントハンドラを変更 if game_state == TITLE: self.title_handler(event) elif game_state == FIELD: self.field_handler(event) elif game_state == COMMAND: self.cmd_handler(event) elif game_state == TALK: self.talk_handler(event) elif game_state == BATTLE_INIT: self.battle_init_handler(event) elif game_state == BATTLE_COMMAND: self.battle_cmd_handler(event) elif game_state == BATTLE_PROCESS: self.battle_proc_handler(event)
Example #16
Source File: utils.py From Games with MIT License | 6 votes |
def endInterface(screen, color, is_win): screen.fill(color) clock = pygame.time.Clock() if is_win: text = 'VICTORY' else: text = 'FAILURE' font = pygame.font.SysFont('arial', 30) text_render = font.render(text, 1, (255, 255, 255)) while True: for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if (event.type == pygame.KEYDOWN) or (event.type == pygame.MOUSEBUTTONDOWN): return screen.blit(text_render, (350, 300)) clock.tick(60) pygame.display.update()
Example #17
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 #18
Source File: interfaces.py From Games with MIT License | 6 votes |
def showEndGameInterface(screen, exitcode, accuracy, game_images): font = pygame.font.Font(None, 24) text = font.render(f"Accuracy: {accuracy}%", True, (255, 0, 0)) text_rect = text.get_rect() text_rect.centerx = screen.get_rect().centerx text_rect.centery = screen.get_rect().centery + 24 while True: screen.fill(0) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if exitcode: screen.blit(game_images['youwin'], (0, 0)) else: screen.blit(game_images['gameover'], (0, 0)) screen.blit(text, text_rect) pygame.display.flip()
Example #19
Source File: video_looper.py From pi_video_looper with GNU General Public License v2.0 | 6 votes |
def _idle_message(self): """Print idle message from file reader.""" # Print message to console. message = self._reader.idle_message() self._print(message) # Do nothing else if the OSD is turned off. if not self._osd: return # Display idle message in center of screen. label = self._render_text(message) lw, lh = label.get_size() sw, sh = self._screen.get_size() self._screen.fill(self._bgcolor) self._screen.blit(label, (sw/2-lw/2, sh/2-lh/2)) # If keyboard control is enabled, display message about it if self._keyboard_control: label2 = self._render_text('press ESC to quit') l2w, l2h = label2.get_size() self._screen.blit(label2, (sw/2-l2w/2, sh/2-l2h/2+lh)) pygame.display.update()
Example #20
Source File: 六个类合一.py From Python24 with MIT License | 5 votes |
def game_over(self): # 停止游戏引擎 pygame.quit() # 关闭窗口,退出游戏, sys.exit()
Example #21
Source File: no_rendering_mode.py From scenario_runner with MIT License | 5 votes |
def exit_game(): module_manager.clear_modules() pygame.quit() sys.exit() # ============================================================================== # -- Main -------------------------------------------------------------------- # ==============================================================================
Example #22
Source File: environment.py From 2019-OSS-Summer-RL with MIT License | 5 votes |
def quit_game(self): try: self.__game_over = True if self.__enable_render is True: pygame.display.quit() pygame.quit() except Exception: pass
Example #23
Source File: manual_control.py From scenario_runner with MIT License | 5 votes |
def game_loop(args): pygame.init() pygame.font.init() world = None try: client = carla.Client(args.host, args.port) client.set_timeout(2.0) display = pygame.display.set_mode( (args.width, args.height), pygame.HWSURFACE | pygame.DOUBLEBUF) hud = HUD(args.width, args.height) world = WorldSR(client.get_world(), hud, args) controller = KeyboardControl(world, args.autopilot) clock = pygame.time.Clock() while True: clock.tick_busy_loop(60) if controller.parse_events(client, world, clock): return if not world.tick(clock): return world.render(display) pygame.display.flip() finally: if (world and world.recording_enabled): client.stop_recorder() if world is not None: world.destroy() pygame.quit() # ============================================================================== # -- main() -------------------------------------------------------------------- # ==============================================================================
Example #24
Source File: human_agent.py From scenario_runner with MIT License | 5 votes |
def __init__(self, parent): self.quit = False self._parent = parent self._width = 800 self._height = 600 self._throttle_delta = 0.05 self._steering_delta = 0.01 self._surface = None pygame.init() pygame.font.init() self._clock = pygame.time.Clock() self._display = pygame.display.set_mode((self._width, self._height), pygame.HWSURFACE | pygame.DOUBLEBUF) pygame.display.set_caption("Human Agent")
Example #25
Source File: gui.py From openag_brain_box with GNU General Public License v3.0 | 5 votes |
def handleEvents(self): for event in pygame.event.get(): if event.type == pygame.QUIT or (event.type == KEYDOWN and event.key == K_ESCAPE) : self.webcam.stop() pygame.quit() sys.exit() elif event.type == pygame.MOUSEBUTTONUP: x,y = pygame.mouse.get_pos() logger.info('{}, {}'.format(x,y)) if 320<x<800: if self.canny: self.canny = False else: self.canny = True
Example #26
Source File: block.py From pygame with MIT License | 5 votes |
def key_handler(self): """キー入力処理""" for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit()
Example #27
Source File: Game17.py From Games with MIT License | 5 votes |
def endInterface(screen, score_left, score_right): clock = pygame.time.Clock() font1 = pygame.font.Font(config.FONTPATH, 30) font2 = pygame.font.Font(config.FONTPATH, 20) msg = 'Player on left won!' if score_left > score_right else 'Player on right won!' texts = [font1.render(msg, True, config.WHITE), font2.render('Press ESCAPE to quit.', True, config.WHITE), font2.render('Press ENTER to continue or play again.', True, config.WHITE)] positions = [[120, 200], [155, 270], [80, 300]] while True: screen.fill((41, 36, 33)) for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit() if event.type == pygame.KEYDOWN: if event.key == pygame.K_RETURN: return elif event.key == pygame.K_ESCAPE: sys.exit() pygame.quit() for text, pos in zip(texts, positions): screen.blit(text, pos) clock.tick(10) pygame.display.update()
Example #28
Source File: invader01.py From pygame with MIT License | 5 votes |
def main(): pygame.init() screen = pygame.display.set_mode(SCR_RECT.size) pygame.display.set_caption(u"Invader 01 自機を動かす") # スプライトグループを作成して登録 all = pygame.sprite.RenderUpdates() Player.containers = all # スプライトの画像を登録 Player.image = load_image("player.png") # 自機を作成 Player() clock = pygame.time.Clock() while True: clock.tick(60) screen.fill((0, 0, 0)) all.update() all.draw(screen) pygame.display.update() for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit()
Example #29
Source File: invader07.py From pygame with MIT License | 5 votes |
def key_handler(self): """キーハンドラー""" for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit() elif event.type == KEYDOWN and event.key == K_SPACE: if self.game_state == START: # スタート画面でスペースを押したとき self.game_state = PLAY elif self.game_state == GAMEOVER: # ゲームオーバー画面でスペースを押したとき self.init_game() # ゲームを初期化して再開 self.game_state = PLAY
Example #30
Source File: block.py From pygame with MIT License | 5 votes |
def key_handler(self): """キー入力処理""" for event in pygame.event.get(): if event.type == QUIT: pygame.quit() sys.exit() elif event.type == KEYDOWN and event.key == K_ESCAPE: pygame.quit() sys.exit()