Avram
Member
Hi all,
Is there a more efficient way to write the following code?
If the enemy is hit with obj_fire_up then the enemy's health (blob_health) is decreased.
I have five frames of damage for it to cycle through (e.g. health at 50, move to frame 01, health at 40, move to frame 02, etc.)
Thanks in advance!
Is there a more efficient way to write the following code?
If the enemy is hit with obj_fire_up then the enemy's health (blob_health) is decreased.
I have five frames of damage for it to cycle through (e.g. health at 50, move to frame 01, health at 40, move to frame 02, etc.)
Thanks in advance!
GML:
if instance_place(x,y,obj_fire_up)
{
blob_health -= 1;
spin += 0.1;
//bad code to animate
if blob_health = 50
{
image_index = 1;
instance_create(x,y,obj_blob_bit);
}
if blob_health = 40
{
image_index = 2;
instance_create(x,y,obj_blob_bit);
}
if blob_health = 30
{
image_index = 3;
instance_create(x,y,obj_blob_bit);
}
if blob_health = 20
{
image_index = 4;
instance_create(x,y,obj_blob_bit);
}
if blob_health = 10
{
image_index = 5;
instance_create(x,y,obj_blob_bit);
}
if blob_health = 0
{
for (var i = 0; i < 6; i += 1)
{
instance_create(x,y,obj_blob_bit);
}
instance_destroy();
}
}