PHP BBORPG help :)

Coding a health bar in PHP?!?!

Page 1 of 1

4 Replies - 3076 Views - Last Post: 06 May 2008 - 05:23 PM Rate Topic: -----

#1 rpghero  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 30-April 08

PHP BBORPG help :)

Posted 30 April 2008 - 09:06 AM

Hello

I have been learning PHP for nearly 2 years now, still having great fun i might add!!

i would consider myself inbetween beginner and intermediate at the present.

im coding this game on my own, i did plan to do this with a friend but hes to busy at the moment :(

so im seeking your help :)

one section of my game, there is a turn based system, were you can challenge bosses, that are pre coded, its going well at the moment, but i dont know how to create a health bar system thats effective in PHP.

can anyone help?


also any useful tips for example secruity and etc would be fantastic :)

thanks so much


rpghero

This post has been edited by rpghero: 30 April 2008 - 09:07 AM


Is This A Good Question/Topic? 0
  • +

Replies To: PHP BBORPG help :)

#2 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4333
  • View blog
  • Posts: 12,128
  • Joined: 18-April 07

Re: PHP BBORPG help :)

Posted 30 April 2008 - 09:17 AM

Well health bars as you know are typically designed to be updated as the action happens in real time. Or in the case of turn based battle updated whenever damage is dealt or healing is to begin. It depends primarily on the way you have setup the boss scenario. If you are using standard page refreshes to "attack" and hit a submit button, you would then update the boss health bar according to its success, have your boss deal damage to your character and depending on its success, update your health stats, then render the page back to the user to show both attack results.

In a PHP game like this you just need to have the health bar visually show the user where they stand in health. Typically it will be the amount of life left of the available life given.

Your character has 100 health points and your boss has 300. Your bar would be drawn to represent 100% or a full bar. Same with the boss. You press attack, the page goes to the server where it is calculated that you did 50 fire damage and 20 lightning damage. In turn the boss did a crushing blow and knocked out 30 health on you. So now your health is 70 and the boss is 250. Battle damage is assigned to stats in a database or whatever, then PHP will read the database and draw a bar that is 70% filled. This means if the bar was 100px wide, the bar should now be 70px wide. Your boss should have about 83% of their bar filled or 83px wide. The page is then shown back to the user with the 70px and 83px wide health bars.

Understand? :)

Edit: This could also be implemented with AJAX to give you more real life health bar action. It is up to you how that works. Just thought I would throw that in to let you know.

This post has been edited by Martyr2: 30 April 2008 - 09:19 AM

Was This Post Helpful? 0
  • +
  • -

#3 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: PHP BBORPG help :)

Posted 30 April 2008 - 09:24 AM

For a health bar, why not try something using CSS? Have a div that's your health bar's background and is a set width - like 200px or something. Then have one overtop of it that's red(or whatever your health color is) and just modify the width of it based on the percentage of their health.

When it comes to security, are you protected against cross site scripting, and SQL injection? Those are both things you should be careful about.
Was This Post Helpful? 0
  • +
  • -

#4 ultimatenet  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 13
  • Joined: 14-April 08

Re: PHP BBORPG help :)

Posted 06 May 2008 - 12:36 PM

I have a Fully coded PHP RPG game site called Ultimate City The Game
feel free to sign up and ask me for tips.On other subjests
You will first need to enable cron or setup a cron system.I use CPANEL to satup crons and manege my site.
Here is the css.
The First one the one which shows the players health out of 100.The second one shows the decreased part of a players health.
.bar_aenergy{

width:100px;

border: 1px solid: #FFFFFF;

background-color: #C80000;

}

.bar_benergy{

font-size: 4px;

background-color: #326432;

}


You can change the color if you like.
It would be helpful if you put on a link to my site on yor index page and i will put a link to your site.
Was This Post Helpful? 0
  • +
  • -

#5 JBrace1990  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 110
  • View blog
  • Posts: 760
  • Joined: 09-March 08

Re: PHP BBORPG help :)

Posted 06 May 2008 - 05:23 PM

it would be better (possibly) to use the GD library if it's supported.... this is one I use, and you can see here: http://jbrace.blades....php?length=150

<?php
	  header ("Content-type: image/jpeg");
	  $length = $_GET['length'];
	  $length = $length + 3;
	  $im = imagecreate(206,15);
			$color = imagecolorallocate($im,0,0,0);	
			$color2 = imagecolorallocate($im,30,144,255);
/* makes sure the rectangle for the HP isn't larger then the rectangle size */
			if($length > '3' && $length <= '203'){ 
	  imagefilledrectangle($im,3,3,$length,12,$color2);
			}
	  imagejpeg($im); 
	  
	  
?>

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1