It's a C language problematic.
You can implement a tree or a simple table using indexes like this:
typedef struct
{
char *image_name;
int button_a_index;
int button_b_index;
int button_c_index;
} t_game_step;
# define BUTTON_INACTIVE (-1)
t_game_step game_steps[] =
{
{ "A.TGA", 1, 2, 3 },
{ "B.TGA", 0, 2, BUTTON_INACTIVE },
{ "C.TGA", 1, 0, 3 },
{ "D.TGA", BUTTON_INACTIVE, 0, 1 },
};
int current_game_step = 0;
void change_background(char *image_name)
{
jo_img img;
img.data = JO_NULL;
if (jo_tga_loader(&img, JO_ROOT_DIR, image_name, JO_COLOR_Transparent))
{
jo_set_background_sprite(&img, 0, 0);
jo_free_img(&img);
}
}
void my_gamepad(void)
{
if (game_steps[current_game_step].button_a_index != BUTTON_INACTIVE && jo_is_pad1_key_down(JO_KEY_A))
{
current_game_step = game_steps[current_game_step].button_a_index;
change_background(game_steps[current_game_step].image_name);
}
else if (game_steps[current_game_step].button_b_index != BUTTON_INACTIVE && jo_is_pad1_key_down(JO_KEY_B))
{
current_game_step = game_steps[current_game_step].button_b_index;
change_background(game_steps[current_game_step].image_name);
}
else if (game_steps[current_game_step].button_c_index != BUTTON_INACTIVE && jo_is_pad1_key_down(JO_KEY_C))
{
current_game_step = game_steps[current_game_step].button_c_index;
change_background(game_steps[current_game_step].image_name);
}
}
void my_draw(void)
{
}
void jo_main(void)
{
jo_core_init(JO_COLOR_Black);
jo_core_add_callback(my_gamepad);
jo_core_add_callback(my_draw);
current_game_step = 0;
change_background(game_steps[current_game_step].image_name);
jo_core_run();
}