Welcome to Dream.In.Code
Getting PHP Help is Easy!

Join 109,722 PHP Programmers for FREE! Ask your question and get quick answers from experts. There are 1,902 online right now! We've got more than 500 tutorials and 2,000 snippets. Join and find out why Dream.In.Code is the #1 programming help community on the internet! Registration is fast and FREE... Join Now!



PHP BBORPG help :)

 
Reply to this topicStart new topic

PHP BBORPG help :), Coding a health bar in PHP?!?!

rpghero
post 30 Apr, 2008 - 09:06 AM
Post #1


New D.I.C Head

*
Joined: 30 Apr, 2008
Posts: 1

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 sad.gif

so im seeking your help smile.gif

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 smile.gif

thanks so much


rpghero

This post has been edited by rpghero: 30 Apr, 2008 - 09:07 AM
User is offlineProfile CardPM

Go to the top of the page


Martyr2
post 30 Apr, 2008 - 09:17 AM
Post #2


Programming Theoretician

Group Icon
Joined: 18 Apr, 2007
Posts: 4,365



Thanked 84 times

Expert In: C/C++, Java, VB, VB.NET, C#, PHP, Web Development, HTML & CSS, Javascript

My Contributions


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? smile.gif

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 Apr, 2008 - 09:19 AM
User is offlineProfile CardPM

Go to the top of the page

girasquid
post 30 Apr, 2008 - 09:24 AM
Post #3


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 1,157



Thanked 6 times

Dream Kudos: 625
My Contributions


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.
User is offlineProfile CardPM

Go to the top of the page

ultimatenet
post 6 May, 2008 - 12:36 PM
Post #4


New D.I.C Head

*
Joined: 14 Apr, 2008
Posts: 13


My Contributions


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.
CODE
.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.
User is offlineProfile CardPM

Go to the top of the page

JBrace1990
post 6 May, 2008 - 05:23 PM
Post #5


D.I.C Regular

Group Icon
Joined: 9 Mar, 2008
Posts: 427



Thanked 19 times

Dream Kudos: 350
My Contributions


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.bladesedge.net/RPG/images/MP.php?length=150

CODE
<?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);
      
      
?>
User is offlineProfile CardPM

Go to the top of the page

Fast ReplyReply to this topicStart new topic
Time is now: 9/8/08 09:42AM

Live PHP Help!

PHP Tutorials

Reference Sheets

PHP Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month