What is a good way to make HP bar in ACM library java

30 views Asked by At

I am using ACM library in Java, How can I make a simple HP bar for the game. The health is an integer like 5 4 3 2 1 0

1

There are 1 answers

0
FailingCoder On

First, you fill a red rectangle for 0 health on an area. Then, you fill in a green rectangle with area [boxLocationX, boxLocationY, health, healthBarHeight].

For example:

//java.awt.Graphics
public void paint(Graphics g){
    g.setColor(Color.RED);
    g.fillRect(boxLocationX, boxLocationY, healthBarWidth, healthBarHeight);
    g.setColor(Color.GREEN);
    g.fillRect(boxLocationX, boxLocationY, health, healthBarHeight);
}

This paints a red rectangle and then a green rectangle over it.