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

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

项目: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"))