python类K_ESCAPE的实例源码

menus.py 文件源码 项目:project_xcape 作者: OthmanEmpire 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                self.audio.state = "pause"
game_functions.py 文件源码 项目:Galaxian-Against-COMP140 作者: tomjlw 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
def check_keydown_events(event, ai_settings, screen, ship, bullets):
    if event.key == pygame.K_RIGHT:
        ship.moving_right = True
    elif event.key == pygame.K_LEFT:
        ship.moving_left = True
    elif event.key == pygame.K_SPACE:
        fire_bullet(ai_settings, screen, ship, bullets)
    elif event.key == pygame.K_ESCAPE:
        sys.exit()
BusStopPi.py 文件源码 项目:BusStopPi 作者: LoveBootCaptain 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def loop():

    update_data()

    running = True

    while running:

        draw_to_tft()

        for event in pygame.event.get():

            if event.type == pygame.QUIT:

                running = False

                quit_all()

            elif event.type == pygame.KEYDOWN:

                if event.key == pygame.K_ESCAPE:

                    running = False

                    quit_all()

                elif event.key == pygame.K_SPACE:

                    print('\nSPACE')

    quit_all()
client.py 文件源码 项目:ice-mud-game 作者: PyBargain 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def handle_key(self, time):
        """
        ??????
        """
        for event in pygame.event.get():
            if event.type == pygame.KEYUP and event.key == pygame.K_ESCAPE: self.stop()
        self.state_changed = self.key_binding.update(lambda key: pygame.key.get_pressed()[key], time, self)
eduactiv8.py 文件源码 项目:eduActiv8 作者: imiolek-ireneusz 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
def main():
    # create configuration object
    if android is not None or len(sys.argv) == 1:
        # Map the back button to the escape key.

        if android is not None:
            pygame.init()
            android.init()
            android.map_key(android.KEYCODE_BACK, pygame.K_ESCAPE)
        configo = classes.config.Config(android)

        # create the language object
        lang = classes.lang.Language(configo, path)

        # create the Thread objects and start the threads
        speaker = classes.speaker.Speaker(lang, configo, android)

        app = GamePlay(speaker, lang, configo)
        if android is None:
            speaker.start()
        app.run()
    elif len(sys.argv) == 2:
        if sys.argv[1] == "v" or sys.argv[1] == "version":
            from classes.cversion import ver
            print("eduactiv8-%s" % ver)
    else:
        print("Sorry arguments not recognized.")
game.py 文件源码 项目:pytetris 作者: catalinc 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def process_input(self):
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
            if event.type == pygame.KEYDOWN:
                if self.state.paused:
                    if event.key == pygame.K_r:
                        self.state.paused = False
                if self.state.game_over:
                    if event.key == pygame.K_r:
                        self.state = State(self.ROWS, self.COLS)
                    if event.key == pygame.K_ESCAPE:
                        sys.exit()
                if self.state.running:
                    if event.key == pygame.K_DOWN:
                        self.state.move_piece(board.DIRECTION_DOWN)
                    if event.key == pygame.K_LEFT:
                        self.state.move_piece(board.DIRECTION_LEFT)
                    if event.key == pygame.K_RIGHT:
                        self.state.move_piece(board.DIRECTION_RIGHT)
                    if event.key == pygame.K_x:
                        self.state.rotate_piece()
                    if event.key == pygame.K_z:
                        self.state.rotate_piece(True)
                    if event.key == pygame.K_SPACE:
                        self.state.drop_piece()
                    if event.key == pygame.K_p:
                        self.state.paused = True
pygame_functions.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def pause(milliseconds, allowEsc=True):
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = current_time + milliseconds
    while not (current_time > waittime or (keys[pygame.K_ESCAPE] and allowEsc)):
        pygame.event.clear()
        keys = pygame.key.get_pressed()
        if (keys[pygame.K_ESCAPE] and allowEsc):
            pygame.quit()
            sys.exit()
        current_time = pygame.time.get_ticks()
pygame_functions.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 28 收藏 0 点赞 0 评论 0
def endWait():
    print("Press ESC to quit")
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = 0
    while not keys[pygame.K_ESCAPE]:
        current_time = pygame.time.get_ticks()
        if current_time > waittime:
            pygame.event.clear()
            keys = pygame.key.get_pressed()
            waittime += 20
    pygame.quit()
pygame_functions.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
def updateDisplay():
    global bgSurface
    spriteRects = spriteGroup.draw(screen)
    textboxRects = textboxGroup.draw(screen)
    pygame.display.update()
    keys = pygame.key.get_pressed()
    if (keys[pygame.K_ESCAPE]):
        pygame.quit()
        sys.exit()
    spriteGroup.clear(screen, bgSurface)
    textboxGroup.clear(screen, bgSurface)
