Drag And Drop How can I create for example obstacle to spawn randomly out of 3 options and move down

Discussion in 'Programming' started by Aite, Jan 13, 2020 at 9:28 PM.

  1. Aite

    Aite Member

    Joined:
    Monday
    Posts:
    4
    Hello, sorry for the dumb question but I'm new with this kind of stuff and I really struggle with it. I'm making my own game but i don't know how to spawn out of 3 options spawn obstacle that the player who is down on the screen to move left, middle or right in order t o prevent being hit by it. I'll appreciate help!
     
  2. NimonoSolenze

    NimonoSolenze Member

    Joined:
    Jul 25, 2017
    Posts:
    25
    That's simple!

    Option 1:
    Code:
    var obstacle_array = [obstacle1, obstacle2, obstacle3];
    var choice = i_random(2);
    var obstacle = instance_create_layer(x, y, "Layer", obstacle_array[choice]);
    ... other stuff with the obstacle here
    Option2:
    Code:
    var obstacle = instance_create_layer(x, y, "Layer", choose(obstacle1, obstacle2, obstacle3));
    ... other stuff with the obstacle here
    The first option is a little easier to modify the invididual choices, but the latter is more efficient overall. In that case, you may want to use variables to reference the obstacles to choose from. Or perhaps an array, like

    Code:
    var obstacle_array = [obstacle1, obstacle2, obstacle3];
    var obstacle = instance_create_layer(x, y, "Layer", choose(obstacle_array[0], obstacle_array[1], obstacle_array[2]));
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice