change you draw to
draw_sprite(spr_orc,image_single,x,y);
if(bbox_left < 0) exit;
if(bbox_top < 0 ) exit;
if(bbox_right > room_width) exit;
if(bbox_bottom > room_height) exit;
multiplier = 100/this_creep.creep_maxhealth;
draw_healthbar(x-10,y-18,x+10,y-14,this_creep.creep_health*multiplier,c_black,c_red,c_green,0,1,1);
Pretty sure you have a slow PC and it does not like that draw_healthbar.
actually. remove the draw event from all your creaps.
Add the draw event in the creep parent
draw_sprite(sprite_index,image_number,x,y);
if(bbox_left < 0) exit;
if(bbox_top < 0 ) exit;
if(bbox_right > room_width) exit;
if(bbox_bottom > room_height) exit;
multiplier = 100/this_creep.creep_maxhealth;
draw_healthbar(x-10,y-18,x+10,y-14,this_creep.creep_health*multiplier,c_black,c_red,c_green,0,1,1);
you can probably do the same for all your creep events that are the same in all the creep types. move the code to the parent, make the code more generic like I did with the sprite_index image_number bit
You can also remove the precision Collision from your sprites, given you use
// makes sure the tower turns to the right direction
image_single = direction;
// following the closest creep passing if it comes within range
if(distance_to_object(obj_creep_basic) < towerrange) {
direction = round((point_direction(x,y,instance_nearest(x,y,obj_creep_basic).x,instance_nearest(x,y,obj_creep_basic).y)/360)*32);
}
// fires a bullet when the creep comes within tower range
if(distance_to_object(obj_creep_basic) < towerrange) {
if(fire_bullet == true) {
instance_create(x,y,obj_ranger_bullet);
fire_bullet = false;
}
}
to find the instance. distance_to_object is a little intensive, precission OF may make it faster. but here is the optimal code
creep create, add
radius = point_distance(0,0,sprite_width,sprite_height) /2;
and your range finder code above can be changed to
ins = instance_nearest(x,y,obj_creep_basic);
if(ins == noone) exit;
if((point_distance(x,y,ins.x,ins.y) - ins.radius) < towerrange)
{
direction = point_direction(x,y,ins.x,ins.y);
if(fire_bullet == true) {
instance_create(x,y,obj_ranger_bullet);
fire_bullet = false;
}
}