pygame_functions.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 23 收藏 0 点赞 0 评论 0
def pause(milliseconds, allowEsc=True):
    keys = pygame.key.get_pressed()
    current_time = pygame.time.get_ticks()
    waittime = current_time + milliseconds
    while not (current_time > waittime or (keys[pygame.K_ESCAPE] and allowEsc)):
        pygame.event.clear()
        keys = pygame.key.get_pressed()
        if (keys[pygame.K_ESCAPE] and allowEsc):
            pygame.quit()
            sys.exit()
        current_time = pygame.time.get_ticks()
pygame_functions.py 文件源码 项目:Pygame_Functions 作者: StevePaget 项目源码 文件源码 阅读 38 收藏 0 点赞 0 评论 0
def updateDisplay():
    global bgSurface
    spriteRects = spriteGroup.draw(screen)
    textboxRects = textboxGroup.draw(screen)
    pygame.display.update()
    keys = pygame.key.get_pressed()
    if (keys[pygame.K_ESCAPE]):
        pygame.quit()
        sys.exit()
    spriteGroup.clear(screen, bgSurface)
    textboxGroup.clear(screen, bgSurface)
cli.py 文件源码 项目:solarwolf 作者: pygame 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
def __pygamebox(title, message):
    try:
        import pygame
        pygame.quit() #clean out anything running
        pygame.display.init()
        pygame.font.init()
        screen = pygame.display.set_mode((460, 140))
        pygame.display.set_caption(title)
        font = pygame.font.Font(None, 18)
        foreg, backg, liteg = (0, 0, 0), (180, 180, 180), (210, 210, 210)
        ok = font.render('Ok', 1, foreg, liteg)
        okbox = ok.get_rect().inflate(200, 10)
        okbox.centerx = screen.get_rect().centerx
        okbox.bottom = screen.get_rect().bottom - 10
        screen.fill(backg)
        screen.fill(liteg, okbox)
        screen.blit(ok, okbox.inflate(-200, -10))
        pos = [10, 10]
        for text in message.split('\n'):
            if text:
                msg = font.render(text, 1, foreg, backg)
                screen.blit(msg, pos)
            pos[1] += font.get_height()
        pygame.display.flip()
        stopkeys = pygame.K_ESCAPE, pygame.K_SPACE, pygame.K_RETURN, pygame.K_KP_ENTER
        while 1:
            e = pygame.event.wait()
            if e.type == pygame.QUIT or \
                       (e.type == pygame.KEYDOWN and e.key in stopkeys) or \
                       (e.type == pygame.MOUSEBUTTONDOWN and okbox.collidepoint(e.pos)):
                break
        pygame.quit()
    except pygame.error:
        raise ImportError
errorbox.py 文件源码 项目:solarwolf 作者: pygame 项目源码 文件源码 阅读 32 收藏 0 点赞 0 评论 0
def __pygame(title, message):
    try:
        import pygame, pygame.font
        pygame.quit() #clean out anything running
        pygame.display.init()
        pygame.font.init()
        screen = pygame.display.set_mode((460, 140))
        pygame.display.set_caption(title)
        font = pygame.font.Font(None, 18)
        foreg = 0, 0, 0
        backg = 200, 200, 200
        liteg = 255, 255, 255
        ok = font.render('Ok', 1, foreg)
        screen.fill(backg)
        okbox = ok.get_rect().inflate(20, 10)
        okbox.centerx = screen.get_rect().centerx
        okbox.bottom = screen.get_rect().bottom - 10
        screen.fill(liteg, okbox)
        screen.blit(ok, okbox.inflate(-20, -10))
        pos = [20, 20]
        for text in message.split('\n'):
            msg = font.render(text, 1, foreg)
            screen.blit(msg, pos)
            pos[1] += font.get_height()

        pygame.display.flip()
        while 1:
            e = pygame.event.wait()
            if (e.type == pygame.QUIT or e.type == pygame.MOUSEBUTTONDOWN or
                        pygame.KEYDOWN and e.key
                        in (pygame.K_ESCAPE, pygame.K_SPACE, pygame.K_RETURN)):
                break
        pygame.quit()
    except pygame.error:
        raise ImportError
