• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

SOLVED How to make a spawner?

M

Machku

Guest
Hello, im using the latest version of GMS 2, and im making a shooter game, and im trying to make a spawner for it. I need to be able to change the time between spawns and waves, and enemy type, also enemys should pawn at an random y level. I have tried doing this;
///CREATE///
GML:
Delay = 300;
Spawned = 0;
///STEP///
GML:
Delay -= 1;
if (Delay <= 0) and (Spawned < 10)
{
    instance_create_layer(x,irandom_range(10,310),layer_get_id("Enemys"),oEnemy)
    Delay = 120;
    Spawned += 1;
}
if (Delay <= 0) and (10 < Spawned < 20)
{
    instance_create_layer(x,irandom_range(10,310),layer_get_id("Enemys"),oEnemyInter)
    Delay = 120;
    Spawned += 1;
}
But its really hard to add waves or change enemy types. Maybe using a script with some arguments to choose between enemys and waves???
 

zenousX

Member
you can declare different structs with some waves information inside. exp(Enemy types,Amount of each enemy, Delays, and etc...).
then just create some thing to handle your waves.
 
M

Machku

Guest
you can declare different structs with some waves information inside. exp(Enemy types,Amount of each enemy, Delays, and etc...).
then just create some thing to handle your waves.
The thing is, i don't know how to do that...
 
Basically like this
GML:
//An optional macro
#macro ENEMY_TYPE_1        "Blob"

//The constructor
function enemy_wave(_type, _quantity, _spawn_rate) constructor {
    type = _type;
    quantity = _quantity;
    quantity_left = quantity;
    spawn_rate = _spawn_rate;
}

//The variablwe containing the struct
global.enemy_wave = new enemy_wave(ENEMY_TYPE_1, 50, room_speed);

//To get or set the values
var _type = global.enemy_wave[$ "type"];        //This would GET the enemy type (in this case ENEMY_TYPE_1) and put it in the variable _type
global.enemy_wave[$ "quantity"] = 60;        //This would SET the number of enemies to 60  
global.enemy_wave[$ "spawn_rate"] = 30;        //This would SET your spawn rate to 30 steps
I will also leave you this link from Yoyo's Guest Blogs, this is a must-read, especially if you still don't use structs
Coding GUI Elements Using Structs | Blog | YoYo Games
 
Last edited:
M

Machku

Guest
Basically like this
GML:
//An optional macro
#macro ENEMY_TYPE_1        "Blob"

//The constructor
function enemy_wave(_type, _quantity, _spawn_rate) constructor {
    type = _type;
    quantity = _quantity;
    quantity_left = quantity;
    spawn_rate = _spawn_rate;
}

//The variablwe containing the struct
global.enemy_wave = new enemy_wave(ENEMY_TYPE_1, 50, room_speed);

//To get or set the values
var _type = global.enemy_wave[$ "type"];        //This would GET the enemy type (in this case ENEMY_TYPE_1) and put it in the variable _type
global.enemy_wave[$ "quantity"] = 60;        //This would SET the number of enemies to 60 
global.enemy_wave[$ "spawn_rate"] = 30;        //This would SET your spawn rate to 30 steps
I will also leave you this link from Yoyo's Guest Blogs, this is a must-read, especially if you still don't use structs
Coding GUI Elements Using Structs | Blog | YoYo Games
Thanks for explaining what every line does and what to do with them.
This helped a lot, and sorry for the late reply, was busy alot.
 
Top