Python pyglet.window.key.A Examples

The following are 13 code examples of pyglet.window.key.A(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module pyglet.window.key , or try the search function .
Example #1
Source File: events.py    From learning-python with MIT License 5 votes vote down vote up
def on_key_press(symbol, modifiers):
    print("key %s was pressed" % symbol)
    if symbol == key.A:
        print('The "A" key was pressed.')
    elif symbol == key.LEFT:
        print('The left arrow key was pressed.')
    elif symbol == key.ENTER:
        print('The enter key was pressed.') 
Example #2
Source File: events.py    From flappy-bird-py with GNU General Public License v2.0 5 votes vote down vote up
def on_key_press(symbol, modifiers):
    if symbol == key.A:
        print 'The "A" key was pressed.'
    elif symbol == key.LEFT:
        print 'The left arrow key was pressed.'
    elif symbol == key.ENTER:
        print 'The enter key was pressed.' 
Example #3
Source File: events.py    From flappy-bird-py with GNU General Public License v2.0 5 votes vote down vote up
def on_key_press(symbol, modifiers):
    if symbol == key.A:
        print 'The "A" key was pressed.'
    elif symbol == key.LEFT:
        print 'The left arrow key was pressed.'
    elif symbol == key.ENTER:
        print 'The enter key was pressed.' 
Example #4
Source File: events.py    From pyglet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def on_key_press(symbol, modifiers):
    if symbol == key.A:
        print('The "A" key was pressed.')
    elif symbol == key.LEFT:
        print('The left arrow key was pressed.')
    elif symbol == key.ENTER:
        print('The enter key was pressed.') 
Example #5
Source File: renderfield.py    From pyglet with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def on_key_press(symbol, modifiers):
    global enable_shader
    global enable_bidirectional
    global enable_antialias
    global enable_outline
    global enable_glow
    global outline_width
    global glow_width
    if symbol == key.S:
        enable_shader = not enable_shader
    elif symbol == key.B:
        enable_bidirectional = not enable_bidirectional
    elif symbol == key.A:
        enable_antialias = not enable_antialias
    elif symbol == key.O:
        enable_outline = not enable_outline
        enable_glow = False
    elif symbol == key.G:
        enable_glow = not enable_glow
        enable_outline = False
    elif symbol == key.PERIOD:
        if enable_glow:
            glow_width += 0.005
        else:
            outline_width += 0.005
    elif symbol == key.COMMA:
        if enable_glow:
            glow_width -= 0.005
        else:
            outline_width -= 0.005

    print('-' * 78)
    print('enable_shader', enable_shader)
    print('enable_bidirectional', enable_bidirectional)
    print('enable_antialias', enable_antialias)
    print('enable_outline', enable_outline)
    print('enable_glow', enable_glow)
    print('outline_width', outline_width) 
Example #6
Source File: player_agent.py    From playground with Apache License 2.0 5 votes vote down vote up
def should_fire(self):
        if self.last_repeat_time is None:
            # The first repetition:
            if time() - self.keydown_time > REPEAT_DELAY:
                return True
        else:
            # A repetition after the first:
            if time() - self.last_repeat_time > REPEAT_INTERVAL:
                return True

        # No repetition yet
        return False 
Example #7
Source File: player_agent.py    From playground with Apache License 2.0 5 votes vote down vote up
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 = {} 
Example #8
Source File: player.py    From code-jam-5 with MIT License 5 votes vote down vote up
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() 
Example #9
Source File: scenes.py    From TerraCraft with GNU General Public License v3.0 5 votes vote down vote up
def play(self, source, position=(0, 0, 0)):
        """Play a sound effect on the next available channel

        :param source: A pyglet audio Source
        :param position: Optional spacial position for the sound.
        """
        player = self.sfx_players[0]
        player.position = position
        player.queue(source=source)
        if not player.playing:
            player.play()
        else:
            player.next_source()
        self.sfx_players.rotate() 
Example #10
Source File: scenes.py    From TerraCraft with GNU General Public License v3.0 5 votes vote down vote up
def play_music(self, source):
        """Play a music track, or switch to a new one.

        :param source: A pyglet audio Source
        """
        self.music_player.queue(source=source)
        if not self.music_player.playing:
            self.music_player.play()
        else:
            self.music_player.next_source() 
Example #11
Source File: scenes.py    From TerraCraft with GNU General Public License v3.0 5 votes vote down vote up
def update_shown_sectors(self, position, rotation):
        """Update shown sectors according to the actual frustum.

        A sector is a contiguous x, y sub-region of world. Sectors are
        used to speed up world rendering.
        """
        sector = sectorize(position)
        if self.sector == sector:
            # The following computation is based on the actual sector
            # So if there is no changes on the sector, it have to display
            # The exact same thing
            return

        sectors_to_show = []
        pad = int(FOG_END) // SECTOR_SIZE
        for dx in range(-pad, pad + 1):
            for dy in range(-pad, pad + 1):
                for dz in range(-pad, pad + 1):
                    # Manathan distance
                    dist = abs(dx) + abs(dy) + abs(dz)
                    if dist > pad + pad // 2:
                        # Skip sectors outside of the sphere of radius pad+1
                        continue
                    x, y, z = sector
                    sectors_to_show.append((dist, x + dx, y + dy, z + dz))

        # Sort by distance to the player in order to
        # displayed closest sectors first
        sectors_to_show = sorted(sectors_to_show)
        sectors_to_show = [s[1:] for s in sectors_to_show]
        self.model.show_only_sectors(sectors_to_show) 
Example #12
Source File: scenes.py    From TerraCraft with GNU General Public License v3.0 5 votes vote down vote up
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() 
Example #13
Source File: scenes.py    From TerraCraft with GNU General Public License v3.0 4 votes vote down vote up
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')