What you've posted is essentially a state machine, where the state variable is the value of kickTimer.
A generic state machine might look like this:
Quote:
// Set kicking loop to start when button 7 on gamepad is pressed and not in loop already
switch(kickState) {
case 0: // kicking is not in progress
if(gamePad.getRawButton(7) == true) {
start_the_kick_sequence_and_initialize_variables_a s_necessary();
kickState = 1;
}
break;
case 1:
if case_1_timer_or_event_has occurred(){
perform_case_1_action();
initialize_variables_for_case_2_as_necessary();
kickState=2;
}
break;
case 2:
if case_2_timer_or_event_has occurred(){
perform_case_2_action();
initialize_variables_for_case_3_as_necessary();
kickState=3;
}
break;
.
.
.
case n:
if case_n_timer_or_event_has occurred(){
perform_casen2_action();
initialize_variables_for_case_0_as_necessary();
kickState=0;
}
break;
}
|
The above has the advantage that it's a little easier to see how to use events (like limit switches etc) to change states, instead of being strictly timer-based.
~