How to use the melee.enums.Button.BUTTON_MAIN function in melee

To help you get started, we’ve selected a few melee examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github altf4 / libmelee / melee / controller.py View on Github external
def tilt_analog(self, button, x, y):
        if not self.pipe:
            return
        command = "SET " + str(button.value) + " " + str(x) + " " + str(y) + "\n"
        if button == enums.Button.BUTTON_MAIN:
            self.current.main_stick = (x, y)
        else:
            self.current.c_stick = (x, y)
        if self.logger:
            self.logger.log("Buttons Pressed", command, concat=True)
        self.pipe.write(command)
github altf4 / libmelee / melee / controller.py View on Github external
def simple_press(self, x, y, button):
        if not self.pipe:
            return
        #Tilt the main stick
        self.tilt_analog(enums.Button.BUTTON_MAIN, x, y)
        #Release the shoulders
        self.press_shoulder(enums.Button.BUTTON_L, 0)
        self.press_shoulder(enums.Button.BUTTON_R, 0)
        #Press the right button
        for item in enums.Button:
            #Don't do anything for the main or c-stick
            if item == enums.Button.BUTTON_MAIN:
                continue
            if item == enums.Button.BUTTON_C:
                continue
            #Press our button, release all others
            if item == button:
                self.press_button(item)
            else:
                self.release_button(item)
github altf4 / libmelee / melee / menuhelper.py View on Github external
larger_magnitude = max(diff_x, diff_y)

        # Scale down values to between 0 and 1
        x = diff_x / larger_magnitude
        y = diff_y / larger_magnitude

        # Now scale down to be between .5 and 1
        if ai_state.cursor_x < target_x:
            x = (x/2) + 0.5
        else:
            x = 0.5 - (x/2)
        if ai_state.cursor_y < target_y:
            y = (y/2) + 0.5
        else:
            y = 0.5 - (y/2)
        controller.tilt_analog(enums.Button.BUTTON_MAIN, x, y)
        return

    #We want to get to a state where the cursor is NOT over the character,
    # but it's selected. Thus ensuring the token is on the character
    isOverCharacter = abs(ai_state.cursor_x - target_x) < wiggleroom and \
        abs(ai_state.cursor_y - target_y) < wiggleroom

    #Don't hold down on B, since we'll quit the menu if we do
    if controller.prev.button[enums.Button.BUTTON_B] == True:
        controller.release_button(enums.Button.BUTTON_B)
        return

    #If character is selected, and we're in of the area, and coin is down, then we're good
    if (ai_state.character == character) and ai_state.coin_down:
        if start and gamestate.ready_to_start and \
            controller.prev.button[enums.Button.BUTTON_START] == False:
github altf4 / libmelee / melee / menuhelper.py View on Github external
#Move up if we're too low
    if ai_state.cursor_y < target_y - wiggleroom:
        controller.tilt_analog(enums.Button.BUTTON_MAIN, .5, 1)
        return
    #Move downn if we're too high
    if ai_state.cursor_y > target_y + wiggleroom:
        controller.tilt_analog(enums.Button.BUTTON_MAIN, .5, 0)
        return
    #Move right if we're too left
    if ai_state.cursor_x < target_x - wiggleroom:
        controller.tilt_analog(enums.Button.BUTTON_MAIN, 1, .5)
        return
    #Move left if we're too right
    if ai_state.cursor_x > target_x + wiggleroom:
        controller.tilt_analog(enums.Button.BUTTON_MAIN, 0, .5)
        return

    #If we get in the right area, press A until we're in the right state
    controller.tilt_analog(enums.Button.BUTTON_MAIN, .5, .5)
    if controller.prev.button[enums.Button.BUTTON_A] == False:
        controller.press_button(enums.Button.BUTTON_A)
    else:
        controller.release_button(enums.Button.BUTTON_A)
github altf4 / libmelee / melee / techskill.py View on Github external
def multishine(ai_state, controller):
    #If standing, shine
    if ai_state.action == enums.Action.STANDING:
        controller.press_button(enums.Button.BUTTON_B)
        controller.tilt_analog(enums.Button.BUTTON_MAIN, .5, 0)
        return

    #Shine on frame 3 of knee bend, else nothing
    if ai_state.action == enums.Action.KNEE_BEND:
        if ai_state.action_frame == 3:
            controller.press_button(enums.Button.BUTTON_B)
            controller.tilt_analog(enums.Button.BUTTON_MAIN, .5, 0)
            return
        else:
            controller.empty_input()
            return

    isInShineStart = (ai_state.action == enums.Action.DOWN_B_STUN or
            ai_state.action == enums.Action.DOWN_B_GROUND_START)

    #Jump out of shine
    if isInShineStart and ai_state.action_frame >= 4 and ai_state.on_ground:
        controller.press_button(enums.Button.BUTTON_Y)
        return

    if ai_state.action == enums.Action.DOWN_B_GROUND:
        controller.press_button(enums.Button.BUTTON_Y)
        return