Legacy GM [SOLVED]Help Spawning X Amount of Enemies Each Level

D

dawson2223

Guest
Hi everyone,

I'm trying to have it so 5 enemies spawn the first round, and then every round the number increases by 5.
I've tried using the "do" "until" tool but I don't think it works for this.

Still pretty new with GameMaker so I don't know a lot.

Any thoughts?
 

jazzzar

Member
Have a variable that holds the number of enemies in each round, let's call it enemies, on game start use :
Code:
Enemies=5;
Now when you want to spawn the enemis simply use :
Code:
repeat(Enemies)
      instance_create(whatever x, whatever y, enemy);
After that just increase enemies variable, this thing is really fairly simple
 
D

dawson2223

Guest
Have a variable that holds the number of enemies in each round, let's call it enemies, on game start use :
Code:
Enemies=5;
Now when you want to spawn the enemis simply use :
Code:
repeat(Enemies)
      instance_create(whatever x, whatever y, enemy);
After that just increase enemies variable, this thing is really fairly simple

I put it in the game start and the code didn't work. I put it in an alarm and it did work, but the enemies were placed in at the same time and ended up overlapping each other. This, however, did only produce 5 enemies, so that's good.
When I try to use the spawnRate variable I created they keep spawning and don't stop.

Right now my code for my obj_cont_spawn is:
Create Event:
// Enemy Spawn
spawnRate = random_range(1 * room_speed,3 * room_speed);
alarm[0] = spawnRate;

Alarm[0}:
Enemies = 5;

repeat(Enemies)
instance_create(2144,1504,obj_enemy);


Thoughts? And thank you for your help!
 
C

CROmartin

Guest
Have a variable that holds the number of enemies in each round, let's call it enemies, on game start use :
Code:
Enemies=5;
Now when you want to spawn the enemis simply use :
Code:
repeat(Enemies)
      instance_create(whatever x, whatever y, enemy);
