当前位置: 首页>>代码示例>>Python>>正文


Python pygame.JOYHATMOTION属性代码示例

本文整理汇总了Python中pygame.JOYHATMOTION属性的典型用法代码示例。如果您正苦于以下问题:Python pygame.JOYHATMOTION属性的具体用法?Python pygame.JOYHATMOTION怎么用?Python pygame.JOYHATMOTION使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在pygame的用法示例。


在下文中一共展示了pygame.JOYHATMOTION属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: event_wait

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import JOYHATMOTION [as 别名]
def event_wait(self):
        while True:
            for event in pygame.event.get():
                if self.m_bUnload: break
                if event.type == pygame.KEYDOWN:
                    input = self.get_key(event.key)
                    if input: return input
                elif event.type == pygame.JOYBUTTONDOWN:
                    input = self.get_button(event.joy, event.button)
                    if input: return input
                elif event.type == pygame.JOYHATMOTION:
                    input = self.get_hat(event.value)
                    if input: return input
                elif event.type == pygame.JOYAXISMOTION:
                    input = self.get_axis(event.joy, event.axis, event.value)
                    if input: return input
            self.m_oClock.tick(20)
            pygame.time.wait(0) 
开发者ID:krahsdevil,项目名称:Retropie-CRT-Edition,代码行数:20,代码来源:core_controls.py

示例2: check_hat

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import JOYHATMOTION [as 别名]
def check_hat(self, pg_event):
        if pg_event.type == pg.JOYHATMOTION:
            x, y = pg_event.value
            if x == -1:
                self.press(actions.LEFT, value=x * -1)
            elif x == 0:
                self.release(actions.LEFT)
                self.release(actions.RIGHT)
            elif x == 1:
                self.press(actions.RIGHT)

            if y == -1:
                self.press(actions.DOWN, value=y * -1)
            elif y == 0:
                self.release(actions.DOWN)
                self.release(actions.UP)
            elif y == 1:
                self.press(actions.UP) 
开发者ID:pygame,项目名称:stuntcat,代码行数:20,代码来源:event_handling.py

示例3: joy_key

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import JOYHATMOTION [as 别名]
def joy_key(key, inlist=True, testmode=True):
        """
        Create a pygame joy controller key event.

        :param key: Key to press
        :type key: bool
        :param inlist: Return event in a list
        :type inlist: bool
        :param testmode: Key event is in test mode
        :type testmode: bool
        :return: Event
        :rtype: :py:class:`pygame.event.Event`
        """
        event_obj = pygame.event.Event(pygame.JOYHATMOTION,
                                       {'value': key,
                                        'test': testmode
                                        })
        if inlist:
            event_obj = [event_obj]
        return event_obj 
开发者ID:ppizarror,项目名称:pygame-menu,代码行数:22,代码来源:_utils.py

示例4: update

# 需要导入模块: import pygame [as 别名]
# 或者: from pygame import JOYHATMOTION [as 别名]
def update(self, events):
        updated = False
        for event in events:  # type: pygame.event.Event

            if event.type == pygame.KEYDOWN:  # Check key is valid
                if not check_key_pressed_valid(event):
                    continue

            # Events
            keydown = event.type == pygame.KEYDOWN
            joy_hatmotion = self.joystick_enabled and event.type == pygame.JOYHATMOTION
            joy_axismotion = self.joystick_enabled and event.type == pygame.JOYAXISMOTION
            joy_button_down = self.joystick_enabled and event.type == pygame.JOYBUTTONDOWN

            if keydown and event.key == _controls.KEY_LEFT or \
                    joy_hatmotion and event.value == _controls.JOY_LEFT or \
                    joy_axismotion and event.axis == _controls.JOY_AXIS_X and event.value < _controls.JOY_DEADZONE:
                self.sound.play_key_add()
                self.left()
                updated = True

            elif keydown and event.key == _controls.KEY_RIGHT or \
                    joy_hatmotion and event.value == _controls.JOY_RIGHT or \
                    joy_axismotion and event.axis == _controls.JOY_AXIS_X and event.value > -_controls.JOY_DEADZONE:
                self.sound.play_key_add()
                self.right()
                updated = True

            elif keydown and event.key == _controls.KEY_APPLY or \
                    joy_button_down and event.button == _controls.JOY_BUTTON_SELECT:
                self.sound.play_open_menu()
                self.apply(*self._elements[self._index][1:])
                updated = True

            elif self.mouse_enabled and event.type == pygame.MOUSEBUTTONUP:
                if self._rect.collidepoint(*event.pos):
                    # Check if mouse collides left or right as percentage, use only X coordinate
                    mousex, _ = event.pos
                    topleft, _ = self._rect.topleft
                    topright, _ = self._rect.topright
                    dist = mousex - (topleft + self._title_size)  # Distance from label
                    if dist > 0:  # User clicked the options, not label

                        # Position in percentage, if <0.5 user clicked left
                        pos = dist / float(topright - topleft - self._title_size)
                        if pos <= 0.5:
                            self.left()
                        else:
                            self.right()
                        updated = True

        return updated 
开发者ID:ppizarror,项目名称:pygame-menu,代码行数:54,代码来源:selector.py


注:本文中的pygame.JOYHATMOTION属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。