First I would give a name to the system of shooting in both diagonal directions for a short period, perhaps somehting like “staggered_diagonal_fire”.
Then I would set bool flags for:
‘is_firing_diagonal_staggered’ to indicate if this is in action or not.
‘is_direction_change_recent’, to see if we have recently changed directions.
‘is_firing_staggered_in_movement_direction’, so we can flip this for left, then right, etc.
Then you would set these appropriately:
When the player changes direction:
is_direction_change_recent = true
When the player starts firing:
if is_direction_change_recent:
is_firing_diagonal_staggered = true
In your weapon system if diagonal firing flip direction each time you fire:
if is_firing_diagonal_staggered:
is_firing_staggered_in_movement_direction = not is_firing_staggered_in_movement_direction
Then when you fire your diagonal weapon, its direction is decided by is_firing_staggered_in_movement_direction and your current movement direction left or right. This will flip every time your weapon is fired until is_firing_diagonal_staggered changes to false.
You can then either, use a timer or a delta counter to set is_firing_diagonal_staggered back to false when your max time is exceeded, or you can count each diagonal fire when it is staggered and change it to false when you have fired, say, four diagonal shots.
You would then set a timer for the is_direction_change_recent. Whenever your player changes direction you reset this timer. When your is_firing_diagonal_staggered is due to reset, you re-check the is_direction_change_recent, and if it is again (as the player may have again changed direction) you can reset the staggered_diagonal firing timer or counter. So your player keeps firing in both directions if they are swapping directions rapidly.
So you have a flag and timer for ‘if direction change is recent’. Plus a flag and timer (or counter) for your ‘is alternating diagonal fire’. A direction change then allows for the alternating diagonal fire to be possible. When its counter or timer runs out, check if direction change is still recent and start again if it is.
Anyway, that’s sort-of how I would approach it. Hope that helps and was not too basic an answer for you.