當前位置: 首頁>>代碼示例>>Python>>正文


Python key.D屬性代碼示例

本文整理匯總了Python中pyglet.window.key.D屬性的典型用法代碼示例。如果您正苦於以下問題:Python key.D屬性的具體用法?Python key.D怎麽用?Python key.D使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在pyglet.window.key的用法示例。


在下文中一共展示了key.D屬性的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: on_key_press

# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import D [as 別名]
def on_key_press(symbol, modifiers):
    """
    This handler processes keyboard commands that
    control the simulation
    """

    if symbol == key.BACKSPACE or symbol == key.SLASH:
        print('RESET')
        env.reset()
        env.render('pyglet', view=view_mode)
        return

    if symbol == key.ESCAPE:
        env.close()
        sys.exit(0)

    if symbol == key.UP:
        step(env.actions.move_forward)
    elif symbol == key.DOWN:
        step(env.actions.move_back)

    elif symbol == key.LEFT:
        step(env.actions.turn_left)
    elif symbol == key.RIGHT:
        step(env.actions.turn_right)

    elif symbol == key.PAGEUP or symbol == key.P:
        step(env.actions.pickup)
    elif symbol == key.PAGEDOWN or symbol == key.D:
        step(env.actions.drop)

    elif symbol == key.ENTER:
        step(env.actions.done) 
開發者ID:maximecb,項目名稱:gym-miniworld,代碼行數:35,代碼來源:manual_control.py

示例2: __init__

# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import D [as 別名]
def __init__(self, character=characters.Bomber, agent_control='arrows'):
        super(PlayerAgent, self).__init__(character)

        ##
        # @NOTE: DO NOT move this import outside the constructor. It will
        # not work in headless environments like a Docker container
        # and prevents Pommerman from running.
        #
        from pyglet.window import key
        controls = {
            'arrows': {
                key.UP: 1,
                key.DOWN: 2,
                key.LEFT: 3,
                key.RIGHT: 4,
                key.SPACE: 5,
                key.M: 6  # In Pommerman, this will freeze the game.
            },
            'wasd': {
                key.W: 1,
                key.S: 2,
                key.A: 3,
                key.D: 4,
                key.E: 5,
                key.Q: 6  # In Pommerman, this will freeze the game.
            }
        }

        assert agent_control in controls, "Unknown control: {}".format(
            agent_control)
        self._key2act = controls[agent_control]

        self._action_q = []
        self._keystate = {} 
開發者ID:MultiAgentLearning,項目名稱:playground,代碼行數:36,代碼來源:player_agent.py

示例3: update

# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import D [as 別名]
def update(self, dt):
        # Fall into water if there's too much under our feet
        if self.water_tiles >= 4:
            self.falling += FALL_RATE * dt

        # If we're on full land, climb back up
        if self.water_tiles == 0 and self.falling > 0:
            self.falling -= FALL_RATE * 2 * dt

        if self.falling:
            self.falling += FALL_RATE * dt
            self.update_size()

        if self.falling > FALL_MAX:
            self.game_over(fell=True)

        self.water_tiles = 0

        self.previous_coordinates = (self.x, self.y)

        if keys[key.W]:
            self.y += dt * self.speed
        if keys[key.S]:
            self.y -= dt * self.speed
        if keys[key.A]:
            self.x -= dt * self.speed
        if keys[key.D]:
            self.x += dt * self.speed

        if self.firing:
            self.fire() 
開發者ID:python-discord,項目名稱:code-jam-5,代碼行數:33,代碼來源:player.py

示例4: on_key_release

# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import D [as 別名]
def on_key_release(self, symbol, modifiers):
        """Event handler for the Window.on_key_release event.

        Called when the player releases a key. See pyglet docs for key
        mappings.

        Parameters
        ----------
        symbol : int
            Number representing the key that was pressed.
        modifiers : int
            Number representing any modifying keys that were pressed.

        """
        if symbol == key.W:
            self.strafe[0] += 1
        elif symbol == key.S:
            self.strafe[0] -= 1
        elif symbol == key.A:
            self.strafe[1] += 1
        elif symbol == key.D:
            self.strafe[1] -= 1
        elif symbol == key.SPACE:
            self.dy = 0
        elif symbol == key.LCTRL:
            self.running = False
        elif symbol == key.LSHIFT:
            self.dy = 0
        elif symbol == key.P:
            breakpoint() 
開發者ID:XenonLab-Studio,項目名稱:TerraCraft,代碼行數:32,代碼來源:scenes.py

示例5: on_key_press

# 需要導入模塊: from pyglet.window import key [as 別名]
# 或者: from pyglet.window.key import D [as 別名]
def on_key_press(self, symbol, modifiers):
        """Event handler for the Window.on_key_press event.

        Called when the player presses a key. See pyglet docs for key
        mappings.

        Parameters
        ----------
        symbol : int
            Number representing the key that was pressed.
        modifiers : int
            Number representing any modifying keys that were pressed.

        """
        if symbol == key.W:
            self.strafe[0] -= 1
        elif symbol == key.S:
            self.strafe[0] += 1
        elif symbol == key.A:
            self.strafe[1] -= 1
        elif symbol == key.D:
            self.strafe[1] += 1
        elif symbol == key.SPACE:
            if self.flying:
                # Reduces vertical flying speed
                # 0.1 positive value that allows vertical flight up.
                self.dy = 0.1 * JUMP_SPEED
            elif self.dy == 0:
                self.dy = JUMP_SPEED
                self.audio.play(self.jump_sfx)
        elif symbol == key.LCTRL:
            self.running = True
        elif symbol == key.LSHIFT:
            if self.flying:
                # Reduces vertical flying speed
                # -0.1 negative value that allows vertical flight down.
                self.dy = -0.1 * JUMP_SPEED
            elif self.dy == 0:
                self.dy = JUMP_SPEED
        elif symbol == key.ESCAPE:
            self.set_exclusive_mouse(False)
            return pyglet.event.EVENT_HANDLED
        elif symbol == key.TAB:
            self.flying = not self.flying
        elif symbol == key.F1:
            self.scene_manager.change_scene("HelpScene")
        elif symbol == key.F2:
            self.toggleGui = not self.toggleGui
        elif symbol == key.F3:
            self.toggleLabel = not self.toggleLabel
        elif symbol == key.F5:
            self.scene_manager.save.save_world(self.model)
        elif symbol == key.F12:
            pyglet.image.get_buffer_manager().get_color_buffer().save('screenshot.png')
        elif symbol in self.num_keys:
            index = (symbol - self.num_keys[0]) % len(self.inventory)
            self.block = self.inventory[index]
        elif symbol == key.ENTER:
            self.scene_manager.change_scene('MenuScene') 
開發者ID:XenonLab-Studio,項目名稱:TerraCraft,代碼行數:61,代碼來源:scenes.py


注:本文中的pyglet.window.key.D屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。