Sega Saturn Development > General Jo Engine Help
Question about IF statements
(1/1)
Basic_Coder_Man:
Ive managed to be able to change the background image by pressing A,B or C. Now Im trying to code it so you can choose different images depending on what image is on the screen .
for example:
ImageA is on screen
button A -loads Image B
button B -loads Image C
button C -loads Image D
but then when Image B is displaying you could choose say imageE - H so for each displayed image, you could choose different pictures to load,, rather than just one set for button A, another for button B and one for button C.
Now in Basic this would be a simple IF statement along this lines of"If Image A = enabled and Button A = pressed THEN Image G = enabled" but I have no idea how to do this in Jo engine, I tried to have a set:
static int level = 0;
then set:
if (jo_is_pad1_key_down(JO_KEY_C))
level = 1;
what I want in a nutshell is when Button C is pressed Level becomes 1 and then if Button A is pressed and Level = 1 a set image would be displayed. I looked at IF statements in JO but couldn't find anything that looked like what I need. ^^;
hope I explained it well, hope someone can point me in the right direction :)
mindslight:
Hi,
I think you wants a tree like the image in attachement.
The player choose one option (A, B or C) and you have new paths to choose, etc.
That's right ?
Basic_Coder_Man:
yes thats what I meant :) how do I code that in jo engine?
mindslight:
It's a C language problematic.
You can implement a tree or a simple table using indexes like this:
--- Code: ---
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();
}
--- End code ---
Navigation
[0] Message Index
Go to full version