if (current_target_list != noone) {
if (hurt && image_index > 3) { //I rearanged this so that is more of a switch
if (targets_defeated >= ds_list_size(current_target_list)) {
ds_list_destroy(current_target_list); //we have defeated all enemies. To avoid a memory leak, we destroy this list
current_target_list = noone; //And set it to noone (-4) again so that our first if statements fails and we can check again for enemies
} else {
var current_target = ds_list_find_value(current_target_list,targets_defeated); //we get the current entry of the ds_list
damage_target(current_target, attack); //hurt target here
hurt = false;
/*
I Don't know how damage_target(); looks like but you have to increase the variable
"targets_defeated" by 1 if you defeat one of the enemies!
targets_defeated += 1;
You can check collision again in your damage_target() script but this time collision_line() should suffice.
If it isn't there delete the list so it's reset and we don't have to deal with adding IDs to the list.
*/
var make_sure = collision_line(x-attack_area_x, y, x+attack_area_x, y, obj_enemy, false, true);
if (make_sure == noone) {
ds_list_destroy(current_target_list);
current_target_list = noone;
}
}
} else {
if (can_attack) {
alarm[0] = room_speed * attack_speed; //alarm to set can_attack flag
speed = 0;
hurt = true;
image_speed = 0.4;
can_attack = false;
}
}
} else {
//GET SOME ENEMY IDS IN THE LIST
current_target_list = collision_line_list(x-attack_area_x, y, x+attack_area_x, y, obj_enemy, false, true);
if (current_target_list != noone) {
list_size = ds_list_size(current_target_list); //this is our list full of enemy IDs
targets_defeated = 0; //this will keep track of how many enemies you have slain
} else { //the list returns noone if no enemy is found
x += move_speed;
}
}