D
DarthTenebris
Guest
Hello everyone,
Currently working on an idea that I have and it involves spawners as a method to bring in enemies. However I don't seem to be able to work out the logic on how to do so.
Create Event:
Alarm[0] Event:
The problem is the enemies seem to keep spawning in the walls or outside the room, I can't quite tell. Also for some reason only the top left corner spawner is able to spawn anything. When an enemy is created it simply tries to move in a straight line to get to the target, which is the blue box in the center. When an enemy dies, a particle effect is generated with a random size and color.
Note: The green circles are bullets from the player, no problem with that. Just happened to get caught in the screenshot.
Hopefully I've commented my code adequately to explain my thought train. Any idea what I'm doing wrong?
Thank you for your time.
Currently working on an idea that I have and it involves spawners as a method to bring in enemies. However I don't seem to be able to work out the logic on how to do so.
Create Event:
Code:
ros = room_speed * 5;
minRange = 64 * 2;
maxRange = 64 * 4;
minSpawn = 1;
maxSpawn = 4;
maxEnt = 8;
alarm[0] = ros;
Code:
var count = irandom_range(minSpawn, maxSpawn);
var spawn = false;
if (instance_exists(obj_enemy)) { // if enemy exists
var ent = 0;
for(var i = 0; i < instance_number(obj_enemy) - 1; i++) { // loop through all enemies
var enemy = instance_find(obj_enemy, i)
if (point_in_circle(enemy.x, enemy.y, x, y, maxRange)) { // check if enemy is too close
ent++; // count enemies that are too close
}
}
if ((ent + count) < maxEnt) {
spawn = true; // allow to spawn only if spawning the enemy doesnt cause to blow the limit
}
} else {
spawn = true; // if no enemy exists then obviously its fine to spawn
}
if (spawn) {
repeat(count) {
do { // keep trying to find free space
var dis = random_range(minRange, maxRange); // pick a random distance
var dir = random_range(0, 360); // pick a random angle
// convert polar (distance, angle) to cartesian (x, y) relative to spawner
var xspawn = lengthdir_x(dis, dir);
var yspawn = lengthdir_y(dis, dir);
} until ((!place_meeting(xspawn, yspawn, obj_wall)) // until it finds free space obviously
&& ((xspawn > 0) && (xspawn < room_width))
&& ((yspawn > 0) && (yspawn < room_height))) // and also isnt outside the room
instance_create_layer(x + xspawn, y + yspawn, "Instances", obj_enemy_kamikaze);
}
}
alarm[0] = ros;
Note: The green circles are bullets from the player, no problem with that. Just happened to get caught in the screenshot.
Hopefully I've commented my code adequately to explain my thought train. Any idea what I'm doing wrong?
Thank you for your time.
Last edited by a moderator: