Python pygame 模块,K_DOWN 实例源码

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

项目:generals-bot    作者:harrischristiansen    | 项目源码 | 文件源码
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
项目:cs6244_motionplanning    作者:chenmin1107    | 项目源码 | 文件源码
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()
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
def handleEvent(self, event):
        if event.type == pg.KEYDOWN:

            if event.key == pg.K_UP:
                self.arrow.moveUp()
            if event.key == pg.K_DOWN:
                self.arrow.moveDown()

            if event.key == pg.K_RETURN:
                self.audio.state = "enter"
                if self.arrow.index == 0:
                    self.messageMenu("transition", "blank_menu")
                    self.messageCutScene("transition", "office_cutscene")
                if self.arrow.index == 1:
                    self.messageMenu("transition", "blank_menu")
                    self.messageScene("start_game", "coop")
                if self.arrow.index == 2:
                    self.messageMenu("transition", "options_menu")
                if self.arrow.index == 3:
                    quit()
项目:Tutoriales_juegos_Python    作者:tidus747    | 项目源码 | 文件源码
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')
项目:tensorflow_dqn_supermario    作者:JSDanielPark    | 项目源码 | 文件源码
def update_cursor(self, keys):
        """Update the position of the cursor"""
        input_list = [pg.K_RETURN, pg.K_a, pg.K_s]

        if self.cursor.state == c.PLAYER1:
            self.cursor.rect.y = 358
            if keys[pg.K_DOWN]:
                self.cursor.state = c.PLAYER2
            for input in input_list:
                if keys[input]:
                    self.reset_game_info()
                    self.done = True
        elif self.cursor.state == c.PLAYER2:
            self.cursor.rect.y = 403
            if keys[pg.K_UP]:
                self.cursor.state = c.PLAYER1
项目:third_person_im    作者:bstadie    | 项目源码 | 文件源码
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)
项目:LD39    作者:Bobsleigh    | 项目源码 | 文件源码
def notify(self, event):
        if self.isActivated:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    self.optionList[self.selector.selectedIndex].deselect()
                    self.selector.moveUp()
                    self.scrollUp()
                    self.optionList[self.selector.selectedIndex].select()
                elif event.key == pygame.K_DOWN:
                    self.optionList[self.selector.selectedIndex].deselect()
                    self.selector.moveDown()
                    self.scrollDown()
                    self.optionList[self.selector.selectedIndex].select()
                elif event.key == pygame.K_SPACE:
                    self.chosenOptionIndex = self.selectedIndex()
                    self.isActivated = False
                elif event.key == pygame.K_RETURN:
                    self.chosenOptionIndex = self.selectedIndex()
                    self.isActivated = False
项目:rllabplusplus    作者:shaneshixiang    | 项目源码 | 文件源码
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)
项目:freddie    作者:kunkkakada    | 项目源码 | 文件源码
def main():
    global DISPLAYSURF, font, menufont


    pygame.init()
    font = pygame.font.Font('etc/INVASION2000.ttf', 25)
    menufont = pygame.font.Font('etc/INVASION2000.ttf', 15)
    DISPLAYSURF = pygame.display.set_mode((WINDOWWIDTH, WINDOWHEIGHT))
    pygame.display.set_caption('Ski Jump Henri 1.0')

    while True: # main game loop
        #header = 

        for event in pygame.event.get():
            if event.type == QUIT:
                pygame.quit()
                sys.exit()
            #elif event.type == KEYDOWN and event.key == pygame.K_DOWN:



        for h in hills:
            player_jump(h)
