bonus level spawn

D

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.
 
N

Nexusrex

Guest
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.
 
D

Davidb67

Guest
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.
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);
}
 
D

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;
}
 

samspade

Member
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;
}
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;
    }
}
 

samspade

Member
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.
 
Top