After that just increase enemies variable, this thing is really fairly simple
Without ofend but I think you didnt help the novice(I get you but he probaly dont), he need that "just".
Code:
///number of enemy spawing, put it in create event
Enemies =  5
///I see you want know whic round is it so add this variable to
Round = 1
///now spawning and  increase
if instance_number(enemy) = 0 
{
repeat(Enemies)
             {{instance_create(whatever x, whatever y, enemy)}
Enemies += 5
Round += 1
}
///In draw event do this for displaying round number on scren
draw_self();
draw_text(view_xview+10,view_yview+10,string(round))
///adjust coordinates for your self
So this code will every time you kill all enemys spawn new wave but add 5 more and display number of rounds. If I made mistake let me know.
 

TheouAegis

Member
Either you do not want the enemies to spawn in the same spot or you do and you want them to spawn over a period time after they've moved away from each other. If you don't want them to spawn in the same spot, don't use the same value for x and y for every enemy. If you're going to use repeat, then you cannot have the enemy spawning in the same location. Alternatively, don't repeat, just count how many enemies are in the room and if it is less than your spawn limit create a new one. If you're going to use an alarm, do not forget to reset the alarm can the alarm event.
 
D

dawson2223

Guest
Without ofend but I think you didnt help the novice(I get you but he probaly dont), he need that "just".
Code:
///number of enemy spawing, put it in create event
Enemies =  5
///I see you want know whic round is it so add this variable to
Round = 1
///now spawning and  increase
if instance_number(enemy) = 0
{
repeat(Enemies)
             {{instance_create(whatever x, whatever y, enemy)}
Enemies += 5
Round += 1
}
///In draw event do this for displaying round number on scren
draw_self();
draw_text(view_xview+10,view_yview+10,string(round))
///adjust coordinates for your self
So this code will every time you kill all enemys spawn new wave but add 5 more and display number of rounds. If I made mistake let me know.
thanks! they all spawned in the same place though. and after I killed them no more spawned. I'm a little confused lol.
 
D

dawson2223

Guest
Either you do not want the enemies to spawn in the same spot or you do and you want them to spawn over a period time after they've moved away from each other. If you don't want them to spawn in the same spot, don't use the same value for x and y for every enemy. If you're going to use repeat, then you cannot have the enemy spawning in the same location. Alternatively, don't repeat, just count how many enemies are in the room and if it is less than your spawn limit create a new one. If you're going to use an alarm, do not forget to reset the alarm can the alarm event.
Okay thank you, this makes sense. I do want them to show up in the same location.

Can you provide what the code would look like for this?
"don't repeat, just count how many enemies are in the room and if it is less than your spawn limit create a new one. If you're going to use an alarm, do not forget to reset the alarm can the alarm event."
 
C

CROmartin

Guest
thanks! they all spawned in the same place though. and after I killed them no more spawned. I'm a little confused lol.
Did you look on difrence between var Enemies and obj enemy? It should work fine I am 100% sure. Did you put in step event after ///spawning and increase, sry I forgot to mention it.
you need put this in step event(code belove)
if instance_number(enemy) = 0
{
repeat(Enemies)
{{instance_create(whatever x, whatever y, enemy)}
Enemies += 5
Round += 1
}
 
D

dawson2223

Guest
Did you look on difrence between var Enemies and obj enemy? It should work fine I am 100% sure. Did you put in step event after ///spawning and increase, sry I forgot to mention it.
you need put this in step event(code belove)
if instance_number(enemy) = 0
{
repeat(Enemies)
{{instance_create(whatever x, whatever y, enemy)}
Enemies += 5
Round += 1
}
Oh it wasn't in the step event that is why. Okay it worked Thanks!!! How can I make the spawns like a second spaced out so they don't overlap??
 
C

CROmartin

Guest
Oh it wasn't in the step event that is why. Okay it worked Thanks!!! How can I make the spawns like a second spaced out so they don't overlap??
No problem.You think to they dont spawn on same spot? If you think on that you need change in this code(just add random_range(-100,100) in instance_create code like in code belove)
Code:
instance_create( x+random_range(-100,100),  y+random_range(-100,100), enemy)
For now it will be good(it wont spawn on same place probaly ,but is posible bcs its random ,but chance to that happens are rly small) ,tomorow I can explain abouth x,y grind and help you make more advanced spawner. I go to sleep now, good night sir.
 
D

dawson2223

Guest
No problem.You think to they dont spawn on same spot? If you think on that you need change in this code(just add random_range(-100,100) in instance_create code like in code belove)
Code:
instance_create( x+random_range(-100,100),  y+random_range(-100,100), enemy)
For now it will be good(it wont spawn on same place probaly ,but is posible bcs its random ,but chance to that happens are rly small) ,tomorow I can explain abouth x,y grind and help you make more advanced spawner. I go to sleep now, good night sir.
Thank you so much for your help! Good night.
 
C

CROmartin

Guest
Code:
/// creat event
Repeater_value = 5
Repeater = Repeater_value
///in alarm[0],instance_create adjust how you want
if Repeater > 0
 {
Repeater -= 1 
alarm[0] = 0.5*room_speed
 instance_create(x,y,obj_enemy)
}
///in step event
if alarm[0] = -1 && Repeater > 0 {alarm [0] = 0.5*room_speed}
if instance_number(obj_enemy) = 0 && Repeater = 0
 {
Repeater_value += 5
Repeater = Repeater_value
}
Let me know if doesnt work(it is from head so not sure 100% if will work).
 
D

dawson2223

Guest
Code:
/// creat event
Repeater_value = 5
Repeater = Repeater_value
///in alarm[0],instance_create adjust how you want
if Repeater > 0
 {
Repeater -= 1
alarm[0] = 0.5*room_speed
 instance_create(x,y,obj_enemy)
}
///in step event
if alarm[0] = -1 && Repeater > 0 {alarm [0] = 0.5*room_speed}
if instance_number(obj_enemy) = 0 && Repeater = 0
 {
Repeater_value += 5
Repeater = Repeater_value
}
Let me know if doesnt work(it is from head so not sure 100% if will work).
They're still coming in at the same time. I probably put it in wrong do you want me to send you the .gmx file so you can see if I did it right?
 
D

dawson2223

Guest
Code:
/// creat event
Repeater_value = 5
Repeater = Repeater_value
///in alarm[0],instance_create adjust how you want
if Repeater > 0
 {
Repeater -= 1
alarm[0] = 0.5*room_speed
 instance_create(x,y,obj_enemy)
}
///in step event
if alarm[0] = -1 && Repeater > 0 {alarm [0] = 0.5*room_speed}
if instance_number(obj_enemy) = 0 && Repeater = 0
 {
Repeater_value += 5
Repeater = Repeater_value
}
Let me know if doesnt work(it is from head so not sure 100% if will work).

Nevermind I think I got it!!!!
 
D

dawson2223

Guest
So did code work or you did your code? I am just curious.
Hey man! Just wanted to let you know I went back to your code and it works great!!! I just had to increase the time between each alarm, starting to learn more about GML. I'm also reading the GameMaker Manual and it's been helping a lot! You're the best!!!!
 
M

matejj

Guest
Hey, does anybody know how to add new enemies when you reach a certain wave ?? thanks in advance
 

TheouAegis

Member
Way to hijack a thread without anything to contribute...

Post your wave spawning code. We can't help you without it.

And next time, start your own threads; don't hijack others.
 
C

CROmartin

Guest
Hey man! Just wanted to let you know I went back to your code and it works great!!! I just had to increase the time between each alarm, starting to learn more about GML. I'm also reading the GameMaker Manual and it's been helping a lot! You're the best!!!!
I am glade to help you!
matejj if you are new I highly recomend you to read GameMaker help documents
/// creat event
Repeater_value = 5
Repeater = Repeater_value
Round = 1
///in alarm[0],instance_create adjust how you want
if Repeater > 0
{
Repeater -= 1
alarm[0] = 0.5*room_speed
instance_create(x,y,obj_enemy)
// this will start spawning new enemy after 3 waves,ofc you need make little adjustment
if Round > 3 instance_create(x,y,obj_enemy_2)
//this will spawn twice smaller number then a obj_enemy, just play with math if you want specific number to be spawned
if Round > 3 && Repeater > Repeater/2 instance_create(x,y,obj_enemy_2)
}
///in step event
if alarm[0] = -1 && Repeater > 0 {alarm [0] = 0.5*room_speed}
if instance_number(obj_enemy) = 0 && Repeater = 0
{
Repeater_value += 5
Repeater = Repeater_value
Round += 1
}
 
D

dawson2223

Guest
I am glade to help you!
matejj if you are new I highly recomend you to read GameMaker help documents
/// creat event
Repeater_value = 5
Repeater = Repeater_value
Round = 1
///in alarm[0],instance_create adjust how you want
if Repeater > 0
{
Repeater -= 1
alarm[0] = 0.5*room_speed
instance_create(x,y,obj_enemy)
// this will start spawning new enemy after 3 waves,ofc you need make little adjustment
if Round > 3 instance_create(x,y,obj_enemy_2)
//this will spawn twice smaller number then a obj_enemy, just play with math if you want specific number to be spawned
if Round > 3 && Repeater > Repeater/2 instance_create(x,y,obj_enemy_2)
}
///in step event
if alarm[0] = -1 && Repeater > 0 {alarm [0] = 0.5*room_speed}
if instance_number(obj_enemy) = 0 && Repeater = 0
{
Repeater_value += 5
Repeater = Repeater_value
Round += 1
}

Hey! I have a quick question. I have two different enemies and I want them to spawn with each other each round. So Round two there may be 3 of enemy 1 and 2 of enemy 2 and so on. I can't get the code to work. If i put a variable in the creation code it will only randomly spawn 1 enemy and the game will only spawn that enemy. If i put it in the step event it just keeps spawning enemies. How do I do this?!?!


Code:
///Create Event
//Round = 1
Repeater_value = 1
Repeater = Repeater_value
global.Round = 1
test =  choose(obj_Enemy,obj_brunetteEnemy)
x1 = 896
x2 = 224
x3 = 928
x4 = 1600

y1 = 128
y2 = 640
y3 = 608
y4 = 64
Code:
///Alarm[0]
if (Repeater > 0) {
    Repeater -= 1;
    alarm[0] = room_speed;
    var eny = instance_create(choose(x1,x2,x3,x4),y,test);
Code:
///Step Event

if alarm[0] = -1 && Repeater > 0 {alarm [0] = room_speed}
if instance_number(global.test) = 0 && Repeater = 0
 {
Repeater_value += 4
Repeater = Repeater_value
global.Round += 1
}
 
C

CROmartin

Guest
dawson2223
Code:
///Create Event
//Round = 1
global.Round = 1
Repeater_value_obj_enemy =  Round *1.5// so I aimd to there is 3 enemy in round 2 as you said
Repeater_1 = Repeater_value_obj_enemy
Repeater_value_obj_brunetteEnemy  = Round div 1 // so I aimd to there is 2 enemy in round 2 as you said
Repeater_2 = Repeater_value_obj_brunetteEnemy

x1 = 896
x2 = 224
x3 = 928
x4 = 1600

y1 = 128
y2 = 640
y3 = 608
y4 = 64
Code:
///Alarm[0]
if (Repeater_1 > 0) {
    Repeater_1 -= 1;
    alarm[0] = room_speed;
    var eny = instance_create(choose(x1,x2,x3,x4),y,obj_enemy);
Code:
///Alarm[1]
if (Repeater_2 > 0) {
    Repeater_2 -= 1;
    alarm[1] = room_speed;
    var eny = instance_create(choose(x1,x2,x3,x4),y,obj_brunetteEnemy);
Code:
///Step Event

if alarm[0] = -1 && Repeater_1 > 0 {alarm [0] = room_speed}
if instance_number(obj_enemy) = 0 && Repeater_1  = 0
 {
global.Round += 1
Repeater_value_obj_enemy =  Round *1.5
Repeater_1 = Repeater_value_obj_enemy
}

if alarm[1] = -1 && Repeater_2 > 0 {alarm [1] = room_speed}
if instance_number(obj_brunetteEnemy) = 0 && Repeater_2  = 0
 {
global.Round += 1
Repeater_value_obj_brunetteEnemy  = Round div 1
Repeater_2 = Repeater_value_obj_brunetteEnemy
}
So this code will spawn depending on which round is it. If you dont understand code or code doesent work pleas let me know.
 
G

Gabipixel

Guest
Hey! I have a problem... I did the code exactly how it is written, but the horde always stops on 5, can someone please help me? I have tried everything, and nothing worked...
 
Top