Author Topic: Question about IF statements  (Read 1445 times)

Basic_Coder_Man

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Question about IF statements
« on: October 07, 2016, 08:46:40 pm »
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

  • Administrator
  • Full Member
  • *****
  • Posts: 157
  • Karma: +6/-1
    • View Profile
    • Jo Engine
Re: Question about IF statements
« Reply #1 on: October 10, 2016, 02:11:24 pm »
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

  • Newbie
  • *
  • Posts: 3
  • Karma: +0/-0
    • View Profile
Re: Question about IF statements
« Reply #2 on: October 11, 2016, 06:19:04 pm »
yes thats what I meant :)  how do I code that in jo engine?

mindslight

  • Administrator
  • Full Member
  • *****
  • Posts: 157
  • Karma: +6/-1
    • View Profile
    • Jo Engine
Re: Question about IF statements
« Reply #3 on: October 14, 2016, 01:52:49 pm »
It's a C language problematic.

You can implement a tree or a simple table using indexes like this:

Code: [Select]
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();
}
« Last Edit: October 14, 2016, 05:43:46 pm by mindslight »

 

Sitemap 1 2 3 4 5 6 7 8 9 10 
SMF spam blocked by CleanTalk