Python pygame 模块,K_n() 实例源码

我们从Python开源项目中,提取了以下7个代码示例,用于说明如何使用pygame.K_n()

项目:Jeff-Long-Run    作者:matthiasrigaud    | 项目源码 | 文件源码
def manager(jeff, field, frame, level_select):
    for event in pygame.event.get():
        if event.type == pygame.QUIT or (event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_ESCAPE):
            sys.exit()
        elif event.type == pygame.KEYDOWN and jeff.is_dead() and event.dict["key"] == pygame.K_r:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            field.reload_level()
        elif event.type == pygame.KEYDOWN and (jeff.is_dead() or field.is_level_ended()) and event.dict["key"] == pygame.K_m:
            jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
            frame = "MENU"
        elif event.type == pygame.KEYDOWN and field.is_level_ended() and event.dict["key"] == pygame.K_n:
            next_level = level_select.get_next_level(field.get_level_file())
            if next_level != "":
                jeff = Jeff.Jeff([300, Constant.GROUND_HEIGHT - 50])
                field.load_level(next_level)
        elif event.type == pygame.KEYDOWN and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(True)
        elif event.type == pygame.KEYUP and event.dict["key"] == pygame.K_SPACE:
            jeff.jump(False)
    return jeff, frame
项目:CritterEvolution    作者:apockill    | 项目源码 | 文件源码
def updateKeys(self, event):
        if event.type == pygame.KEYDOWN:
            if event.key == K_r:
                keys["r"] = True
            elif event.key == pygame.K_e:
                keys["e"] = True
            elif event.key == pygame.K_p:
                keys["p"] = True
            elif event.key == pygame.K_n:
                keys["n"] = True

        if event.type == pygame.KEYUP:
            if event.key == pygame.K_r:
                keys["r"] = False
            elif event.key == pygame.K_e:
                keys["e"] = False
            elif event.key == pygame.K_p:
                keys["p"] = False
            elif event.key == pygame.K_n:
                keys["n"] = False

        if event.type == pygame.MOUSEBUTTONDOWN:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = True
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = True

        if event.type == pygame.MOUSEBUTTONUP:
            if event.button == 1:  # Left Mouse
                keys["mouseL"] = False
            if event.button == 3:  # Right Mouse
                keys["mouseR"] = False

        keys["mousePos"] =  pygame.mouse.get_pos()
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def from_json(self, raw):
        '''
        Load the object from JSON loaded from config file
        '''

        # First pass make sure all are valid
        for key in raw:
            if isinstance(raw[key], str):
                if not hasattr(pygame, raw[key]):
                    raise ConfigError(
                        "Invalid control for {}. Must be a valid pygame key constant".format(key)
                    )
                else:
                    raw[key] = getattr(pygame, raw[key])
            elif isinstance(raw[key], int):
                pass
            else:
                raise ConfigError(
                    "Controls must be a valid pygame key constant as a string or integer"
                )

        # Check for duplicates
        values = list(raw.values())
        values_set = set(values)

        if len(values) != len(values_set):
            raise ConfigError("Cannot have duplicate controls")

        self.up = raw.get('up', getattr(pygame, 'K_w'))
        self.down = raw.get('down', getattr(pygame, 'K_s'))
        self.left = raw.get('left', getattr(pygame, 'K_a'))
        self.right = raw.get('right', getattr(pygame, 'K_d'))
        self.jump = raw.get('jump', getattr(pygame, 'K_SPACE'))
        self.interact = raw.get('interact', getattr(pygame, 'K_e'))
        self.push = raw.get("push", getattr(pygame, "K_LSHIFT"))
        self.reset_code = raw.get("reset_code", getattr(pygame, "K_q"))
        self.toggle_sound = raw.get("toggle_sound", getattr(pygame, "K_m"))
        self.kill_self = raw.get("kill_self", getattr(pygame, "K_k"))
        self.reset_game = raw.get("reset_game", getattr(pygame, "K_n"))