项目:python-fsm    作者:axelhj    | 项目源码 | 文件源码
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]
项目:team-brisket-pyweek21    作者:AjaxVM    | 项目源码 | 文件源码
def handleEvents(self, events):
        for event in events:
            if event.type == pygame.QUIT:
                self.doQuit()
                return
            elif event.type == pygame.KEYDOWN:
                if event.key == pygame.K_ESCAPE:
                    self.doQuit()
                    return

                elif event.key == pygame.K_DOWN:
                    self.current_option += 1
                    if self.current_option >= len(self.options):
                        self.current_option = 0
                elif event.key == pygame.K_UP:
                    self.current_option -= 1
                    if self.current_option < 0:
                        self.current_option = len(self.options)-1
                elif event.key == pygame.K_RETURN:
                    self.currentOptionExecute()
                    return
项目:Heap-Project-1    作者:stacompsoc    | 项目源码 | 文件源码
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
项目:Arkon    作者:UnkDevE    | 项目源码 | 文件源码
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.
项目:uit-inf-1400-2017.github.io    作者:uit-inf-1400-2017    | 项目源码 | 文件源码
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
项目:gail-driver    作者:sisl    | 项目源码 | 文件源码
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)
项目:planet-hopper    作者:reddit-pygame    | 项目源码 | 文件源码
def get_event(self, event):
        if event.type == pg.QUIT:
            self.quit = True
        elif event.type == pg.KEYUP:
            if event.key == pg.K_ESCAPE:
                self.quit = True
            elif event.key == pg.K_SPACE:
                self.running_sim = not self.running_sim
            elif event.key == pg.K_UP:
                if self.tick_index < len(self.tick_lengths) - 1:
                    self.tick_index += 1
                    self.tick_length = self.tick_lengths[self.tick_index]
            elif event.key == pg.K_DOWN:
                if self.tick_index > 0:
                    self.tick_index -= 1
                    self.tick_length = self.tick_lengths[self.tick_index]
项目:c64-remakes    作者:DealPete    | 项目源码 | 文件源码
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()
项目:Kuai    作者:Duroktar    | 项目源码 | 文件源码
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
项目:pyimgui    作者:swistakm    | 项目源码 | 文件源码
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
项目:rllab    作者:rll    | 项目源码 | 文件源码
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)
项目:maml_rl    作者:cbfinn    | 项目源码 | 文件源码
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)
项目:cs6244_motionplanning    作者:chenmin1107    | 项目源码 | 文件源码
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()
项目:project_xcape    作者:OthmanEmpire    | 项目源码 | 文件源码
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")
项目:Physics-2.0    作者:rschwa6308    | 项目源码 | 文件源码
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]
项目:third_person_im    作者:bstadie    | 项目源码 | 文件源码
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
项目:sftext    作者:LukeMS    | 项目源码 | 文件源码
def on_key_press(self, event):
        if event.type == pygame.KEYDOWN and event.key == pygame.K_UP:
            self.scroll(50)
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_PAGEUP:
            self.scroll(500)
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_HOME:
            self.scroll('home')

        elif event.type == pygame.KEYDOWN and event.key == pygame.K_DOWN:
            self.scroll(-50)
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_PAGEDOWN:
            self.scroll(-500)
        elif event.type == pygame.KEYDOWN and event.key == pygame.K_END:
            self.scroll('end')
项目:LD39    作者:Bobsleigh    | 项目源码 | 文件源码
def notify(self, event):
        if self.isActivated:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    pass
                elif event.key == pygame.K_DOWN:
                    pass
                elif event.key == pygame.K_SPACE:
                    self.isActivated = False
                elif event.key == pygame.K_RETURN:
                    pass
项目:LD39    作者:Bobsleigh    | 项目源码 | 文件源码
def notify(self, event):
        if self.selected:
            if event.type == pygame.KEYDOWN:
                if event.key == pygame.K_UP:
                    self.optionList[self.selector.vPos].deselect()
                    self.selector.moveUp()
                    self.optionList[self.selector.vPos].select()
                elif event.key == pygame.K_DOWN:
                    self.optionList[self.selector.vPos].deselect()
                    self.selector.moveDown()
                    self.optionList[self.selector.vPos].select()
                elif event.key == pygame.K_SPACE:
                    self.optionList[self.selector.vPos].doOption()
                elif event.key == pygame.K_RETURN:
                    self.optionList[self.selector.vPos].doOption()
