1. Hello Guest! It's with a heavy heart that we must announce the removal of the Legacy GMC Archive. If you wish to save anything from it, now's the time! Please see this topic for more information.
    Dismiss Notice

bonus level spawn

Discussion in 'Programming' started by Davidb67, Sep 2, 2017.

  1. Davidb67

    Davidb67 Guest

    Totally new to this, and programming in general.

    I have a spawner that is persistent and spawns two objects at random intervals. On bonus levels i want to add a third object to the spawner. I guess i can make a different spawner for the bouns levels, but is there a way to do it with code? and where would i place the code.

    an old man thanks you for your help.
     
  2. Nexusrex

    Nexusrex Nexusrex Games

    Joined:
    Jun 20, 2016
    Posts:
    211
    So if I don't get it wrong, you have a spawner, spawning two enemies, and in the bonus level, you want it to spawn three enemies/objects instead of just one.
    Mind to show us your code? So we can have a better idea of what you are doing?
    But for now, all you can do, is if statements, check if room = rm_bonus, then spawn 3 enemies, if not, create the normal 2.
     
  3. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,145
    Spawn tge two ibjects. Check if it is a bonus level then spawn the third.
     
  4. Davidb67

    Davidb67 Guest

    you are correct. the code for the spawner is as such: i want to add a third object but only to the bonus level.



    // Randomize
    randomize();

    // Assign Variable
    r = 2;

    // Get Random Number
    r = floor(random_range(1, 2 + 1));

    // If Variable
    if(r == 2)
    {
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", object1_spawn);

    // Set Alarm Countdown
    alarm_set(spawnrate = max(1,50 - 5*(score div 50)), spawnrate);
    }

    // Else
    else
    {
    // Create Instance
    instance_create_layer(irandom_range(64,287), 64, "Instances", objectyellow_spawn);

    // Set Alarm Countdown
    alarm_set(spawnrate = max(1,50 - 5*(score div 50)), spawnrate);
    }
     
  5. TheouAegis

    TheouAegis Member

    Joined:
    Jul 3, 2016
    Posts:
    7,145
    Like we said, just check if the current level is the bonus level.
     
  6. Davidb67

    Davidb67 Guest

    so this is my new code in the alarm event of the spawner object. it works fine in all rooms except for room2 (which is the bonus at the moment). in that room it creates 2 of each object simultaneously instead of one at a time in a random order. any clue why this is happening?


    // If Variable
    if(room == room2)
    {
    // Randomize
    randomize();

    // Assign Variable
    r = 1;

    // Get Random Number
    var r = floor(random_range(1, 3 + 1));

    // Switch
    var l49D05CC2_0 = r;
    switch(l49D05CC2_0)
    {
    // Case
    case 1:
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", object1_spawn);
    break;

    // Case
    case 2:
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", objectyellow_spawn);
    break;

    // Case
    case 3:
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", object_boss_spawn);
    break;
    }
    }

    // Else
    else
    {

    }

    // Randomize
    randomize();

    // Assign Variable
    r = 1;

    // Get Random Number
    var r = floor(random_range(1, 2 + 1));

    // Switch
    var l04B5705C_0 = r;
    switch(l04B5705C_0)
    {
    // Case
    case 1:
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", object1_spawn);
    break;

    // Case
    case 2:
    // Create Instance
    instance_create_layer(random_range(64,287), 64, "Instances", objectyellow_spawn);
    break;
    }
     
  7. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,124
    Using code tags and indentation in your code would help readability a lot. I didn't see a problem in your code, so it could be elsewhere. Why not try this?

    Code:
    
    ///object spawner
    
    randomize();
    
    var spawn;
    
    if (room != bonus_room) {
        spawn = choose(1, 2);
        switch (spawn) {
            case 1: 
                /* spawn object 1 */
                break;
            case 2: 
                /* spawn object 2 */
                break;
        }
    } else {
        spawn = choose(1, 2, 3);
        switch (spawn) {
            case 1: 
                /* spawn object 1 */
                break;
            case 2: 
                /* spawn object 2 */
                break;
            case 3: 
                /* spawn object 3 */
                break;
        }
    }
    
    
     
  8. samspade

    samspade Member

    Joined:
    Feb 26, 2017
    Posts:
    2,124
    Alternatively, this might even be simpler:

    Code:
    
    var spawn;
    
    if (room != boss_room) {
        spawn = choose(1, 2);
    } else {
        spawn = choose(1, 2, 3);
    }
    
    switch (spawn) {
        case 1:
               /* spawn object 1 */
               break;
       case 2:
               /* spawn object 2 */
               break;
       case 3:
               /* spawn object 3 */
               break;
    }
    
    
    randomize() only needs to be called once and probably at the start of the game.
     
  9. Davidb67

    Davidb67 Guest

    thanks for your help guys!
     

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