Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 03-14-2009, 10:33 PM   PM User | #1
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
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
Jon W is offline   Reply With Quote
Old 03-14-2009, 11:03 PM   PM User | #2
sea4me
Regular Coder

 
sea4me's Avatar
 
Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 27 Times in 26 Posts
sea4me is an unknown quantity at this point
Have 1 image that represents 1% and add to it with every percent??

That could work....
__________________
sea4me is offline   Reply With Quote
Old 03-14-2009, 11:24 PM   PM User | #3
Jon W
Regular Coder

 
Join Date: Jan 2008
Posts: 334
Thanks: 9
Thanked 0 Times in 0 Posts
Jon W is an unknown quantity at this point
Not to sure if that would work. Can you give me a better example?
Jon W is offline   Reply With Quote
Old 03-15-2009, 01:00 AM   PM User | #4
sea4me
Regular Coder

 
sea4me's Avatar
 
Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 27 Times in 26 Posts
sea4me is an unknown quantity at this point
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.'" />';
?>
__________________
sea4me is offline   Reply With Quote
Old 03-15-2009, 01:01 AM   PM User | #5
sea4me
Regular Coder

 
sea4me's Avatar
 
Join Date: Jan 2009
Location: Damn, I don't know...
Posts: 389
Thanks: 11
Thanked 27 Times in 26 Posts
sea4me is an unknown quantity at this point
It will return something like:

__________________
sea4me is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:35 AM.


Advertisement
Log in to turn off these ads.