Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.

1. ## Percentage Bar

Hi, me and my friend are working a on PHP web based game. We ran into a few ideas that we are sure a possible, but not to sure how it would be done.

So one of our ideas was whenever fighting a enemy in the game it would show a Percentage bar of the enemies hit points. So say that the enemy has a base hit points of 20. We are trying to figure how we can make a dynamic bar that would take the percentage of the enemy hits points, and as the player takes away his hit points the bar would go down. Like whenever the enemy is fully maxed in hit points it would be totally green. As the enemy gets hit the bar every time you refresh the page would go down a percentage of the bar and then bar would turn red little bit by little bit. I've already figured out how we can have it turn from red to green, but my question is how can we figure out a percentage and have it take away slowly but surely?

Any ideas on this would be great. Suggestions are welcomed as well.

Thanks,
Jon W

• Have 1 image that represents 1% and add to it with every percent??

That could work....

• Not to sure if that would work. Can you give me a better example?

• Make a page named graph.php:
PHP Code:
``` <?php      // returns a PNG graph from the \$_GET['per'] variable      \$per = imagecreate(302,7);      \$background = imagecolorallocate(\$per, 0xFF, 0xFF, 0xFF);      \$foreground = imagecolorallocate(\$per, 0x00, 0x8A, 0x01);      \$border = imagecolorallocate(\$per, 0x99, 0x99, 0x99);      if (\$_GET['per'] > 0)      {          \$grad = imagecreatefrompng("images/grad.png");          \$per2 = imagecopy(\$per, \$grad, 1, 1, 0, 0, (\$_GET['per'] * 3), 5);          imagerectangle(\$per, 0, 0, 301, 6, \$border);      }      header("Content-type: image/png");      imagepng(\$per, NULL, 5);  ?> ```
Call the page using:

PHP Code:
``` <?php echo '<img src="/graph.php?per='.\$your_percentage_variable.'" />'; ?> ```

• It will return something like:

•

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•