Пример #1
0
    def joystick_buttons(self):

        if joystick.get_button(1):  # X on PS4 controller
            self.active = True
            if self.color not in color_list:
                self.color = color_list[self.color_value]

            if 1 not in self.buttons_pressed:
                self.buttons_pressed.append(1)
        else:
            self.active = False
            if self.color in color_list:
                dark_color = []
                for value in self.color:
                    if value - 20 < 0:
                        dark_color.append(0)
                    else:
                        dark_color.append(value - 20)
                self.color = tuple(dark_color)

        if joystick.get_button(2):  # O on PS4 controller
            self.erase_mode = True

        if joystick.get_button(
                0
        ) and 0 not in self.buttons_pressed:  # Square on PS4 controller
            if len(drawings) > 1:
                drawings.pop(-1)
                self.buttons_pressed.append(0)

        if joystick.get_button(5):  # R1 on PS4 controller
            closest_rect_size = sum(self.size) / len(self.size)
            self.size = (closest_rect_size, closest_rect_size)

        if joystick.get_button(
                4) and 4 not in self.buttons_pressed:  # L1 on PS4 Controller
            self.equal_scale = True
            self.buttons_pressed.append(4)

        for i in range(6, 8):

            if joystick.get_button(i) and i not in self.buttons_pressed:
                self.speed *= 2
                self.buttons_pressed.append(i)

        if joystick.get_button(8):  # Share on PS4 controller
            global prompt
            prompt_pos = (win_size[0] / 2, win_size[1] / 3)
            prompt_size = (160, 90)
            button_yes = Prompt.Button((prompt_pos[0] - prompt_size[0] * 0.1,
                                        prompt_pos[1] + prompt_size[1] * 0.8),
                                       (32, 18), "Yes")
            input_field = Prompt.InputField(
                (prompt_pos[0] - prompt_size[0] * 0.4,
                 prompt_pos[1] - prompt_size[1] * 0), "Drawing.png")
            prompt = (Prompt.Prompt(prompt_pos, prompt_size,
                                    "Would you like to save?", (button_yes, ),
                                    input_field))

            self.freeze = True

        hat = joystick.get_hat(0)
        if abs(hat[0]) and not self.hats_pressed:
            self.color_value += hat[0]
            self.update_color()
        elif abs(hat[1]) and not self.hats_pressed:
            global win_color
            win_color += hat[1]
            update_win_color()
            self.ghost.color = color_list[win_color]
        if abs(hat[0]) or abs(hat[1]):
            self.hats_pressed = True
        else:
            self.hats_pressed = False

        for button in self.buttons_pressed:
            if not joystick.get_button(button):
                self.buttons_pressed.remove(button)
                if button in (6, 7):
                    self.speed /= 2
                if button == 4:
                    self.equal_scale = False

                if button == 1:
                    drawings.append(win.copy())