项目:ice-mud-game    作者:PyBargain    | 项目源码 | 文件源码
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
项目:neuroblast    作者:ActiveState    | 项目源码 | 文件源码
def update(self, screen, event_queue, dt,clock,joystick, netmodel, vizmodel):
        # Logos/titles
        screen.blit(self.logo,(screen.get_width() / 4 - 265,screen.get_height() * 3 / 4-500))
        screen.blit(self.intel,(screen.get_width() / 4 - 300,screen.get_height()-130))
        screen.blit(self.activestate,(screen.get_width() - 980,screen.get_height() - 130))

        nextState = self
        displaytext('Play', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4
                    - 80, WHITE, screen)
        displaytext('Train', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4
                    - 40, WHITE, screen)
        displaytext('Exit', 32, screen.get_width() / 4 - 20, screen.get_height() * 3 / 4,
                    WHITE, screen)
        displaytext(u'\u00bb', 32, screen.get_width() / 4 - 60, screen.get_height() * 3 / 4
                    - 40*self.menu_selection, WHITE, screen)

        # Each game state processes its own input queue in its own way to avoid messy input logic
        for event in event_queue:
            if event.type == pygame.KEYDOWN or event.type == pygame.JOYBUTTONDOWN:
                if (event.type == pygame.KEYDOWN and (event.key == pygame.K_DOWN)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 1)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value >= DEADZONE)):
                    self.menu_selection -= 1
                    if self.menu_selection == -1:
                        self.menu_selection = 2
                if (event.type == pygame.KEYDOWN and (event.key == pygame.K_UP)) or (event.type == pygame.JOYBUTTONDOWN and (event.button == 0)) or (event.type == pygame.JOYAXISMOTION and (event.axis == 1 or event.value <= -DEADZONE)):
                    self.menu_selection += 1
                    if self.menu_selection == 3:
                        self.menu_selection = 0
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_RETURN) or (event.type == pygame.JOYBUTTONDOWN and event.button == 11):
                    if self.menu_selection == 2:
                        nextState = Play(False)
                    elif self.menu_selection == 1:
                        nextState = Play(True)
                    else:
                        nextState = None
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_x):
                    self.ExportModel()
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_d):
                    self.DumpData()
                if (event.type == pygame.KEYDOWN and event.key == pygame.K_w):
                    self.DumpWeights()
        return nextState
项目:rllabplusplus    作者:shaneshixiang    | 项目源码 | 文件源码
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
项目:eduActiv8    作者:imiolek-ireneusz    | 项目源码 | 文件源码
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)
项目:pyDino    作者:lucaspbordignon    | 项目源码 | 文件源码
def run(self):
        # Setup
        for event in pygame.event.get():
            if (event.type == pygame.QUIT):
                return (False, '', None)
            if (event.type == pygame.KEYDOWN):
                if (event.key == pygame.K_UP and not self.dino.is_jumping()):
                    self.dino.set_movement(8)
                    self.dino.set_jumping(True)
                if (event.key == pygame.K_DOWN):
                    self.dino.set_movement(-5)
                if (event.key == pygame.K_h):
                    if self.dino.get_coins() > 4:
                        self.dino.set_coins(self.dino.get_coins() - 5)
                        self.powers.append(power(self.dino.get_position()))

        # Movement
        self.move_all_objects()

        # Enemies
        if (self.enemy.check_hitted(self.dino) and not self.enemy.get_hitted()):
            del self.enemy
            self.enemy = enemy(self.screen_size, self.ground_limit)
            self.dino.set_lives(1, type='decrement')
            if (not self.dino.get_lives()):
                return(True, 'game_over', None)

        # Prize
        self.check_prize_hitted()

        # Objects to show
        objects_to_show = {}
        objects_to_show['lives'] = self.dino.get_lives()
        objects_to_show['coins'] = self.dino.get_coins()
        objects_to_show['power'] = self.powers
        objects_to_show['char'] = self.dino
        objects_to_show['enemy'] = self.enemy
        objects_to_show['prize'] = self.prize
        self.clock.tick(self.difficulty * 60)
        return (True, 'match_running', objects_to_show)
