External Exam Download Resources Web Applications Games Recycle Bin

intermittent spawner | gml

objGameManager Create

ticks = 0;
ring_instances = ds_list_create();

objGameManager Step

ticks += 1;

//every second, on the second:
if (ticks mod room_speed == 0){
    var inst = instance_create_layer(1,1,"Instances",objRing);
    with(inst){
        var aim_at_x = irandom_range(2,room_height);
        var aim_at_y = irandom_range(2,room_width);
        direction = point_direction(x,y,aim_at_x,aim_at_y);
        speed = irandom_range(1,10);
    }
    ds_list_add(ring_instances, inst);
}

//check for instances outside room, and destroy:
for (var i = 0; i < ds_list_size(ring_instances); i++){
    var inst = ds_list_find_value(ring_instances, i);
    if !point_in_rectangle(inst.x,inst.y,0,0,room_width,room_height){
        ds_list_delete(ring_instances, i);
        instance_destroy(inst);
    }
}

objGameManager Draw GUI

draw_text(20,20,"Rings: " + string(instance_number(objRing)));

for (var i = 0; i < ds_list_size(ring_instances); i++){
    draw_text(20,(60 + i*20),ds_list_find_value(ring_instances, i));
}

extension activities
The step event of the objGameManager can be modified so that the waves of enemies spawned are gradually increased over time:

objGameManager Step

ticks += 1;
var seconds_passed = ticks div room_speed;

//-------------------------------------------------------
//WAVE ONE: each second for first 5 seconds of game time:
if (ticks mod room_speed == 0 and seconds_passed <= 5){
	var inst = instance_create_layer(1,1,"Instances",objRing);
	with(inst){
	  var aim_at_x = irandom_range(2,room_height);
	  var aim_at_y = irandom_range(2,room_width);
	  direction = point_direction(x,y,aim_at_x,aim_at_y);
	  speed = irandom_range(1,10);
	}
    ds_list_add(ring_instances, inst);
}

//------------------------------------------------
//WAVE TWO: each half second, 
//during 10 to 15 seconds past start of game time:
if ( (ticks mod room_speed == 0 or 
	  ticks mod room_speed == room_speed div 2) 
		and seconds_passed >= 10 and seconds_passed <= 15){
			var inst = instance_create_layer(1,1,"Instances",objRing);
			with(inst){
			  var aim_at_x = irandom_range(2,room_height);
			  var aim_at_y = irandom_range(2,room_width);
			  direction = point_direction(x,y,aim_at_x,aim_at_y);
			  speed = irandom_range(1,10);
			}
		    ds_list_add(ring_instances, inst);
}

//------------------------------------------------
//WAVE THREE: each quarter second (4 per sec), 
//during 20 to 30 seconds past start of game time:
if ( (ticks mod room_speed == 0 or 
	  ticks mod room_speed == room_speed div 2 or
	  ticks mod room_speed == room_speed div 4) 
		and seconds_passed >= 20 and seconds_passed <= 30){
			var inst = instance_create_layer(1,1,"Instances",objRing);
			with(inst){
			  var aim_at_x = irandom_range(2,room_height);
			  var aim_at_y = irandom_range(2,room_width);
			  direction = point_direction(x,y,aim_at_x,aim_at_y);
			  speed = irandom_range(1,10);
			}
		    ds_list_add(ring_instances, inst);
}

//------------------------------------------------
//check for instances outside room, and destroy:
for (var i = 0; i < ds_list_size(ring_instances); i++){
	var inst = ds_list_find_value(ring_instances, i);
	if !point_in_rectangle(inst.x,inst.y,0,0,room_width,room_height){
		ds_list_delete(ring_instances, i);
		instance_destroy(inst);
	}
}