J

#### joedirtdigger

##### Guest

SO I have this code and I know it will work, but I am curious if I am missing an easier or more compact way to do accomplish the task. As it stands I will have to write 100 if statements to account for all the variables possible and that is just a bit excessive imo. I was wondering if anyone had any ideas on how to accomplish the same thing with a single if statement or group of if statements designed to adjust itself via other variables.

The code is used to adjust the image index for the players HP gauge. I have a 100 slide sprite with decreasing visual indication of player hp. The code will convert the players current hp into a percentage that is then checked against the "if statement from hell" to display the correct image index based off the data given.

The reason I have chosen to do this in the way described is so that as the players HP total increases as game play progresses the hp gauge will continue to accurately show the current hp vs total hp on the hp gauge.

I am also not using the built in HP gauge as I do not like the standard hp bar my hp gauge is a half circle instead and wraps around the players ship.

so given all that info here is a snip of the current code:

///scr_cal_perc_damage(current_player_hp, total_player_hp)

hp_perc_holder = (current_player_hp / total_player_hp);

hp_percent = round(hp_perc_holder * 100);

if (hp_percent <100 && hp_percent > 98) {

draw_sprite(spr_player_hp_ring100, -1, x, y);

image_index = 1;

} else if (hp_percent < 99 && hp_percent > 97) {

draw_sprite(spr_player_hp_ring100, -1, x, y);

image_index = 2;

} else if (hp_percent < 98 && hp_percent > 96) {

draw_sprite(spr_player_hp_ring100, -1, x, y);

image_index = 3;

} else if (hp_percent < 97 && hp_percent > 95) {

draw_sprite(spr_player_hp_ring100, -1, x, y);

image_index = 4;

} else if (hp_percent < 96 && hp_percent > 94) {

draw_sprite(spr_player_hp_ring100, -1, x, y);

etc, etc, etc

thanks in advance for any replies