项目:pytetris    作者:catalinc    | 项目源码 | 文件源码
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
项目:catcom    作者:Meepasaurus    | 项目源码 | 文件源码
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
项目:TicTacTio    作者:DevelopForLizardz    | 项目源码 | 文件源码
def setControls(self):
        """
        Setups the controls for the class. setGame must be called first in order for this to run correctly
        """

        self.controls = []
        self.values = [self.game.board.callable, self.game.board.mvCurUp, self.game.board.mvCurDown,
                       self.game.board.mvCurLeft, self.game.board.mvCurRight]
        if self.control_set == "arrows":
            self.keys = [pygame.K_RETURN, pygame.K_UP, pygame.K_DOWN, pygame.K_LEFT, pygame.K_RIGHT]
        else:
            self.keys = [pygame.K_SPACE, pygame.K_w, pygame.K_s, pygame.K_a, pygame.K_d]

        for i in range(len(self.keys)):
            self.controls.append([self.keys[i], self.values[i]])
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def __init__(self, main_menu):
        self.parent     = main_menu.parent
        self.main_menu  = main_menu
        self.settings   = self.parent.settings

        self.parent.event_handler.register_key_listener(self.handle_keypress)
        self.title = text_renderer.render_title("Options", colours.COLOUR_WHITE)

        self.title_position = (
            (self.parent.resolution[0] - self.title.get_width())// 2,
            15
        )

        self.directions = {
            pygame.K_UP        : [-1,  0],
            pygame.K_DOWN      : [ 1,  0],
            pygame.K_RIGHT     : [ 0,  1],
            pygame.K_LEFT      : [ 0, -1],
            pygame.K_SPACE     : [ 0,  2],
            pygame.K_RETURN    : [ 0,  2],
            pygame.K_ESCAPE    : [ 0,  3],
            pygame.K_BACKSPACE : [ 0,  3]
        }
        self.animation = None
        self.menu = SettingsMenu(self.settings)

        self.menu.register_finished_callback(self.finished)
项目:OfMagesAndMagic    作者:munnellg    | 项目源码 | 文件源码
def __init__(self, main_menu):
        self.parent     = main_menu.parent
        self.main_menu  = main_menu
        self.title_banner = main_menu.title_banner
        self.parent.event_handler.register_key_listener(self.handle_keypress)
        self.main_menu.menu.selected = 0
        self.animation = None

        self.directions = {
            pygame.K_UP   : -1,
            pygame.K_DOWN : 1
        }
项目:Pygames    作者:christat    | 项目源码 | 文件源码
def update(self, dt, game):
        key = pygame.key.get_pressed()
        if key[pygame.K_UP]:
            self.rect.y -= self.vel * dt
        if key[pygame.K_DOWN]:
            self.rect.y += self.vel * dt
        self.collider(game)


#AI Paddle, same as paddle but with pseudo AI for updating position
项目:nautical-combat    作者:horstjens    | 项目源码 | 文件源码
def run(self):
        """The mainloop
        """
        #self.paint() 
        running = True
        while running:
            for event in pygame.event.get():
                if event.type == pygame.QUIT:
                    running = False 
                elif event.type == pygame.KEYDOWN:
                    if event.key == pygame.K_ESCAPE:
                        running = False
                    if event.key==pygame.K_UP:
                        #print(m.active_itemnumber)
                        self.offset_y += 50
                        #self.sound2.play()
                    if event.key==pygame.K_DOWN:
                        self.offset_y -= 50
                    if event.key==pygame.K_LEFT:
                        self.x += self.dy
                    if event.key == pygame.K_RIGHT:
                        self.x -= self.dy
                    if event.key == pygame.K_PAGEUP:
                        self.offset_y += self.height
                    if event.key == pygame.K_PAGEDOWN:
                        self.offset_y -= self.height


            milliseconds = self.clock.tick(self.fps)
            seconds = milliseconds / 1000.0 # important for python2
            self.offset_y -= seconds * 10 # scroll 10 pixels / second
            if self.offset_y * -1 > self.text_height:
                running = False
            self.playtime += milliseconds / 1000.0
            self.paint()
            pygame.display.flip()
            self.screen.blit(self.background, (0, 0))

        #pygame.quit()
        return
