Exemplo n.º 1
0
    def on_joybutton_press(self, joystick, button):
        vector = self.player.get_sight_vector()
        block, previous = self.world.hit_test(self.player.position, vector)
        if button == 0:
            player_x, player_y, player_z = normalize(self.player.position)
            if previous and previous != (player_x, player_y, player_z) and \
                    previous != (player_x, player_y - 1, player_z):
                # make sure the block isn't in the players head or feet
                if self.player.current_item:
                    self.world.add_block(previous, get_block(self.player.get_block()))

        elif button == 1:
            self.player.jump()

        elif button == 2 and block:
            texture = self.world.objects[block]
            if texture.hit_and_destroy():
                self.world.remove_block(block)

        elif button == 3:
            self.player.fly()

        elif button == 4:
            self.player.previous_inventory_item()

        elif button == 5:
            self.player.next_inventory_item()

        print('Button %s pressed' % button)
Exemplo n.º 2
0
    def on_mouse_press(self, x, y, button, modifiers):
        """Called when a mouse button is pressed. See pyglet docs for button
        amd modifier mappings.

        Parameters
        ----------
        x, y : int
            The coordinates of the mouse click. Always center of the screen if
            the mouse is captured.
        button : int
            Number representing mouse button that was clicked. 1 = left button,
            4 = right button.
        modifiers : int
            Number representing any modifying keys that were pressed when the
            mouse button was clicked.
        """
        if self.exclusive:
            vector = self.player.get_sight_vector()
            block, previous = self.world.hit_test(self.player.position, vector)
            if (button == mouse.RIGHT) or \
                    ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
                # ON OSX, control + left click = right click.
                if previous and self.player.block:
                    self.world.add_block(previous,
                                         get_block(self.player.block))
                    self.player.adjust_inventory(self.player.block)
            elif button == pyglet.window.mouse.LEFT and block:
                texture = self.world.objects[block]
                if texture.breakable:
                    self.world.remove_block(block)
        else:
            self.set_exclusive_mouse(True)
Exemplo n.º 3
0
    def on_mouse_press(self, x, y, button, modifiers):
        """Called when a mouse button is pressed. See pyglet docs for button
        amd modifier mappings.

        Parameters
        ----------
        x, y : int
            The coordinates of the mouse click. Always center of the screen if
            the mouse is captured.
        button : int
            Number representing mouse button that was clicked. 1 = left button,
            4 = right button.
        modifiers : int
            Number representing any modifying keys that were pressed when the
            mouse button was clicked.
        """
        if self.exclusive:
            vector = self.player.get_sight_vector()
            block, previous = self.world.hit_test(self.player.position, vector)
            if (button == mouse.RIGHT) or \
                    ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
                # ON OSX, control + left click = right click.
                if previous and self.player.block:
                    self.world.add_block(previous, get_block(self.player.block))
                    self.player.adjust_inventory(self.player.block)
            elif button == pyglet.window.mouse.LEFT and block:
                texture = self.world.objects[block]
                if texture.breakable:
                    self.world.remove_block(block)
        else:
            self.set_exclusive_mouse(True)
Exemplo n.º 4
0
    def on_mouse_press(self, x, y, button, modifiers):
        if (button == mouse.RIGHT) or \
                ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
            block, previous = self.player.hit(self.world.area.blocks, left=False)
            # ON OSX, control + left click = right click.
            if block and self.player.current_item:
                self.world.add_block(previous, get_block(self.player.get_block()))

        elif button == mouse.LEFT:
            block = self.player.hit(self.world.area.blocks)[0]
            if block:
                texture = self.world.area.get_block(block)
                if texture.hit_and_destroy():
                    self.world.remove_block(block)
Exemplo n.º 5
0
    def on_mouse_press(self, x, y, button, modifiers):
        if (button == mouse.RIGHT) or \
                ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
            block, previous = self.player.hit(self.world.area.blocks,
                                              left=False)
            # ON OSX, control + left click = right click.
            if block and self.player.current_item:
                self.world.add_block(previous,
                                     get_block(self.player.get_block()))

        elif button == mouse.LEFT:
            block = self.player.hit(self.world.area.blocks)[0]
            if block:
                texture = self.world.area.get_block(block)
                if texture.hit_and_destroy():
                    self.world.remove_block(block)
Exemplo n.º 6
0
    def on_mouse_press(self, x, y, button, modifiers):
        vector = self.player.get_sight_vector()
        block, previous = self.world.hit_test(self.player.position, vector)
        if (button == mouse.RIGHT) or \
                ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
            # ON OSX, control + left click = right click.
            player_x, player_y, player_z = normalize(self.player.position)
            if previous and previous != (player_x, player_y, player_z) and \
                    previous != (player_x, player_y - 1, player_z):
                # make sure the block isn't in the players head or feet
                if self.player.current_item:
                    self.world.add_block(previous, get_block(self.player.get_block()))

        elif button == pyglet.window.mouse.LEFT and block:
            texture = self.world.objects[block]
            if texture.hit_and_destroy():
                self.world.remove_block(block)
Exemplo n.º 7
0
    def on_mouse_press(self, x, y, button, modifiers):
        vector = self.player.get_sight_vector()
        block, previous = self.world.hit_test(self.player.position, vector)
        if (button == mouse.RIGHT) or \
                ((button == mouse.LEFT) and (modifiers & key.MOD_CTRL)):
            # ON OSX, control + left click = right click.
            player_x, player_y, player_z = normalize(self.player.position)
            if previous and self.player.block and \
                previous != (player_x, player_y, player_z) and \
                    previous != (player_x, player_y - 1, player_z):
                # make sure the block isn't in the players head or feet
                self.world.add_block(previous, get_block(self.player.block))
                self.player.adjust_inventory(self.player.block)

        elif button == pyglet.window.mouse.LEFT and block:
            texture = self.world.objects[block]
            if texture.hit_and_destroy():
                self.world.remove_block(block)