I need some help with game math.
What I am using:
I am using java awt library.
What I am trying to do:
I am trying to build enemy health bar, which will display as an rectangle. I am display two rectangles. First one is black rectange and it will act as in base container. 2nd one is red rectangle and it will act as helath bar.
now the max size of enemy health bar will be enemy.getWidth(). I need some help with 2nd red rectangle width. how can I set up so that it dependents on enemy.getHealth() and max is enemy.getWidth.?
and enemy.getHealth() will be 4.
Code:
g.setColor(Color.black);
g.fillRect(enemy.getX(), enemy.getY(), enemy.getWidth(), 5);
g.setColor(Color.red);
g.fillRect(enemy.getX(), enemy.getY(), enemy.getHealth() * 3, 5);
Not sure if I explain this correct but I just want to change red rectangle with so that it depends on enemy.getHealth(). so if enemy get hit than red rectangle will go down by say 25%? and it keep going to on untill it reach 0.