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

Thread: Percentage Bar

  1. #1
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts

    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

  • #2
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Have 1 image that represents 1% and add to it with every percent??

    That could work....

  • #3
    Regular Coder
    Join Date
    Jan 2008
    Posts
    334
    Thanks
    9
    Thanked 0 Times in 0 Posts
    Not to sure if that would work. Can you give me a better example?

  • #4
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    Make a page named graph.php:
    PHP Code:
    <?php 
        
    // returns a PNG graph from the $_GET['per'] variable 
        
    $per imagecreate(302,7); 
        
    $background imagecolorallocate($per0xFF0xFF0xFF); 
        
    $foreground imagecolorallocate($per0x000x8A0x01); 
        
    $border imagecolorallocate($per0x990x990x99); 
        if (
    $_GET['per'] > 0
        { 
            
    $grad imagecreatefrompng("images/grad.png"); 
            
    $per2 imagecopy($per$grad1100, ($_GET['per'] * 3), 5); 
            
    imagerectangle($per003016$border); 
        } 
        
    header("Content-type: image/png"); 
        
    imagepng($perNULL5); 
    ?>
    Call the page using:

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

  • #5
    Regular Coder sea4me's Avatar
    Join Date
    Jan 2009
    Location
    Damn, I don't know...
    Posts
    390
    Thanks
    11
    Thanked 28 Times in 27 Posts
    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
    •