Thread: health...

  1. #1
    Registered User
    Join Date
    Nov 2005
    Posts
    34

    health...

    im trying to make a fighting game where u take in turns to do stuff..

    if i make it...

    int health = 100;
    int ohealth = 100;

    how do i get it to show the health all the way through the fight? cuz i know how to reduct of the 100 just need the code to show the health all the way through.

    im new so if this is all wrong im sorry.

    let me know, thanks reece.

  2. #2
    Registered User
    Join Date
    Sep 2003
    Posts
    34
    Well all you'd have to do is have it reprint the amount of health whenever it's changed. So if your enemy attacks and does damage then you would print the new value of 'health'. I'm not sure if that's what you're looking for or not, if not then I guess try to be a little more detailed.
    -gunder

    if (problem)
    postcount++;

  3. #3
    the Great ElastoManiac's Avatar
    Join Date
    Nov 2005
    Location
    Republika Srpska - Balkan
    Posts
    377
    Are you doing this in dos, 'cause if you are:
    - you must create the main loop
    - you must clear the screen at the end of loop
    so you could write your health like this:
    Code:
    for(int i = 0; i < heath; i++)
    {
          cout<<"|";
    }
    lu lu lu I've got some apples lu lu lu You've got some too lu lu lu Let's make some applesauce Take off our clothes and lu lu lu

  4. #4
    Registered User VirtualAce's Avatar
    Join Date
    Aug 2001
    Posts
    9,607
    Well this is quite simple really.

    First turn the health value into a percentage of the total.

    Code:
    float fHealthCoef=(float)CurrentHealth/(float)TotalHealth;
    Now take this value and multiply it by the vertical height or horizontal width of your health meter.

    Code:
    float fHealthBarSize=fHealthBarGaugeSize*fHealthCoef;
    Now find the starting x,y and add fBarSize to the correct component.

    This would be for a horizontal gauge
    Code:
    float fHealthBarRight=(float)HealthBarGaugeLeft+fHealthBarSize;
    ..convert to integer and draw bar here
    This is akin to a progress bar control in win32 programming. That stupid bar that comes up when you are installing programs that tells you how much is left to install(if you are pessimistic) or how much has been installed (if you are optimistic).
    Last edited by VirtualAce; 12-03-2005 at 04:09 AM.

  5. #5
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    While clearing the screen seems like a good way to do this, take note at how successful things like MUDs have become where they display a bar of health, mana, stamina... or whatever else is important with every move.

    Code:
    HP: 100 | MP: 45 | MM: 88 > North
    - You enter the great plains.
    
    HP: 100 | MP: 45 | MM: 87 >
    You don't need great graphics to make a good game. I wouldn't even think of doing a health bar unless I was doing a graphical program as Bubba appears to be suggesting. Then a meter would be slick and professional looking.
    Sent from my iPadŽ

  6. #6
    Registered User
    Join Date
    Nov 2005
    Posts
    34
    what i want is like..

    top of the program says HP or Health = 100...

    whenever i get hit, the health goes down depending on how hard u get hit but i dont wait it to print somewhere else...

    like health = 100

    You get kicked - hard

    and the health stays where it is on the screen but goes to 94...

    you get headbutted - very hard

    goes from 94 to 84.. etc... whats the easiest way to do this?

  7. #7
    Devil's Advocate SlyMaelstrom's Avatar
    Join Date
    May 2004
    Location
    Out of scope
    Posts
    4,079
    Easiest or most portable?

    Look into the gotoxy() function in conio.h or windows.h. It's really not the best function to use if you want portability though.
    Sent from my iPadŽ

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Little Game
    By cjwenigma in forum C++ Programming
    Replies: 9
    Last Post: 11-07-2007, 12:50 PM
  2. Health...
    By Hugo716 in forum C++ Programming
    Replies: 17
    Last Post: 05-18-2006, 04:46 PM
  3. Help With Health in Games
    By Mustang5670 in forum Game Programming
    Replies: 8
    Last Post: 01-04-2004, 04:43 PM
  4. AOL And your health
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 02-09-2003, 09:51 AM
  5. Health Bar demo
    By jdinger in forum Game Programming
    Replies: 7
    Last Post: 04-12-2002, 12:27 PM