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

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

项目: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
项目:jackit    作者:vix597    | 项目源码 | 文件源码
def __init__(self):
        super(JackitConfigControls, self).__init__()
        self.up = pygame.K_w
        self.down = pygame.K_s
        self.left = pygame.K_a
        self.right = pygame.K_d
        self.jump = pygame.K_SPACE
        self.interact = pygame.K_e
        self.push = pygame.K_LSHIFT
        self.reset_code = pygame.K_q
        self.toggle_sound = pygame.K_m
        self.kill_self = pygame.K_k
        self.reset_game = pygame.K_n
项目: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"))
项目:pygame-event-calendar-and-pianobar    作者:scottpcrawford    | 项目源码 | 文件源码
def get_event(self, event):
        if event.type == pg.QUIT:
            self.done = True
        elif event.type == self.CHANGESTATE:
            self.change_state()
        elif event.type == self.UPDATECALENDAR:
            self.update_calendar()
        elif event.type == self.UPDATEQUOTE:
            self.update_quote()
        elif event.type == self.UPDATEWEATHER:
            self.update_weather()
        elif event.type == self.NIGHTRADIO:
            if self.RESTING and self.RADIO_RUNNING:
                process_input('s41\n')
                pg.time.set_timer(self.NIGHTRADIO,0)
                print('Station Changed to Relaxation Radio, disabling timer')
        elif event.type == pg.KEYDOWN:
            if event.key == pg.K_ESCAPE:
                if self.RADIO_RUNNING:
                    process_input('q')
                print('You pressed ESC... Quitting')
                self.done = True
                return
            if not self.RADIO_RUNNING:
                if event.key == pg.K_m and pg.key.get_mods() & pg.KMOD_CTRL:
                    print('Attempting to start the music')
                    self.RADIO_RUNNING = True
                    start_pianobar(sys.platform)
            else:
                if event.key in self.keymap_dict:
                    if event.key == pg.K_q:
                        self.RADIO_RUNNING = False
                        process_input('q')
                    elif event.key == pg.K_r:
                        print('choosing a random radio station')
                        sl = readfile(self.cwd+'/scripts/stationlist')
                        random_station = 's'+str(random.randint(0,(len(sl)-1)))+'\n'
                        process_input(random_station)
                    else:
                        process_input(self.keymap_dict[event.key])
                elif event.key == pg.K_9 and pg.key.get_mods() & pg.KMOD_SHIFT:
                    process_input('(')
                elif event.key == pg.K_0 and pg.key.get_mods() & pg.KMOD_SHIFT:
                    process_input(')')