Help With Health in Games

This is a discussion on Help With Health in Games within the Game Programming forums, part of the General Programming Boards category; Hey, I'm writing a Game in C that is text based. I've written almost the complete game, but it isn't ...

  1. #1
    Registered User Mustang5670's Avatar
    Join Date
    Dec 2003
    Posts
    53

    Talking Help With Health in Games

    Hey, I'm writing a Game in C that is text based. I've written almost the complete game, but it isn't going to be fully complete unless I have a way for my Character to die.

    I've looked through several books and I just can't find out how to answer my question, so I turned to here.

    My question is:

    How do I add a "health system" to my game. that deals with just numbers. Kinda like an RPG, when My character gets into battle..i need for the "bad" guy to generate a hit and take off a random amount of health..

    Do i need to set a global HEALTH variable and add a few while loops or what? .

    Please Help.
    Which 'a Huh?

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,422
    Code:
    player.health -= rand() % enemy.strength;
    if ( player.heath <= 0 ) {
       requiem( player, "he was a valiant warrior" );
    }
    Subtract from the player's health, some random value based on the strength on the enemy. A stronger enemy can therefore do more damage.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Registered User Mustang5670's Avatar
    Join Date
    Dec 2003
    Posts
    53
    Thanks alot ..I'll try it
    Which 'a Huh?

  4. #4
    Registered User Mustang5670's Avatar
    Join Date
    Dec 2003
    Posts
    53
    Thanks alot ..I'll try it
    Which 'a Huh?

  5. #5
    Gronkulator of Surds littleweseth's Avatar
    Join Date
    Oct 2003
    Posts
    68
    If you have a game loop (problably) , do what salem said, then make a function that checks if the characters health is 0 or less (dead) and inline it. Then, if it returns true, do something.

    since im bored and its chrissie....

    Code:
    (game loop....)
    for (;;)
        {
        Some Stuff
        Some Stuff
        if ( CharacterDead () )
            {
             cout << "hello world!"
            }
         yadda yaa....
        }
    
    inline bool CharacterDead ()
    {
        if ( Character is dead..... )
            { return true; }
       else 
            { return false }
    }
    Ph33r the sphericalCUBE

  6. #6
    Registered User
    Join Date
    Dec 2002
    Posts
    221
    i have a question
    why inline?

  7. #7
    Registered User Mustang5670's Avatar
    Join Date
    Dec 2003
    Posts
    53

    Thumbs up

    Thanks I got it..game is working great..I've posted just the first little tiny section on the game submit thing on this message board. Its the game small world..its sucks right now..cause its just beta and no where near finished..it will have more and better features.

    Thanks for all your help!
    Which 'a Huh?

  8. #8
    *******argv[] - hu? darksaidin's Avatar
    Join Date
    Jul 2003
    Posts
    314
    It is supposed to be faster though in this case I would say it does not matter a cent if you inline it or not.
    [code]

    your code here....

    [/code]

  9. #9
    Gronkulator of Surds littleweseth's Avatar
    Join Date
    Oct 2003
    Posts
    68

    inlining?

    Well, what i do if a function gets really huge ( over a screen ) is break parts of it off into inline voids (or ints or whatever) and put them directly after the other function. Is this good practice, or shocking? Maybe i should do some planning so i dont end up with such huge functions

    Maybe i should pull myself away from ut2003 long enough so i can do some art and programming.... but there's some powerful magnets in there somewhere... instagib, anyone?
    Ph33r the sphericalCUBE

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. When done right, PC games are amazing
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 6
    Last Post: 08-13-2008, 05:32 PM
  2. Violent video games?
    By VirtualAce in forum A Brief History of Cprogramming.com
    Replies: 58
    Last Post: 04-26-2006, 01:43 PM
  3. Video Games Industry. 5 years left.
    By Cheeze-It in forum A Brief History of Cprogramming.com
    Replies: 26
    Last Post: 12-10-2002, 09:52 PM
  4. Health Bar demo
    By jdinger in forum Game Programming
    Replies: 7
    Last Post: 04-12-2002, 12:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21