W
Will
Guest
Below is the object that manages spawning enemies in my game.
How it should work: If there are 0 enemies left to spawn (enemyCount), and no enemies are left (obj_enemy), increase the round, increase the amount of enemies spawned this round by 1 (enemiesMax) and set enemyCount = to enemyMax. If there are enemies left to spawn, spawn one every 1-3 seconds at a random spawn point (there are 5 instances of obj_spawner).
This works fine for the first 2 rounds. As soon as round 2 is complete, enemyCount will continue ticking down like it's creating enemies, and when it's 0, round_ will increase and so will enemiesMax and enemyCount, however no instances of obj_baby are created after round 2. obj_baby holds code turning it into a different enemy type on create, and this works as intended.
Furthermore, enemies are not spawning at spawner.x,spawner.y. They are being created at the player's x,y position. This was working fine before, but now that I have this system in place (no changes to their code, only to the spawn/round system), they don't spawn in the right place.
Step Event:
Alarm 6:
Alarm 7:
Does anyone have any idea why this might not be working? Did I create a bad loop somewhere?
How it should work: If there are 0 enemies left to spawn (enemyCount), and no enemies are left (obj_enemy), increase the round, increase the amount of enemies spawned this round by 1 (enemiesMax) and set enemyCount = to enemyMax. If there are enemies left to spawn, spawn one every 1-3 seconds at a random spawn point (there are 5 instances of obj_spawner).
This works fine for the first 2 rounds. As soon as round 2 is complete, enemyCount will continue ticking down like it's creating enemies, and when it's 0, round_ will increase and so will enemiesMax and enemyCount, however no instances of obj_baby are created after round 2. obj_baby holds code turning it into a different enemy type on create, and this works as intended.
Furthermore, enemies are not spawning at spawner.x,spawner.y. They are being created at the player's x,y position. This was working fine before, but now that I have this system in place (no changes to their code, only to the spawn/round system), they don't spawn in the right place.
Step Event:
Code:
if enemyCount <= 0 && instance_number(obj_enemy) <= 0 {
round_ ++;
enemiesMax ++;
enemyCount = enemiesMax;
alarm[7] = room_speed * 5;
itemSpawn = instance_random(obj_spawner);
instance_create_layer(itemSpawn.x,itemSpawn.y,"layer_enemies",obj_item);
}
if instance_number(obj_enemy) <= enemiesMax and canSpawn {
randomize();
spawner = instance_random(obj_spawner);
instance_create_layer(spawner.x,spawner.y,"layer_enemies",obj_baby);
canSpawn = false;
enemyCount --;
alarm[6] = irandom_range(1,3) * room_speed;
}
Code:
if enemyCount > 0 {
canSpawn = true;
}
Code:
canSpawn = true;