def move_stick(self, state, pad, target_x, target_y): # print("-----P2 Inputs-----") # print("X: ", state.players[1].cursor_x, " Y: ", state.players[1].cursor_y) dx = target_x - state.players[0].cursor_x dy = target_y - state.players[0].cursor_y mag = math.sqrt(dx * dx + dy * dy) # print(mag) if mag >= 1.3: # x = [dx, 0] # y = [0, dy] # direction_vector = [dx, dy] # x_component = dx * ((sum([x[i] * direction_vector[i] for i in range(len(x))])) / (dx*mag)) # y_component = dy * ((sum([y[i] * direction_vector[i] for i in range(len(y))])) / (dy*mag)) # x_contrib = x_component / mag # y_contrib = y_component / mag # print("X: ", '{:.2f}'.format(x_component), " Y: ", '{:.2f}'.format(y_component)) # print("X_contrib: ", '{:.2f}'.format(x_contrib), " Y_contrib: ", '{:.2f}'.format(y_contrib)) # print(mag) # print("-----") pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5) # pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * x_contrib + 0.5, 0.5 * y_contrib + 0.5) # print("-----dx, dy-----") # print("dx: ", dx, " dy: ", dy) # print("-----Tilt-----") # print("X: ", 0.5 * x_contrib + 0.5, " Y: ", 0.5 * y_contrib + 0.5 + 0.5) # print("X: ", 0.5 * (dx / mag) + 0.5, " Y: ", 0.5 * (dy / mag) + 0.5) # print("=================") return mag < 1.3
def pick_self(self, state, pad): if self.selected: self.lastState = state pad.release_button(p3.pad.Button.A) else: # Go to yoshi and press A target_x = 4.5 target_y = 18.5 # >>> choose fox >>> # target_x = -23.5 # target_y = 11.5 # <<< choose fox <<< dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 1.3: pad.press_button(p3.pad.Button.A) self.selected = True pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def make_action(state, pad, mm, fox): if state.menu == p3.state.Menu.Game: fox.advance(state, pad) elif state.menu == p3.state.Menu.Characters: mm.pick_fox(state, pad) elif state.menu == p3.state.Menu.Stages: # Handle this once we know where the cursor position is in memory. pad.tilt_stick(p3.pad.Stick.C, 0.5, 0.5) elif state.menu == p3.state.Menu.PostGame: mm.press_start_lots(state, pad)
def move_to(self, state, pad, x, y, eps=0.3): if not self.in_place: dx = x - state.players[2].cursor_x dy = y - state.players[2].cursor_y ad = math.sqrt(dx * dx + dy * dy) if ad < eps: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) self.in_place = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / ad) + 0.5, 0.5 * (dy / ad) + 0.5)
def pick_cpu(self, state, pad): if self.selected_cpu: pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) self.pick_cpu_level_9(state, pad) else: target_x = -16.0 target_y = -2 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < .5: pad.press_button(p3.pad.Button.A) self.selected_cpu = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def drag_to_9(self, state, pad): if self.dragged_to_9: pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) self.get_settings(state, pad) else: target_x = -7.0 target_y = -15.0 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < .5: pad.press_button(p3.pad.Button.A) self.dragged_to_9 = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def pick_itachi(self, state, pad): if self.selected_itachi: # Release buttons pad.release_button(p3.pad.Button.A) else: # Go to itachi and press A target_x = -23.5 target_y = 11.5 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.3: pad.press_button(p3.pad.Button.A) self.selected_itachi = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def get_settings(self, state, pad): if self.selected_settings: pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) self.change_settings(state, pad) else: target_x = 0.0 target_y = 30.0 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 5.1: pad.press_button(p3.pad.Button.A) self.selected_settings = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def char_setup(self, state, pad): if not self.marth_picked: self.pick_marth(state, pad) else: if not self.cpu_selected: self.select_cpu(state, pad) else: if not self.diff_set: self.set_diff(state, pad) else: # for some reason, won't press final START # ALSO, dk where cursor is in memory for stage select pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) if self.start: pad.release_button(p3.pad.Button.START) else: pad.press_button(p3.pad.Button.START) self.start = True
def pick_falco(self, state, pad): if self.selected_falco: pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) self.pick_cpu(state, pad) else: # Go to falco and press A target_x = -30 target_y = 11.5 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.5: pad.press_button(p3.pad.Button.A) self.selected_falco = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def pick_fox(self, state, pad): if self.selected_fox: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) pad.release_button(p3.pad.Button.A) return True else: # Go to fox and press A target_x = -23.5 target_y = 11.5 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 1: pad.press_button(p3.pad.Button.A) self.selected_fox = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5) return False
def pick_cpu(self, state, pad): if self.setup_cpu: return True if self.selected_cpu: # Release buttons and lazilly rotate the c stick. pad.release_button(p3.pad.Button.A) self.setup_cpu = True return False else: # Go to cpu and press A target_x = -15.5 target_y = -4.0 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.35: pad.press_button(p3.pad.Button.A) self.selected_cpu = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5) return False
def pick_fox(self, state, pad): if self.selected: # Release buttons and lazilly rotate the c stick. pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) angle = (state.frame % 240) / 240.0 * 2 * math.pi pad.tilt_stick(p3.pad.Stick.C, 0.4 * math.cos(angle) + 0.5, 0.4 * math.sin(angle) + 0.5) else: # Go to fox and press A target_x = -23.5 target_y = 11.5 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.3: pad.press_button(p3.pad.Button.A) self.selected = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def pick_fox(self, state, pad): if self.selected_fox: # Release buttons and lazilly rotate the c stick. pad.release_button(p3.pad.Button.A) pad.tilt_stick(p3.pad.Stick.MAIN, 0.5, 0.5) angle = (state.frame % 240) / 240.0 * 2 * math.pi pad.tilt_stick(p3.pad.Stick.C, 0.4 * math.cos(angle) + 0.5, 0.4 * math.sin(angle) + 0.5) else: # Go to fox and press A target_x = -23.5 target_y = 11.5 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.3: pad.press_button(p3.pad.Button.A) self.selected_fox = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5)
def set_rules(self, state, pad): if self.rules_set: pad.release_button(p3.pad.Button.B) return True if self.entered_menu: pad.release_button(p3.pad.Button.A) if self.menu_count == 0: pad.tilt_stick(p3.pad.Stick.MAIN, .5, 0) if self.menu_count == 1: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) if self.menu_count == 2: pad.tilt_stick(p3.pad.Stick.MAIN, 0, .5) if self.menu_count == 3: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) if self.menu_count == 4: pad.tilt_stick(p3.pad.Stick.MAIN, 0, .5) if self.menu_count == 5: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) if self.menu_count == 6: pad.tilt_stick(p3.pad.Stick.MAIN, 0, .5) if self.menu_count == 7: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) if self.menu_count == 8: pad.tilt_stick(p3.pad.Stick.MAIN, 0, .5) if self.menu_count == 9: pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) if self.menu_count == 10: pad.press_button(p3.pad.Button.B) self.rules_set = True if state.frame % 30 == 0: self.menu_count += 1 return False else: # Go to cpu and press A target_x = -15.5 target_y = 22 dx = target_x - state.players[2].cursor_x dy = target_y - state.players[2].cursor_y mag = math.sqrt(dx * dx + dy * dy) if mag < 0.35: pad.press_button(p3.pad.Button.A) self.entered_menu = True else: pad.tilt_stick(p3.pad.Stick.MAIN, 0.5 * (dx / mag) + 0.5, 0.5 * (dy / mag) + 0.5) return False
def execute(self, actions): pad_path = self.dolphin_dir + '/Pipes/p3' with p3.pad.Pad(pad_path) as pad: for action in actions: if action == 'MR': pad.tilt_stick(p3.pad.Stick.MAIN, .5, .5) elif action == 'MN': pad.tilt_stick(p3.pad.Stick.MAIN, .5, 1) elif action == 'MNW': pad.tilt_stick(p3.pad.Stick.MAIN, 1, 1) elif action == 'MW': pad.tilt_stick(p3.pad.Stick.MAIN, 1, .5) elif action == 'MSW': pad.tilt_stick(p3.pad.Stick.MAIN, 1, 0) elif action == 'MS': pad.tilt_stick(p3.pad.Stick.MAIN, .5, 0) elif action == 'MSE': pad.tilt_stick(p3.pad.Stick.MAIN, 0, 0) elif action == 'ME': pad.tilt_stick(p3.pad.Stick.MAIN, 0, .5) elif action == 'MNE': pad.tilt_stick(p3.pad.Stick.MAIN, 0, 1) if action == 'CR': pad.tilt_stick(p3.pad.Stick.C, .5, .5) elif action == 'CN': pad.tilt_stick(p3.pad.Stick.C, .5, 1) elif action == 'CNW': pad.tilt_stick(p3.pad.Stick.C, 1, 1) elif action == 'CW': pad.tilt_stick(p3.pad.Stick.C, 1, .5) elif action == 'CSW': pad.tilt_stick(p3.pad.Stick.C, 1, 0) elif action == 'CS': pad.tilt_stick(p3.pad.Stick.C, .5, 0) elif action == 'CSE': pad.tilt_stick(p3.pad.Stick.C, 0, 0) elif action == 'CE': pad.tilt_stick(p3.pad.Stick.C, 0, .5) elif action == 'CNE': pad.tilt_stick(p3.pad.Stick.C, 0, 1) if action == 'PA': pad.press_button(p3.pad.Button.A) elif action == 'RA': pad.release_button(p3.pad.Button.A) if action == 'PB': pad.press_button(p3.pad.Button.B) elif action == 'RB': pad.release_button(p3.pad.Button.B) if action == 'PY': pad.press_button(p3.pad.Button.Y) elif action == 'RY': pad.release_button(p3.pad.Button.Y) if action == 'PZ': pad.press_button(p3.pad.Button.Z) elif action == 'RZ': pad.release_button(p3.pad.Button.Z)