项目:Projects    作者:it2school    | 项目源码 | 文件源码
def query(self,
              bold=False, italic=False, underline=False, antialiase=False):
        if self.aborted:
            return False
        spacing = 10
        offset = 20
        y = spacing
        f = self.f
        screen = self.screen
        screen.fill((255, 255, 255))
        pygame.display.flip()
        if not (bold or italic or underline or antialiase):
            text = "normal"
        else:
            modes = []
            if bold:
                modes.append("bold")
            if italic:
                modes.append("italic")
            if underline:
                modes.append("underlined")
            if antialiase:
                modes.append("antialiased")
            text = "%s (y/n):" % ('-'.join(modes),)
        f.set_bold(bold)
        f.set_italic(italic)
        f.set_underline(underline)
        s = f.render(text, antialiase, (0, 0, 0))
        screen.blit(s, (offset, y))
        y += s.get_size()[1] + spacing
        f.set_bold(False)
        f.set_italic(False)
        f.set_underline(False)
        s = f.render("(some comparison text)", False, (0, 0, 0))
        screen.blit(s, (offset, y))
        pygame.display.flip()
        while 1:
            for evt in pygame.event.get():
                if evt.type == pygame.KEYDOWN:
                    if evt.key == pygame.K_ESCAPE:
                        self.abort()
                        return False
                    if evt.key == pygame.K_y:
                        return True
                    if evt.key == pygame.K_n:
                        return False
                if evt.type == pygame.QUIT:
                    self.abort()
                    return False
项目:tictactoe    作者:FlankMe    | 项目源码 | 文件源码
def launch(screen):
    """Simple introductory menu"""   

    # Define some colors
    BLACK = (  0,   0,   0)
    WHITE = (255, 255, 255)
    RED   = (255,   0,   0)
    BLUE  = (  0,   0, 255)
    GREEN = (  0, 100,   0)
    YELLOW =(255, 250, 205)

    font_menu = pygame.font.Font(None, 24)

    menu_running = True
    while menu_running: 
        for event in pygame.event.get(): 
            if event.type == pygame.KEYDOWN: 
                if event.key == pygame.K_y:
                    HUMAN_START = True
                    menu_running = False  
                if event.key == pygame.K_n:
                    HUMAN_START = False
                    menu_running = False  

        screen.fill(BLACK)        

        menu = font_menu.render('WOULD YOU LIKE TO GO FIRST ?', 1, YELLOW)
        text_rect = menu.get_rect()
        text_rect.centery = screen.get_rect().centery
        text_rect.centerx = screen.get_rect().centerx
        screen.blit(menu, text_rect)

        menu = font_menu.render('(press \'y\' or \'n\')', 1, YELLOW)
        text_rect = menu.get_rect()
        text_rect.centery = screen.get_rect().centery + 25
        text_rect.centerx = screen.get_rect().centerx
        screen.blit(menu, text_rect)

        pygame.display.flip()

    del menu, font_menu
    return(HUMAN_START)
项目:AIFun    作者:Plottel    | 项目源码 | 文件源码
def query(self,
              bold=False, italic=False, underline=False, antialiase=False):
        if self.aborted:
            return False
        spacing = 10
        offset = 20
        y = spacing
        f = self.f
        screen = self.screen
        screen.fill((255, 255, 255))
        pygame.display.flip()
        if not (bold or italic or underline or antialiase):
            text = "normal"
        else:
            modes = []
            if bold:
                modes.append("bold")
            if italic:
                modes.append("italic")
            if underline:
                modes.append("underlined")
            if antialiase:
                modes.append("antialiased")
            text = "%s (y/n):" % ('-'.join(modes),)
        f.set_bold(bold)
        f.set_italic(italic)
        f.set_underline(underline)
        s = f.render(text, antialiase, (0, 0, 0))
        screen.blit(s, (offset, y))
        y += s.get_size()[1] + spacing
        f.set_bold(False)
        f.set_italic(False)
        f.set_underline(False)
        s = f.render("(some comparison text)", False, (0, 0, 0))
        screen.blit(s, (offset, y))
        pygame.display.flip()
        while 1:
            for evt in pygame.event.get():
                if evt.type == pygame.KEYDOWN:
                    if evt.key == pygame.K_ESCAPE:
                        self.abort()
                        return False
                    if evt.key == pygame.K_y:
                        return True
                    if evt.key == pygame.K_n:
                        return False
                if evt.type == pygame.QUIT:
                    self.abort()
                    return False
