(SOLVED)changing sprite index based on hp

A

Adjud

Guest
Hi,

I have a boss object controlled by a controller, the boss has a bass thats plant like when the bosses hp hits a certain lvl the base changes its image_index accordingly...

my step event code for objbossbase:

Code:
if controller.bosshp > 8000 {
    image_index=1;
}
if controller.bosshp > 5000 || controller.bosshp < 8000 {
    image_index=2;
}
if controller.bosshp > 1500 || controller.bosshp < 5000 {
    image_index=3;
}
if controller.bosshp > 0 || controller.bosshp < 1500 {
    image_index=4;
}
Edit2: I simplified the above code with
Code:
 image_index = controller.bossmhp/controller.bosshp;
this new code works better but is still not a perfect... the base has 4 images of color based on health, boss.mhp is the max hp of the boss which in this case is 10,000, bosshp is whats effected from damage. so essentially my code just divides the existing boss hp by the bosses max hp, im assuming since damage is so random the divided number won't be an even 1, 2, 3, 4.
is there a way to remove the digits after the decimal for my code? I want this to be relative with any boss hp.

the result is nothing, the base object stays at image_index 1. i simply want the sprite to change 1 index per quarter of boss hp, I'm sure there is a simpler way to this this than the code I guessed on above.

Thanks for any help

EDIT: Also what is the best way to make a sprite turn white on collision? I have the code to change its rgb or hsv, but if i set
Code:
image_blend=make_colour_rgb(255,255,255);
it makes the sprite normal, I can use that to change the color to red, blue purple etc, but I want it to change brighter or white as an effect when being hit by a weapon or spell.

whats the best way to do that?
 
Last edited by a moderator:

Simon Gust

Member
you need to pay attention to your code logic
Code:
if controller.bosshp > 8000 {
    image_index=1;
}
this will be true if the hp is greater than 8000, and will set image_index to 1
but this
Code:
if controller.bosshp > 0 || controller.bosshp < 1500 {
    image_index=4;
}
is also true, because hp at 10000 is also greater than 0 for example.

If you change the || to an && it will enforce both statements to be true before setting image_index to 4. But you might get complications with else-statements.
What you can also do is structure it differently and start from the bottom.
Code:
if (controller.bosshp < 1500) image_index = 4;
else
if (controller.bosshp < 5000) image_index = 3;
else
if (controller.bosshp < 8000) image_index = 2;
else image_index = 1;
To make it based on percentage, you need to define a max_hp variable which is the hp the boss starts with but never decreases.
Code:
var percentage = controller.bosshp / controller.boss_maxhp; // for example
if (percentage < 0.25) image_index = 4; // 25%
else
if (percentage < 0.50) image_index = 3; // 50%
else
if (percentage < 0.75) image_index = 2; // 75%
else image_index = 1;
for the whith flash on hit, there is a tutorial somewhere.
This maybe what you seek
 

TheouAegis

Member
(bossmhp - bosshp )/2500+1

That's a linear distribution.

For specific breakpoints, you need else, like Simon said.
 
A

Adjud

Guest
Thanks guys, that worked very well. sorry for all the stupid questions as I have stated before I am very unlearned mathematically... I'm more of an english/graphics artist/story teller.... I just don't have anyone else who would collaborate wtih me :\
thank you for the help I really appreciate it :)
 
Top