Skip to content

Commit

Permalink
Allow inverted controls while flying (#391)
Browse files Browse the repository at this point in the history
  • Loading branch information
pifopi authored Dec 25, 2023
1 parent 0080b7e commit 0df64eb
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,12 @@ FlyingTrialFarmer::FlyingTrialFarmer()
LockMode::UNLOCK_WHILE_RUNNING,
50
)
, INVERT_CONTROLS_WHILE_FLYING(
"<b>Invert controls while flying:</b><br>"
"If you inverted controls while flying in game, turn this feature on as well.",
LockMode::UNLOCK_WHILE_RUNNING,
false
)
, NOTIFICATIONS({
&NOTIFICATION_PROGRAM_FINISH,
&NOTIFICATION_ERROR_FATAL,
Expand All @@ -79,6 +85,7 @@ FlyingTrialFarmer::FlyingTrialFarmer()
PA_ADD_OPTION(GO_HOME_WHEN_DONE);
PA_ADD_OPTION(NUM_TRIALS);
PA_ADD_OPTION(SAVE_NUM_ROUNDS);
PA_ADD_OPTION(INVERT_CONTROLS_WHILE_FLYING);
PA_ADD_OPTION(NOTIFICATIONS);
}

Expand Down Expand Up @@ -116,6 +123,15 @@ bool FlyingTrialFarmer::run_rewards(SingleSwitchProgramEnvironment& env, BotBase
}
}

uint8_t FlyingTrialFarmer::get_final_y_axis(int8_t delta_y) {
if (INVERT_CONTROLS_WHILE_FLYING) {
return 128 - delta_y;
}
else {
return 128 + delta_y;
}
}

void FlyingTrialFarmer::program(SingleSwitchProgramEnvironment& env, BotBaseContext& context){
assert_16_9_720p_min(env.logger(), env.console);

Expand Down Expand Up @@ -152,13 +168,13 @@ void FlyingTrialFarmer::program(SingleSwitchProgramEnvironment& env, BotBaseCont
if (ret_trial_start == 0) {
env.log("Countdown is over. Starting navigation sequence...");
pbf_wait(context, 3 * TICKS_PER_SECOND);
pbf_move_left_joystick(context, 180, 20, 1 * TICKS_PER_SECOND, 0); // go through the 2nd ring for additional time
pbf_move_left_joystick(context, 180, get_final_y_axis(-108), 1 * TICKS_PER_SECOND, 0); // go through the 2nd ring for additional time
pbf_wait(context, 2 * TICKS_PER_SECOND);
pbf_move_left_joystick(context, 40, 50, 240, 0); // adjust horizontal angle while gaining height
pbf_move_left_joystick(context, 40, get_final_y_axis(-78), 240, 0); // adjust horizontal angle while gaining height
pbf_wait(context, 1 * TICKS_PER_SECOND);
pbf_move_left_joystick(context, 128, 50, 2 * TICKS_PER_SECOND, 0); // adjust vertical height to cross mountain
pbf_move_left_joystick(context, 128, get_final_y_axis(-78), 2 * TICKS_PER_SECOND, 0); // adjust vertical height to cross mountain
pbf_wait(context, 13 * TICKS_PER_SECOND);
pbf_move_left_joystick(context, 128, 180, 2 * TICKS_PER_SECOND, 0); // descend for the gate
pbf_move_left_joystick(context, 128, get_final_y_axis(52), 2 * TICKS_PER_SECOND, 0); // descend for the gate
pbf_wait(context, 9 * TICKS_PER_SECOND);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,11 @@ class FlyingTrialFarmer : public SingleSwitchProgramInstance{
GoHomeWhenDoneOption GO_HOME_WHEN_DONE;
SimpleIntegerOption<uint16_t> NUM_TRIALS;
SimpleIntegerOption<uint16_t> SAVE_NUM_ROUNDS;
BooleanCheckBoxOption INVERT_CONTROLS_WHILE_FLYING;
EventNotificationsOption NOTIFICATIONS;

bool run_rewards(SingleSwitchProgramEnvironment& env, BotBaseContext& context);
uint8_t get_final_y_axis(int8_t delta_y);
};


Expand Down

0 comments on commit 0df64eb

Please sign in to comment.