项目:Snakis    作者:fbessou    | 项目源码 | 文件源码
def __init__(self):
        self._mapping = [
                { # Player 
                    pygame.K_d:"right",
                    pygame.K_s:"down",
                    pygame.K_q:"left",
                    pygame.K_z:"up"
                },
                { # Player 1
                    pygame.K_RIGHT:"right",
                    pygame.K_DOWN:"down",
                    pygame.K_LEFT:"left",
                    pygame.K_UP:"up"
                }
        ]
项目:tutorials    作者:krzyszti    | 项目源码 | 文件源码
def on_event(self, event):
        print(event)
        if event.type == pygame.QUIT:
            self._running = False
        if event.type == pygame.KEYDOWN:
            if event.key == pygame.K_ESCAPE:
                self._running = False
            if event.key == pygame.K_UP:
                self.y -= 5
            if event.key == pygame.K_DOWN:
                self.y += 5
            if event.key == pygame.K_RIGHT:
                self.x += 5
            if event.key == pygame.K_LEFT:
                self.x -= 5
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def Update(self):
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT] and self.Tile.Left != None:
            self.Tile = self.Tile.Left
        elif keys[pygame.K_RIGHT] and self.Tile.Right != None:
            self.Tile = self.Tile.Right

        if keys[pygame.K_UP] and self.Tile.Up != None:
            self.Tile = self.Tile.Up
        elif keys[pygame.K_DOWN] and self.Tile.Down != None:
            self.Tile = self.Tile.Down
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def Update(self):
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT] and self.Tile.Left != None:
            self.Tile = self.Tile.Left
        elif keys[pygame.K_RIGHT] and self.Tile.Right != None:
            self.Tile = self.Tile.Right

        if keys[pygame.K_UP] and self.Tile.Up != None:
            self.Tile = self.Tile.Up
        elif keys[pygame.K_DOWN] and self.Tile.Down != None:
            self.Tile = self.Tile.Down
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def Update(self):
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT] and self.Tile.Left != None:
            self.Tile = self.Tile.Left
        elif keys[pygame.K_RIGHT] and self.Tile.Right != None:
            self.Tile = self.Tile.Right

        if keys[pygame.K_UP] and self.Tile.Up != None:
            self.Tile = self.Tile.Up
        elif keys[pygame.K_DOWN] and self.Tile.Down != None:
            self.Tile = self.Tile.Down
项目:Boardgame    作者:RensMo    | 项目源码 | 文件源码
def Update(self):
        keys = pygame.key.get_pressed()

        if keys[pygame.K_LEFT] and self.Tile.Left != None:
            self.Tile = self.Tile.Left
        elif keys[pygame.K_RIGHT] and self.Tile.Right != None:
            self.Tile = self.Tile.Right

        if keys[pygame.K_UP] and self.Tile.Up != None:
            self.Tile = self.Tile.Up
        elif keys[pygame.K_DOWN] and self.Tile.Down != None:
            self.Tile = self.Tile.Down
