我们从Python开源项目中,提取了以下50个代码示例,用于说明如何使用pygame.K_RIGHT。
def _handleKeypress(self, key): if self._clicked == None or self._moveEvent == None: return False column = self._clicked[0] row = self._clicked[1] target = None if key == pygame.K_LEFT: if column > 0: target = (column-1, row) elif key == pygame.K_RIGHT: if column < self._map.cols - 1: target = (column+1, row) elif key == pygame.K_UP: if row > 0: target = (column, row-1) elif key == pygame.K_DOWN: if row < self._map.rows - 1: target = (column, row+1) if target != None: self._moveEvent(self._clicked, target) self._clicked = target
def check_keyup_events(settings, event, screen, tile_map): player = tile_map.player if event.key == pygame.K_SPACE: if not player.idle_top: if player.falling == False: player.dy = settings.player_jump_velocity player.falling = True elif player.air_jumps < player.max_air_jumps: player.dy = settings.player_air_jump_velocity player.air_jumps += 1 if event.key == pygame.K_LEFT: if not player.idle_top: if player.dx != 0.0: player.dx = 0.0 if event.key == pygame.K_RIGHT: if not player.idle_top: if player.dx != 0.0: player.dx = 0.0
def keyboard_loop(self): while not rospy.is_shutdown(): acc = 0 yaw = 0 keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type==pygame.QUIT: sys.exit() if(keys[pygame.K_UP]): acc = self.acc elif(keys[pygame.K_DOWN]): acc = -self.acc if(keys[pygame.K_LEFT]): yaw = self.yaw elif(keys[pygame.K_RIGHT]): yaw = -self.yaw self.send_control(acc, yaw) self.rate.sleep()
def handle_event(self, event): if event.type == pygame.QUIT: game_over = True if event.type == pygame.KEYDOWN: if event.key == pygame.K_LEFT: self.update('left') if event.key == pygame.K_RIGHT: self.update('right') if event.key == pygame.K_UP: self.update('up') if event.key == pygame.K_DOWN: self.update('down') if event.type == pygame.KEYUP: if event.key == pygame.K_LEFT: self.update('stand_left') if event.key == pygame.K_RIGHT: self.update('stand_right') if event.key == pygame.K_UP: self.update('stand_up') if event.key == pygame.K_DOWN: self.update('stand_down')
def CheckKeys(self): """ Check the keys that are evaluated on every main loop iteration. I.e., they aren't just evaluated when first pressed down """ pygame.event.pump() self.keys = keys = pygame.key.get_pressed() if keys[pygame.K_LEFT]: self.viewCenter -= (0.5, 0) elif keys[pygame.K_RIGHT]: self.viewCenter += (0.5, 0) if keys[pygame.K_UP]: self.viewCenter += (0, 0.5) elif keys[pygame.K_DOWN]: self.viewCenter -= (0, 0.5) if keys[pygame.K_HOME]: self.viewZoom = 1.0 self.viewCenter = (0.0, 20.0)
def update(self): if self.hidden and pygame.time.get_ticks() - self.hide_timer > 1000: self.hidden = False self.rect.centerx = WIDTH / 2 self.rect.bottom = HEIGHT - 10 self.speedx = 0 #speed=8 keystate = pygame.key.get_pressed() if keystate[pygame.K_LEFT]: self.speedx = -speed if keystate[pygame.K_RIGHT]: self.speedx = speed self.rect.x += self.speedx if self.rect.right > WIDTH: self.rect.right = WIDTH if self.rect.left < 0: self.rect.left = 0
def manager(field): put_tile = False 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 (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d): field.change_right_move(True) elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_RIGHT or event.dict["key"] == pygame.K_d): field.change_right_move(False) elif event.type == pygame.KEYDOWN and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q): field.change_left_move(True) elif event.type == pygame.KEYUP and (event.dict["key"] == pygame.K_LEFT or event.dict["key"] == pygame.K_q): field.change_left_move(False) elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 4: field.change_tile(1) elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 5: field.change_tile(-1) elif event.type == pygame.MOUSEBUTTONDOWN and event.dict["button"] == 1: field.put_tile()
def __init__(self, gameInstance): BaseController.__init__(self, gameInstance) keys = ( \ pygame.K_LEFT, #left pygame.K_RIGHT,#right pygame.K_UP, #acc pygame.K_DOWN, #brake pygame.K_LCTRL,#reverse pygame.K_r, #restart #pygame.K_ESC, #endGame pygame.K_RCTRL, #pygame.K_SPACE, \ ) self.keyToAction = dict() for key, action in zip(keys, self.gameInterface.gameInstance.actionsList): self.keyToAction.update({key: action}) self.keyToAction[pygame.K_RCTRL] = self.keyToAction[pygame.K_LCTRL]
def touch_handler(self, event): #handle keypresses... if event.type == pygame.KEYDOWN: if event.key == pygame.K_BACKSPACE: self.panel.text.del_letter() elif event.key == pygame.K_RETURN or event.key == pygame.K_KP_ENTER: self.panel.new_line() elif event.key == pygame.K_ESCAPE: self.close(None) elif event.key == pygame.K_LEFT: self.panel.text.cursor_left() elif event.key == pygame.K_RIGHT: self.panel.text.cursor_right() elif len(event.unicode) > 0: self.panel.text.add_letter(event.unicode) super(Keyboard,self).touch_handler(event)
def check_events(ship): """???? 126 ????ship ??ship""" #??elif event.type == pygame.KEYDOWN: #???? ???? ????? ?? for event in pygame.event.get(): if event.type == pygame.QUIT: #event.type == pygame.QUIT: ????????? sys.exit() '''???? ?? 1262?? ???????? ????? elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: ship.rect.centerx += 1 ''' elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: ship.moving_right = True elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: ship.moving_right = False
def check_events(ship): """???? 126 ????ship ??ship""" #??elif event.type == pygame.KEYDOWN: #???? ???? ????? ?? for event in pygame.event.get(): if event.type == pygame.QUIT: #event.type == pygame.QUIT: ????????? sys.exit() '''???? ?? 1262?? ???????? ????? elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: ship.rect.centerx += 1 ''' #??down ???? ?????????? ??? ??? ?? ? ????? ? ? ???? elif event.type == pygame.KEYDOWN: if event.key == pygame.K_RIGHT: ship.moving_right = True if event.key == pygame.K_LEFT: ship.moving_left = True elif event.type == pygame.KEYUP: if event.key == pygame.K_RIGHT: ship.moving_right = False if event.key == pygame.K_LEFT: ship.moving_left = False
def handle_event(self, event): if event.type == pygame.KEYDOWN: if event.key == pygame.K_ESCAPE: self.root.trigger_exit_to_main() elif event.key == pygame.K_p: self.toggle_pause() elif not self.paused: if event.key == pygame.K_SPACE: self.skip_turn = True elif event.key == pygame.K_RETURN: self.skip_game = True elif event.key in [pygame.K_LEFT, pygame.K_1]: self.parent.battle.award_victory(1) self.skip_game = True elif event.key in [pygame.K_RIGHT, pygame.K_2]: self.parent.battle.award_victory(2) self.skip_game = True
def keyboard(self, key): """ Handle keyboard events. :key: key pressed """ global SCALE_FACTOR, MIN_MASS if key == pygame.K_SPACE: self.pause = not self.pause elif key == pygame.K_UP: self.pos_shift[1] -= int(self.height / 10) elif key == pygame.K_DOWN: self.pos_shift[1] += int(self.height / 10) elif key == pygame.K_LEFT: self.pos_shift[0] -= int(self.width / 10) elif key == pygame.K_RIGHT: self.pos_shift[0] += int(self.width / 10) elif key == pygame.K_EQUALS: SCALE_FACTOR /= 1.05 elif key == pygame.K_MINUS: SCALE_FACTOR *= 1.05 MIN_MASS = SCALE_FACTOR ** 3
def handle_events(): for event in pygame.event.get(): if event.type == pygame.QUIT: pygame.quit() sys.exit(0) if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: player_one.speed = 10 if event.key == pygame.K_RIGHT: player_one.angular_speed = 5 if event.key == pygame.K_LEFT: player_one.angular_speed = -5 if event.type == pygame.KEYUP: if event.key == pygame.K_UP: player_one.speed = 0 if event.key == pygame.K_RIGHT: player_one.angular_speed = 0 if event.key == pygame.K_LEFT: player_one.angular_speed = 0
def run(self): while self.visible & this.drawing: # wait for event event = pygame.event.wait() if event.type == pygame.KEYDOWN: if event.key == pygame.K_DOWN: self.select_previous() elif event.key == pygame.K_LEFT: self.select_previous() elif event.key == pygame.K_RETURN: self.activate() elif event.key == pygame.K_z: self.activate() elif event.key == pygame.K_x: self.previous_menu() elif event.key == pygame.K_RIGHT: self.select_next() # runs self, as well as show.
def handle_events(self): for event in pygame.event.get(): if event.type == pygame.QUIT: exit() elif event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: self.up_pressed = True elif event.key == pygame.K_DOWN: self.down_pressed = True elif event.key == pygame.K_LEFT: self.left_pressed = True elif event.key == pygame.K_RIGHT: self.right_pressed = True elif event.key == pygame.K_ESCAPE: exit() elif event.type == pygame.KEYUP: if event.key == pygame.K_UP: self.up_pressed = False elif event.key == pygame.K_DOWN: self.down_pressed = False elif event.key == pygame.K_LEFT: self.left_pressed = False elif event.key == pygame.K_RIGHT: self.right_pressed = False
def get_input(): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if state.state == "playing": if event.key == pygame.K_LEFT: if valid(state.X - 1, state.Y, state.piece.forms[state.form]): state.X -= 1 if event.key == pygame.K_RIGHT: if valid(state.X + 1, state.Y, state.piece.forms[state.form]): state.X += 1 if event.key == pygame.K_SPACE: new_form = state.form - 1 if new_form < 0: new_form = 3 if valid(state.X, state.Y, state.piece.forms[new_form]): state.form = new_form if event.key == pygame.K_DOWN: state.state = "falling" if state.state == "lost": if event.key in [pygame.K_SPACE, pygame.K_RETURN]: state.start_game()
def run(self): while not self.is_done: time.sleep(0.01) x, y = pygame.mouse.get_pos() events = pygame.event.get() for event in events: if event.type == pygame.KEYDOWN: if event.key == pygame.K_UP: Kuai.emit('key-up', x, y) if event.key == pygame.K_DOWN: Kuai.emit('key-down', x, y) if event.key == pygame.K_LEFT: Kuai.emit('key-left', x, y) if event.key == pygame.K_RIGHT: Kuai.emit('key-right', x, y) if event.key == pygame.K_ESCAPE: Kuai.emit('key-escape') pass
def _map_keys(self): key_map = self.io.key_map key_map[imgui.KEY_TAB] = pygame.K_TAB key_map[imgui.KEY_LEFT_ARROW] = pygame.K_LEFT key_map[imgui.KEY_RIGHT_ARROW] = pygame.K_RIGHT key_map[imgui.KEY_UP_ARROW] = pygame.K_UP key_map[imgui.KEY_DOWN_ARROW] = pygame.K_DOWN key_map[imgui.KEY_PAGE_UP] = pygame.K_PAGEUP key_map[imgui.KEY_PAGE_DOWN] = pygame.K_PAGEDOWN key_map[imgui.KEY_HOME] = pygame.K_HOME key_map[imgui.KEY_END] = pygame.K_END key_map[imgui.KEY_DELETE] = pygame.K_DELETE key_map[imgui.KEY_BACKSPACE] = pygame.K_BACKSPACE key_map[imgui.KEY_ENTER] = pygame.K_RETURN key_map[imgui.KEY_ESCAPE] = pygame.K_ESCAPE key_map[imgui.KEY_A] = pygame.K_a key_map[imgui.KEY_C] = pygame.K_c key_map[imgui.KEY_V] = pygame.K_v key_map[imgui.KEY_X] = pygame.K_x key_map[imgui.KEY_Y] = pygame.K_y key_map[imgui.KEY_Z] = pygame.K_z
def check_keydown_events(event, ai_settings, screen, stats, sb, ship, aliens, bullets): """????""" if event.key == pygame.K_RIGHT: ship.moving_right = True if event.key == pygame.K_LEFT: ship.moving_left = True elif event.key == pygame.K_SPACE: fire_bullet(ai_settings, screen, ship, bullets) elif event.key == pygame.K_q: stats.save_high_score() sys.exit() elif event.key == pygame.K_p and not stats.game_active: start_game(ai_settings, screen, stats, sb, ship, aliens, bullets)
def check_keyup_events(event, ship): """????""" if event.key == pygame.K_RIGHT: ship.moving_right = False if event.key == pygame.K_LEFT: ship.moving_left = False
def check_keydown_events(settings, event, screen, tile_map): """Respond to key down events""" player = tile_map.player if event.key == pygame.K_ESCAPE: sys.exit() if event.key == pygame.K_a: generate_new_random_blob(settings, screen, settings.image_res.enemy_blob_images, tile_map) if event.key == pygame.K_r: reset_game(tile_map) if event.key == pygame.K_LEFT: if not player.idle_top: if player.dx == 0.0: player.dx = -1 * settings.player_dx player.facing_left = True if event.key == pygame.K_RIGHT: if not player.idle_top: if player.dx == 0.0: player.dx = settings.player_dx player.facing_left = False if event.key == pygame.K_F9: if settings.fullscreen == True: settings.fullscreen = False pygame.display.set_mode((800, 600)) else: settings.fullscreen = True pygame.display.set_mode((800, 600), pygame.FULLSCREEN)
def keyboard_loop(self): while not rospy.is_shutdown(): acc = 0 yaw = 0 keys = pygame.key.get_pressed() for event in pygame.event.get(): if event.type==pygame.QUIT:sys.exit() if(keys[pygame.K_s]): self.send_highway_start(1) if(keys[pygame.K_t]): self.send_highway_start(2) if(keys[pygame.K_UP]): acc = self.acc elif(keys[pygame.K_DOWN]): acc = -self.acc if(keys[pygame.K_LEFT]): yaw = self.yaw elif(keys[pygame.K_RIGHT]): yaw = -self.yaw if(keys[pygame.K_r]): state = 1 self.send_record_state(state) elif(keys[pygame.K_q]): state = 2 self.send_record_state(state) elif(keys[pygame.K_p]): state = 0 self.send_record_state(state) self.send_control(acc, yaw) self.rate.sleep()
def handleEvent(self, event): if event.type == pg.KEYDOWN: if event.key == pg.K_ESCAPE: self.effect.timeStartDarken = self.effect.time self.effect.timeEndDarken = self.effect.time + self.dt self.audio.state = "exit" if event.key == pg.K_UP: self.arrow.moveUp() if event.key == pg.K_DOWN: self.arrow.moveDown() if self.arrow.index == 0: if event.key == pg.K_RIGHT: self.backgroundSetting.next() if event.key == pg.K_LEFT: self.backgroundSetting.previous() if event.key == pg.K_RETURN: if self.backgroundSetting.index == 0: self.render.flip(True, False) if self.backgroundSetting.index == 1: self.render.flip(False, True) if self.arrow.index == 1: if event.key == pg.K_RIGHT: self.fullscreenSetting.next() if event.key == pg.K_LEFT: self.fullscreenSetting.previous() if event.key == pg.K_RETURN: if self.fullscreenSetting.index == 0: pg.display.set_mode((settings.WIDTH, settings.HEIGHT)) if self.fullscreenSetting.index == 1: pg.display.set_mode((settings.WIDTH, settings.HEIGHT), pg.FULLSCREEN) self.messageMenu("screen") self.messageScene("screen") self.messageCutScene("screen")
def check_keydown_events(event, ai_settings, screen, ship, bullets): if event.key == pygame.K_RIGHT: ship.moving_right = True elif event.key == pygame.K_LEFT: ship.moving_left = True elif event.key == pygame.K_SPACE: fire_bullet(ai_settings, screen, ship, bullets) elif event.key == pygame.K_ESCAPE: sys.exit()
def check_keyup_events(event, ship): if event.key == pygame.K_RIGHT: ship.moving_right = False elif event.key == pygame.K_LEFT: ship.moving_left = False
def __init__(self, dims): self.position, self.velocity, self.dims, self.scale, self.map = V2(0, 0), V2(0, 0), dims, 1, [pg.K_RIGHT, pg.K_LEFT, pg.K_UP, pg.K_DOWN]
def action_from_keys(self, keys): if keys[pygame.K_LEFT]: return np.asarray([-10]) elif keys[pygame.K_RIGHT]: return np.asarray([+10]) else: return np.asarray([0])
def action_from_keys(self, keys): if keys[pygame.K_LEFT]: return np.asarray([-1]) elif keys[pygame.K_RIGHT]: return np.asarray([+1]) else: return np.asarray([0])
def action_from_keys(self, keys): go = np.zeros(self.action_dim) if keys[pygame.K_LEFT]: go[-1] = self.max_deg if keys[pygame.K_RIGHT]: go[-1] = -self.max_deg if keys[pygame.K_UP]: go[0] = 10 if keys[pygame.K_DOWN]: go[0] = -10 return go
def update(self, is_key_pressed, time, display): """ ????????????????????????????? is_key_pressed ?????????????ascii???????????? time ???? display ????????Display?? """ if (is_key_pressed(pygame.K_e)): if self.theme_changed: display.theme_index = (display.theme_index + 1) % len(self.themes) display.theme = self.themes[display.theme_index] self.theme_changed = False elif not self.theme_changed: self.theme_changed = True flag = False if (is_key_pressed(pygame.K_UP)): self._up(display, time) flag = True if (is_key_pressed(pygame.K_DOWN)): self._down(display, time) flag = True if (is_key_pressed(pygame.K_LEFT)): self._left(display, time) flag = True if (is_key_pressed(pygame.K_RIGHT)): self._right(display, time) flag = True if self.counter >= 3: self.counter = 0 return flag else: self.counter += 1 return False
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and (event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT): self.next_step() elif event.type == pygame.MOUSEBUTTONUP: if self.board.active_ship == self.next_step_btn.unit_id: if self.cursor_pos == self.sumn1n2sl + 1: self.level.next_board_load() else: self.next_step()
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and (event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT): self.next_step() elif event.type == pygame.MOUSEBUTTONUP: if self.board.active_ship == self.next_step_btn.unit_id: if self.current_pos + 1 > self.all_a_count: self.level.next_board_load() else: self.next_step()
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN and (event.key == pygame.K_RIGHT or event.key == pygame.K_LEFT): self.next_step() elif event.type == pygame.MOUSEBUTTONUP: if self.board.active_ship == self.next_step_btn.unit_id: if self.current_pos + 1 > self.all_a_count: # if self.cursor_pos == self.sumn1n2sl+1: self.level.next_board_load() else: self.next_step()
def handle(self, event): gd.BoardGame.handle(self, event) # send event handling up if self.show_msg == False: if event.type == pygame.KEYDOWN or event.type == pygame.MOUSEBUTTONDOWN: self.auto_check_reset() if event.type == pygame.KEYDOWN and event.key == pygame.K_LEFT: self.home_sqare_switch(self.board.active_ship + 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_RIGHT: self.home_sqare_switch(self.board.active_ship - 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_UP: self.home_sqare_switch(self.board.active_ship - self.sumn1n2sl + 1) elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN: self.home_sqare_switch(self.board.active_ship + self.sumn1n2sl) elif event.type == pygame.KEYDOWN and event.key != pygame.K_RETURN and not self.correct: lhv = len(self.home_square.value) self.changed_since_check = True if event.key == pygame.K_BACKSPACE: if lhv > 0: self.home_square.value = self.home_square.value[0:lhv - 1] else: char = event.unicode if (len(char) > 0 and lhv < 2 and char in self.digits): self.home_square.value = char if self.auto_select: self.home_sqare_switch(self.board.active_ship + 1) else: self.home_square.value = "" self.home_square.update_me = True self.mainloop.redraw_needed[0] = True elif event.type == pygame.MOUSEBUTTONUP: self.home_sqare_switch(self.board.active_ship)
def init_rotary_encoders(self): """ Rotary encoders (RE) initializer. This is executed only if RE enabled in config.txt. Two REs are configured this way: 1. Volume Control: GPIO16 - Volume Up, GPIO26 - Volume Down, GPIO13 - Mute 2. Tuning: GPIO12 - Move Right, GPIO6 - Move Left, GPIO5 - Select RE events will be wrapped into keyboard events with the following assignment: Volume Up - '+' key on numeric keypad, Volume Down - '-' key on keypad, Mute - 'x' key """ if not self.config[USAGE][USE_ROTARY_ENCODERS]: return from event.rotary import RotaryEncoder RotaryEncoder(16, 26, 13, pygame.K_KP_PLUS, pygame.K_KP_MINUS, pygame.K_x) RotaryEncoder(12, 6, 5, pygame.K_RIGHT, pygame.K_LEFT, pygame.K_RETURN)
def button_event(self, button): if button == 1: return pygame.K_LEFT elif button == 3: return pygame.K_RIGHT elif button == 2: return pygame.K_UP elif button == 0: return pygame.K_DOWN
def process_input(self): for event in pygame.event.get(): if event.type == pygame.QUIT: sys.exit() if event.type == pygame.KEYDOWN: if self.state.paused: if event.key == pygame.K_r: self.state.paused = False if self.state.game_over: if event.key == pygame.K_r: self.state = State(self.ROWS, self.COLS) if event.key == pygame.K_ESCAPE: sys.exit() if self.state.running: if event.key == pygame.K_DOWN: self.state.move_piece(board.DIRECTION_DOWN) if event.key == pygame.K_LEFT: self.state.move_piece(board.DIRECTION_LEFT) if event.key == pygame.K_RIGHT: self.state.move_piece(board.DIRECTION_RIGHT) if event.key == pygame.K_x: self.state.rotate_piece() if event.key == pygame.K_z: self.state.rotate_piece(True) if event.key == pygame.K_SPACE: self.state.drop_piece() if event.key == pygame.K_p: self.state.paused = True
def move(self, eventKey): #print eventKey if eventKey == pygame.K_LEFT: self.x -= 35 self.col -= 1 elif eventKey == pygame.K_RIGHT: self.x += 35 self.col += 1 elif eventKey == pygame.K_DOWN: self.y += 20
def check_keydown_events(event, ai_settings, screen,ship,bullets): """Respond to keypresses.""" if event.key == pygame.K_RIGHT: ship.moving_right = True elif event.key == pygame.K_LEFT: ship.moving_left = True elif event.key == pygame.K_SPACE: fire_bullet(ai_settings, screen,ship,bullets) elif event.key == pygame.K_q: sys.exit()
def check_keyup_events(event, ship): """Respond to key releases.""" if event.key == pygame.K_RIGHT: ship.moving_right = False elif event.key == pygame.K_LEFT: ship.moving_left = False