-2

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

Joachim Sauer
  • 302,674
  • 57
  • 556
  • 614
  • When asking homework questions, please show your best good faith attempt to solve it and tell what problems you are having to give us a better understanding of your intentions, what you might be doing wrong, and your goal. Please go through the [tour](http://stackoverflow.com/tour), the [help](http://stackoverflow.com/help), and the [How to Ask](http://stackoverflow.com/how-to-ask) sections to see how this site works and to help you improve your current and future questions. Please also have a look at [How do I ask and answer Homework questions?](http://meta.stackoverflow.com/questions/334822) – FailingCoder Nov 10 '19 at 23:42
  • oh this is my project, not a homework question – fastmen192911 Nov 11 '19 at 00:22
  • You are still doing this as a project. You are still asking for people to do the project for you. I am now still calling this a homework question, because it is a convenient stereotype that your question falls into. – FailingCoder Nov 11 '19 at 00:23

1 Answers1

0

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.

FailingCoder
  • 757
  • 1
  • 8
  • 20