项目:pygame-event-calendar-and-pianobar    作者:scottpcrawford    | 项目源码 | 文件源码
def __init__(self, screen):
        self.done = False
        self.screen = screen
        self.clock = pg.time.Clock()
        self.fps = 60
        self.RADIO_STATION = '39' # or 1591330390268116913
        self.BACKGROUND_IMG = 'img/bg/day_tree.png'
        self.SCREEN_WIDTH = SCREEN_WIDTH
        self.SCREEN_HEIGHT = SCREEN_HEIGHT
        self.RADIO_RUNNING = False
        self.RESTING = False
        self.SHOWGOALS = False
        self.grass = 'img/bg/day_grass.png'
        self.day_clouds = pg.sprite.RenderUpdates()
        self.night_clouds = pg.sprite.RenderUpdates()
        self.all_sprites_list = pg.sprite.RenderUpdates()
        self.quote_list = return_list('quotes.txt')
        self.contributions = return_list('contributions.txt')
        self.goals = return_list('goals.txt')
        self.weather = Weather()
        self.weather_observation = {}
        self.phrase = random.choice(self.quote_list)
        #self.cwd = os.getcwd() #windows
        self.cwd = '/home/pi/.config/pianobar' # linux
        ## DAIYE COLORS ###
        self.HEADER_COLOR = pg.Color('black')
        self.CONTENT_COLOR = pg.Color('indianred4')
        self.BG_COLOR = pg.Color('skyblue')
        self.current_events = []
        self.upcoming_events = []

        # User events:
        self.UPDATECALENDAR = pg.USEREVENT + 1
        self.UPDATEQUOTE = pg.USEREVENT + 2
        self.NIGHTRADIO = pg.USEREVENT + 3
        self.CHANGESTATE = pg.USEREVENT + 4
        self.UPDATEWEATHER = pg.USEREVENT + 5
        #self.SHOWGOALS = pg.USEREVENT + 6
        pg.time.set_timer(self.UPDATECALENDAR, 60000) #update calendar every 60 seconds     
        pg.time.set_timer(self.UPDATEQUOTE, 20000) #update quote every 20 seconds
        pg.time.set_timer(self.NIGHTRADIO,300000) # check for relaxation radio time
        pg.time.set_timer(self.UPDATEWEATHER, 600000)
        pg.time.set_timer(self.CHANGESTATE, 300000)
        #pg.time.set_timer(self.SHOWGOALS, 6000)

        self.DAYGFX = load_gfx(os.path.join("img", "clouds", "day"))
        self.NTGFX = load_gfx(os.path.join("img", "clouds", "night"))
        self.BGIMG  = load_gfx(os.path.join('img', 'bg'))
        self.keymap_dict = {pg.K_n: 'n', pg.K_PLUS: '+', pg.K_KP_PLUS: '+', pg.K_EQUALS: '+', pg.K_MINUS: '-', pg.K_KP_MINUS: '-', 
                            pg.K_p: 'p', pg.K_SPACE: 'p', pg.K_q: 'q', pg.K_r: 'r', pg.K_s: 's', pg.K_1: 's6\n', pg.K_2: 's4\n', 
                            pg.K_3: 's15\n', pg.K_4: 's25\n', pg.K_5: 's48\n', pg.K_6: 's37\n', pg.K_7: 's52\n', pg.K_8: 's16\n'}