项目:CoolesSpiel    作者:AlinaGri    | 项目源码 | 文件源码
def update(self, *args):
        """
        Handles the selection

        parameters: tuple arguments for the update (first argument should be an instance pygame.event.Event)
        return values: -
        """
        if len(args) > 0 and self.isActive():
            event = args[0]
            if event.type == pygame.KEYDOWN and self.isFocused():
                if event.key == pygame.K_UP:
                    self.moveCursor(-1)
                elif event.key == pygame.K_DOWN:
                    self.moveCursor(1)
                elif event.key == pygame.K_BACKSPACE or event.key == pygame.K_DELETE:
                    if self.isEditable():
                        if self._selection == self._cursor:
                            self.delete(self._selection - 1, CURSOR)
                            self.moveCursor(-1)
                        else:
                            self.delete(SELECTION, CURSOR)
                            self.setCursor(self._selection)
            elif event.type == pygame.MOUSEBUTTONUP:
                if self.rect.collidepoint(event.pos):
                    self.setSelection(CURSOR, self._posToIndex(event.pos[1] - self.rect.y))
            elif event.type == pygame.MOUSEBUTTONDOWN:
                if self.rect.collidepoint(event.pos):
                    self.setCursor(self._posToIndex(event.pos[1] - self.rect.y))

        super(Listbox, self).update(*args)
项目:Arkon    作者:UnkDevE    | 项目源码 | 文件源码
def run(self):
        # while no other GUI elements are visible or not in battle
        while this.drawing & (not (this.text_box_visible | this.text_menu_visible | this.inbattle)):
            pygame.event.pump()

            event = pygame.event.poll()

            if event.type == pygame.KEYDOWN:
                # get keys pressed using pygame.key.get_pressed() as it is more continous than events.
                if event.key == pygame.K_LCTRL:
                    # seperate hide and show buttons as they would counteract eachother.
                    self.player_menu.show()
                elif event.key == pygame.K_z:
                    self.activate()
                elif event.key == pygame.K_f:
                    # quick testing key to find if the battles work has to be with a background
                    #  where Lucidia Bright is present.
                    battle(self, this.onscreen_sprites["Lucida Bright"])

            pygame.time.delay(5)

            keys = pygame.key.get_pressed()

            if keys[pygame.K_UP]:
                self.facing("backward")
                self.move(0, -1)
            elif keys[pygame.K_DOWN]:
                self.facing("forward")
                self.move(0, 1)
            elif keys[pygame.K_LEFT]:
                self.facing("left")
                self.move(-1, 0)
            elif keys[pygame.K_RIGHT]:
                self.facing("right")
                self.move(1, 0)
项目:labyrinth-explorer    作者:ryukinix    | 项目源码 | 文件源码
def game():
    setup()
    running = True
    start = time()
    while running:

        clock.tick(60)

        for e in pygame.event.get():
            if e.type == pygame.QUIT:
                running = False
            if e.type == pygame.KEYDOWN and e.key == pygame.K_ESCAPE:
                running = False

        # Move the player if an arrow key is pressed
        key = pygame.key.get_pressed()
        if key[pygame.K_LEFT]:
            player.move(-2, 0)
        if key[pygame.K_RIGHT]:
            player.move(2, 0)
        if key[pygame.K_UP]:
            player.move(0, -2)
        if key[pygame.K_DOWN]:
            player.move(0, 2)

        # Just added this to make it slightly fun ;)
        if player.rect.colliderect(end_rect):
            raise SystemExit("You win! @{:2f}s".format(time() - start))
        if computer.rect.colliderect(end_rect):
            raise SystemExit("You lost! The computer wins")
        # Draw the scene
        screen.fill(BLACK)
        computer.run()
        for wall in walls:
            pygame.draw.rect(screen, WHITE, wall.rect)
        pygame.draw.rect(screen, RED, end_rect)
        pygame.draw.rect(screen, GREEN, player.rect)
        pygame.draw.rect(screen, YELLOW, computer.rect)
        draw_counter(time() - start)
        pygame.display.flip()
项目:gail-driver    作者:sisl    | 项目源码 | 文件源码
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