def wait_for_keypress( lst=[ K_RETURN, K_SPACE, K_ESCAPE, M_BUTTON1, W_A, W_B, J_BUTTON9, J_BUTTON10 ]): """Wait for a keyboard keypress, joystick button press, Wiimote button, or mouse button. """ while True: if len(_wii) > 0: for w in _wii: w.tick() for e in lst: if e >= W_A and e <= W_MAXBUTTON and w.get_button(e - W_A): return for evt in pygame.event.get(): if evt.type == QUIT: engine_util.exit() if evt.type == KEYDOWN: if evt.key == K_q and ((evt.mod & KMOD_META > 0) or (evt.mod & KMOD_CTRL > 0)): engine_util.exit() for e in lst: if evt.key == e: return if evt.type == JOYBUTTONDOWN: for e in lst: if evt.button == e - J_BUTTON1: return if evt.type == MOUSEBUTTONDOWN: for e in lst: if evt.button == e - M_BUTTON1: return
def wait_for_keypress(lst=[K_RETURN, K_SPACE, K_ESCAPE, M_BUTTON1, W_A, W_B, J_BUTTON9, J_BUTTON10]): """Wait for a keyboard keypress, joystick button press, Wiimote button, or mouse button. """ while True: if len(_wii) > 0: for w in _wii: w.tick() for e in lst: if e >= W_A and e <= W_MAXBUTTON and w.get_button(e - W_A): return for evt in pygame.event.get(): if evt.type == QUIT: engine_util.exit() if evt.type == KEYDOWN: if evt.key == K_q and ((evt.mod & KMOD_META > 0) or (evt.mod & KMOD_CTRL > 0)): engine_util.exit() for e in lst: if evt.key == e: return if evt.type == JOYBUTTONDOWN: for e in lst: if evt.button == e - J_BUTTON1: return if evt.type == MOUSEBUTTONDOWN: for e in lst: if evt.button == e - M_BUTTON1: return
def handle_events(): """Handle pygame events according to previously set event handlers.""" # First do time events global _event_list t = time() for (tm, func) in _event_list[:]: if tm < t: func() _event_list.remove((tm, func)) for i in _event_handlers: if i[2] and i[3]: i[1]() # Now do Wiimote events if len(_wii) > 0: for wi in range(len(_wii)): w = _wii[wi] w.tick() # Wiimote buttons for e in _event_handlers: event, func, should_repeat, is_repeat, device = e if event >= W_A and event <= W_MAXBUTTON and device == wi: if should_repeat: e[3] = w.get_button(event - W_START) else: if is_repeat: e[3] = w.get_button(event - W_START) else: if w.get_button(event - W_START): func() e[3] = True # Wiimote triggers acc = w.get_acc() l = vlen(acc) if l > 0.8 and l < 1.2: w.orientation = [0.5 * w.orientation[i] + 0.5 * acc[i] for i in range(3)] w.orientation = vnorm(w.orientation) else: if 0 * acc[0] - acc[2] > W_SENSITIVITY and w.triggered[0]: w.triggered[0] = False if 0 * acc[0] - acc[2] < W_SENSITIVITY - 0.5 and not w.triggered[0] and time() > w.when_triggered[0] + W_MAX_CLOSENESS: w.triggered[0] = True w.when_triggered[0] = time() for (event, func, shld_rep, repeating, device) in _event_handlers: if event == W_SHAKE and device == wi: func() acc = w.get_nunchuk_acc() l = vlen(acc) if l > 0.8 and l < 1.2: w.norientation = [0.5 * w.norientation[i] + 0.5 * acc[i] for i in range(3)] w.norientation = vnorm(w.norientation) else: sens = 0.8 if 0 * acc[0] - acc[2] > W_SENSITIVITY and w.triggered[1]: w.triggered[1] = False if 0 * acc[0] - acc[2] < W_SENSITIVITY - 0.5 and not w.triggered[1] and time() > w.when_triggered[1] + W_MAX_CLOSENESS: w.triggered[1] = True w.when_triggered[1] = time() for (event, func, shld_rep, repeating, device) in _event_handlers: if event == W_NUNCHUK_SHAKE and device == wi: func() # Now do pygame events (keyboard and joystick) for evt in pygame.event.get(): if evt.type == QUIT: engine_util.exit() if evt.type == KEYDOWN: if evt.key == K_q and ((evt.mod & KMOD_META > 0) or (evt.mod & KMOD_CTRL > 0)): engine_util.exit() for e in _event_handlers: event, func, should_repeat, is_repeat, device = e if evt.type == KEYUP and event == evt.key: e[3] = False if evt.type == JOYBUTTONUP and event == evt.button + J_START and device == evt.joy: e[3] = False if evt.type == MOUSEBUTTONUP and event == evt.button - 1 + M_START: e[3] = False if evt.type == KEYDOWN and event == evt.key: if should_repeat: e[3] = True else: func() if evt.type == JOYBUTTONDOWN and event == evt.button + J_START and device == evt.joy: if should_repeat: e[3] = True else: func() if evt.type == MOUSEBUTTONDOWN and event == evt.button - 1 + M_START: if should_repeat: e[3] = True else: func()
def handle_events(): """Handle pygame events according to previously set event handlers.""" # First do time events global _event_list t = time() for (tm, func) in _event_list[:]: if tm < t: func() _event_list.remove((tm, func)) for i in _event_handlers: if i[2] and i[3]: i[1]() # Now do Wiimote events if len(_wii) > 0: for wi in range(len(_wii)): w = _wii[wi] w.tick() # Wiimote buttons for e in _event_handlers: event, func, should_repeat, is_repeat, device = e if event >= W_A and event <= W_MAXBUTTON and device == wi: if should_repeat: e[3] = w.get_button(event - W_START) else: if is_repeat: e[3] = w.get_button(event - W_START) else: if w.get_button(event - W_START): func() e[3] = True # Wiimote triggers acc = w.get_acc() l = vlen(acc) if l > 0.8 and l < 1.2: w.orientation = [ 0.5 * w.orientation[i] + 0.5 * acc[i] for i in range(3) ] w.orientation = vnorm(w.orientation) else: if 0 * acc[0] - acc[2] > W_SENSITIVITY and w.triggered[0]: w.triggered[0] = False if 0 * acc[0] - acc[ 2] < W_SENSITIVITY - 0.5 and not w.triggered[ 0] and time( ) > w.when_triggered[0] + W_MAX_CLOSENESS: w.triggered[0] = True w.when_triggered[0] = time() for (event, func, shld_rep, repeating, device) in _event_handlers: if event == W_SHAKE and device == wi: func() acc = w.get_nunchuk_acc() l = vlen(acc) if l > 0.8 and l < 1.2: w.norientation = [ 0.5 * w.norientation[i] + 0.5 * acc[i] for i in range(3) ] w.norientation = vnorm(w.norientation) else: sens = 0.8 if 0 * acc[0] - acc[2] > W_SENSITIVITY and w.triggered[1]: w.triggered[1] = False if 0 * acc[0] - acc[ 2] < W_SENSITIVITY - 0.5 and not w.triggered[ 1] and time( ) > w.when_triggered[1] + W_MAX_CLOSENESS: w.triggered[1] = True w.when_triggered[1] = time() for (event, func, shld_rep, repeating, device) in _event_handlers: if event == W_NUNCHUK_SHAKE and device == wi: func() # Now do pygame events (keyboard and joystick) for evt in pygame.event.get(): if evt.type == QUIT: engine_util.exit() if evt.type == KEYDOWN: if evt.key == K_q and ((evt.mod & KMOD_META > 0) or (evt.mod & KMOD_CTRL > 0)): engine_util.exit() for e in _event_handlers: event, func, should_repeat, is_repeat, device = e if evt.type == KEYUP and event == evt.key: e[3] = False if evt.type == JOYBUTTONUP and event == evt.button + J_START and device == evt.joy: e[3] = False if evt.type == MOUSEBUTTONUP and event == evt.button - 1 + M_START: e[3] = False if evt.type == KEYDOWN and event == evt.key: if should_repeat: e[3] = True else: func() if evt.type == JOYBUTTONDOWN and event == evt.button + J_START and device == evt.joy: if should_repeat: e[3] = True else: func() if evt.type == MOUSEBUTTONDOWN and event == evt.button - 1 + M_START: if should_repeat: e[3] = True else: func()