Shooter: enemy spawn problem

M

Max Doerwaldt

Guest
I am having trouble making my control object spawn different enemies. I have tried making different alarms but it only wants to spawn the basic enemy. If I put the spawns in the same alarm it will spawn them all at once which will impossible for the player to deal with. The spawn code is the same for each enemy with different object names.
Code:
var xpos = irandom_range(50, room_width-50);
// basic
instance_create(xpos, -100, obj_basic);
alarm[1] = room_speed * .8;
// bomber
var xpos = irandom_range(50, room_width-50);
instance_create(xpos, -100, obj_bomber);
alarm[2] = room_speed * 1.5;
 
C

chico_haze

Guest
Where are you running that code? Did you separate it out and put the "basic" in the alarm[1] event and "bomber" in alarm[2]? Assuming bomber is in alarm[2], are you sure you kicked off alarm[2] somewhere?
 
J

joqlepecheur

Guest
I don't really like alarms so I often use things like this:
Code:
//create event
steps_counter = 0 ;

//step event
steps_counter ++ ;
switch(steps_counter)
{
   case 60: //spawn ennemy # 1
  break ;
   case 180: //spawn ennemy # 2
  break ;
   case 190: //spawn ennemy # 3
  break ;
   case 400: //spawn ennemy # 4
  break ;
  case 401: instance_destroy(); break ;
}
 
Last edited by a moderator:
M

Max Doerwaldt

Guest
Where are you running that code? Did you separate it out and put the "basic" in the alarm[1] event and "bomber" in alarm[2]? Assuming bomber is in alarm[2], are you sure you kicked off alarm[2] somewhere?
The first spawn is alarm 1, the second is alarm 2, sorry I didn't clarify. What do you mean kicked off alarm 2?
 
M

Max Doerwaldt

Guest
I don't really like alarms so I often use things like this:
Code:
//create event
steps_counter = 0 ;

//step event
steps_counter ++ ;
switch(steps_counter)
{
   case 60: //spawn ennemy # 1
  break ;
   case 180: //spawn ennemy # 2
  break ;
   case 190: //spawn ennemy # 3
  break ;
   case 400: //spawn ennemy # 4
  break ;
  case 401: instance_destroy(); break ;
}
I'll try this, thanks for the advice!
 
C

chico_haze

Guest
The first spawn is alarm 1, the second is alarm 2, sorry I didn't clarify. What do you mean kicked off alarm 2?
By "kick off" I mean start the alarm running. I see that you have the alarms calling themselves, which is good, as this will keep them running in an infinite cycle. But you need to actually start them running somewhere.

I usually do this in the create event:
alarm[1] = room_speed * .8;
alarm[2] = room_speed * 1.5;


Because you said that only the basic enemy was spawning, it seemed possible you had forgotten to kick off alarm[2] in the create event.
 
M

Max Doerwaldt

Guest
By "kick off" I mean start the alarm running. I see that you have the alarms calling themselves, which is good, as this will keep them running in an infinite cycle. But you need to actually start them running somewhere.

I usually do this in the create event:
alarm[1] = room_speed * .8;
alarm[2] = room_speed * 1.5;


Because you said that only the basic enemy was spawning, it seemed possible you had forgotten to kick off alarm[2] in the create event.
oh ok, thanks a lot!
 

TheouAegis

Member
If you want random enemy spawnings, then you should use 1 alarm, a random value, and a 2D array to hold the enemy-alarm pairings.

Code:
/* CREATE EVENT */
spawn_chart[0,0] = obj_basic;
spawn_chart[0,1] = room_speed * 8/10;
spawn_chart[1,0] = obj_bomber;
spawn_chart[1,1] = room_speed * 3/2;
spawn_chart[2,0] = obj_kamikaze;
spawn_chart[2,2] = room_speed * 3/4;
//and so on just like that

alarm[0] = 1;
Code:
/* ALARM 0 EVENT */
var n = irandom(2) //change the 2 to the highest array index you used
instance_create(irandom_range(50,room_width-50), -100, spawn_chart[n,0]);
alarm[0] = spawn_chart[n,1];
 
Top