本文整理匯總了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)
示例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)
示例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
示例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