tttoe.py 文件源码 项目:TicTacTio 作者: DevelopForLizardz 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def main(self):
        """
        Start the game
        :return: None
        """

        logging.info("Starting game")
        self.board.initUI()
        winner = None

        while not self.exit:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    self.exit = True
                elif not self.gameOver:
                    currentPlayer = self.players[self.turn]
                    move = currentPlayer.getMove()
                    self.turn = 'x' if self.turn == 'o' else 'o'

                    winner = self.board.checkForWin(move)[0]
                    if winner in ['x', 'o', 't']:
                        logging.info("Game has ended with status: {}".format(winner))
                        self.gameOver = True
                        self.board.displayWinner(self.board.checkForWin(move))
                else:
                    if event.type == pygame.KEYDOWN:
                        if event.key in [pygame.K_RETURN, pygame.K_SPACE]:
                            self.gameOver = False
                            self.board.reset()
                            self.board.initUI()
                    elif event.key in [pygame.K_ESCAPE, pygame.K_DELETE, pygame.K_BACKSPACE]:
                        self.exit = True

            pygame.display.flip()
            self.clock.tick(self.fps)

        self.exit = False
        self.gameOver = False
        self.board.reset()
        return winner
game.py 文件源码 项目:pyweek-game-poor-man-medal-of-honor-game 作者: ReekenX 项目源码 文件源码 阅读 19 收藏 0 点赞 0 评论 0
def event_loop(self):
        for event in pg.event.get():
            self.keys = pg.key.get_pressed()
            if event.type == pg.QUIT or self.keys[pg.K_ESCAPE]:
                self.done = True
                self.closed = True
            elif event.type == pg.KEYDOWN and self.keys[pg.K_i]:
                #  import pdb
                #  pdb.set_trace()
                print 'Player at: '
                print self.player.rect
                print self.player.rect.x
                print self.player.rect.y
                print 'Camera at: '
                print self.camera.state
                print 'Painting at: '
                print  [(self.mouse[0], self.mouse[1]), (self.player.rect.centerx + abs(self.camera.state.x), self.player.rect.centery + abs(self.camera.state.y))]
                print 'Angle:'
                print self.angle
            elif event.type == pg.KEYDOWN:
                self.player.add_direction(event.key)
            elif event.type == pg.KEYUP:
                self.player.pop_direction(event.key)

            if event.type == pg.MOUSEBUTTONDOWN and event.button == 1:
                if self.player.bullets_left > 0 and self.player.weapon:
                    self.player_bullets.add(Bullet(self.player.rect.center, self.angle))
                    self.player.bullets_left -= 1
            elif event.type == pg.MOUSEMOTION:
                self.get_angle(event.pos)
event.py 文件源码 项目:pool 作者: max-kov 项目源码 文件源码 阅读 36 收藏 0 点赞 0 评论 0
def events():
    closed = False
    quit = False

    for event in pygame.event.get():
        if event.type == pygame.QUIT:
            closed = True
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                quit = True

    return {"quit_to_main_menu": quit,
            "closed": closed,
            "clicked": pygame.mouse.get_pressed()[0],
            "mouse_pos": np.array(pygame.mouse.get_pos())}
state.py 文件源码 项目:team-brisket-pyweek21 作者: AjaxVM 项目源码 文件源码 阅读 30 收藏 0 点赞 0 评论 0
def handleEvents(self):
        #do event stuff
        #basic setup that allows quitting

        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                self.game.forceQuit()
                return
            elif event.type == pygame.KEYDOWN:
                log.info('Got Key Event: '+str(event))
                if event.key == pygame.K_ESCAPE:
                    self.game.forceQuit()
                    return
join_game.py 文件源码 项目:team-brisket-pyweek21 作者: AjaxVM 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.doQuit()
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.game.gotoState('main_menu')
                    return
                elif event.key == pygame.K_RETURN:
                    self.doJoinServer()
                    return
                else:
                    self.ip_entry.handleKey(event.key)
winners.py 文件源码 项目:OfMagesAndMagic 作者: munnellg 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
def handle_event(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key in [pygame.K_ESCAPE]:
                self.parent.trigger_exit_to_main()
main_menu.py 文件源码 项目:OfMagesAndMagic 作者: munnellg 项目源码 文件源码 阅读 26 收藏 0 点赞 0 评论 0
def __init__(self, main_menu):
        self.parent     = main_menu.parent
        self.main_menu  = main_menu
        self.teams      = self.parent.teams

        self.parent.event_handler.register_key_listener(self.handle_keypress)
        self.title = text_renderer.render_title("Teams", colours.COLOUR_WHITE)
        self.title_position = (
            (self.parent.resolution[0] - self.title.get_width())// 2,
            15
        )

        self.directions = {
            pygame.K_RIGHT     : [1],
            pygame.K_LEFT      : [-1],
            pygame.K_ESCAPE    : [3],
            pygame.K_BACKSPACE : [3]
        }

        self.animation = None

        menu_region = (self.parent.resolution[0],
            600
        )
        self.menu = TeamViewer(menu_region, self.teams)
        self.menu.register_finished_callback(self.finished)


问题


面经


文章

微信
公众号

扫码关注公众号