Health...

This is a discussion on Health... within the C++ Programming forums, part of the General Programming Boards category; to make a mini fighting game, how do u store health and change it? just like, it shows say, Hugo ...

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    132

    Health...

    to make a mini fighting game, how do u store health and change it?
    just like, it shows say,

    Hugo - Health 100%
    he hits kick
    and the Hugo - Health changes to 90% but it doesnt re print this text. where it says Hugo - Health - 100%, it stays there but the 100 turns to 90.

  2. #2
    C++ Enthusiast jmd15's Avatar
    Join Date
    Mar 2005
    Location
    MI
    Posts
    532
    Well it all depends on what you're using for graphics, OpenGL, basic GDI, etc. But either way I'd recommend storing it in a variable and then updating the screen so it will show the variable's new content after it's changed. Just a suggestion, don't get ahead of yourself.
    Trinity: "Neo... nobody has ever done this before."
    Neo: "That's why it's going to work."
    c9915ec6c1f3b876ddf38514adbb94f0

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,045
    You'll want to position the cursor one the screen, or (ugh) clear the whole screen and repaint the whole thing.

    See the FAQ, or try gotoxy() in <conio.h>.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

  4. #4
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    thanks for the fast replys.

    ok, well whats the easiest graphics thing to learn? basicly all i want to do it have writing thats explaining what you doin, like hugo punched david etc.. and then a picture to appear. basic JPEG image from a folder.

    yeh i thought about making a variable to hold the health in but im not too sure on how to do it... any chance you could show me a small example of a code that would work?

    also how do i refresh the whole screen?

    also once i sussed out the basic part id like to add buttons with the move name on it and when i click it, it does what it would if i typed !punch or ! kick or /punch, \kick etc...

  5. #5
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    How's your object orientation concepts? The best thing to do
    would be make yourself a very basic console app first - design
    a fighter class and have methods for different attacks and
    store health, then decrement the health for your oponent.
    Here's some pseudo-code to point you in the right direction:

    Code:
    class Fighter
    {
    private:
    	int health;
    	string name;
    	int kickstrength;
    	int punchstrength;
            
    public:
    	//cxtrs here
    
    	bool kickoponent (Fighter &oponent);
    	bool punchoponent (Fighter &oponent);
    	int GetHealth ();
    	//and so on for more detailed attacks
    };
    
    int main (void)
    {
        //Create instances of your fighters
        //menu stuff for turn select and attack choice
        //below is what player 1 kicking player 2 might look like
        
        if (Player1.kickoponent(Player2))
        {
    		cout << Player2.GetHealth ();
        }
    	
        else
        {
    		cout << "Player 1 wins" << endl;
        }
    
    	//and similarly for player 2 attacking player 1
    
    	return 0;
    }
    Get your console going first on its own, then try out loading it into
    a window and displaying basic graphics. Then all the fancy stuff
    with buttons can come along.

    As far as graphics librarys go, there is some choice, but I've seen
    people do amazing looking stuff with openGL in a very short
    period of time, so thats the only one I could recommend.
    Last edited by Richie T; 05-18-2006 at 04:04 PM.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  6. #6
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    wow thanks alot mate!

    ok ive copied it down so when i get there ill use it.

    what do u mean get the consol going first?

    ok ill try n learn OpenGL , can you learn this advanced on the internet in tutorials and stuff?

    the game i wanted to try would have like... 100's of different moves. like grab opponent and when u do that, lets say a list of 10 moves comes up and u can choose which one ud like to do, once you have chosen, it goes to ure opponents choice to choose to try to reverse it or let it hit.. etc... lol sorry its its long winded.

  7. #7
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    What i meant by console was exactly what you are talking about
    in your other post - the "DOS box". You should code your
    program so that it appears in the console - simple text menu
    indicating what options are available to the player. The user
    uses the keyboard to select an option and the program prints
    the effect of that option. This is all very basic stuff.

    In your other post, you mention that you've studied all the
    tutorials on this site. Even if you have studied them in good
    detail, very little of that will help you in relation to using the
    buttons and the mouse - the Windows API is a very strange
    beast. Keep your program simple, like the structure I've laid out,
    then build on it to intoduce more moves - and then branching
    them out as you wish. All of the attack functions will essentially
    be the same, only deducting different amounts from the oponents
    health.

    If you kept on building the program, you could have a character
    select menu, whereby you might code a generic base class
    Fighter, with all the functionality that a character needs, then
    your list of actual characters could inherit all the basic punches
    and kicks from the base, saving you time - because each derived
    class would have different values for attributes such as attack
    strengths.

    Hey all this sounds like fun, might make a basic game such as
    this myself after my exams!

    For openGL tutorials, one of my friends learned from this site,
    and was able to develop some very cool maps and stuff from
    it very rapidly.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  8. #8
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    oh i get ya lol sorry i bet i sounded so thick then.
    thanks for all the help.

    im going to look into the advanced part of Classes soon, about half way through this book so far.

    nice, thanks for the link for the graphics, ill get straight onto that after ive finished reading this E-Book i have.

    sorry to keep asking loadsa things lol.

    but im just wondering how much harder it would be to make it online.. so u can fight other people who have the program open... and have a small chat room in it aswell for people to chat. i know this is way more advanced than just knowing C++ lol but its something id like to eventualy be able to do.

    thanks for all the help mate. Oh and do u have MSN ?

    Hugo.

  9. #9
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    It would be considerably harder to make it a networked game.
    I assume that you are eventually aiming to make this a basic
    street fighter style game, with characters moving at the same
    time - then you would have to look at multi-threading. Also
    if it was online, the program would also ahave to simultaneously
    update each players screen very rapidly. The truth is that it
    is not impossible, but you would need years of experience to
    be able to wite a program of that calibre, and a lot of time if you
    were doing it on your own too! Not trying to dishearten you,
    but you need to have realistic goals, otherwise you will get very
    disappointed very quickly.

    Also, I am on MSN but I prefer not to use it - if you have a
    question, I don't mind the PM but I can't be guaranteed to be able
    to help, so it may sometimes be a better idea to post questions
    here. My advice is as always, not to give in at the first stumbling
    block with problems you encounter - perseverence pays off big
    time in developing good coding experience, but when you are
    really stuck, then you need help.

    Good luck with the game - take it slow!
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  10. #10
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    NoNoNO lol u dont understand what kind of game i mean.
    i would never dream of doing one like that, im too thick lol.

    its like... how to explain it, kind of card game but not lol.

    like this will be a bit long winded.

    u start match ( lets say wrestling \ boxing etc.. )

    it asks you to choose a fighter ( could be anyone , The rock , Triple H , Mike Tyson etc.. )

    when both players have chosen a person, it loads up that fighters health, and his moveset ( all fighters have different move sets and finishing moves \ blows ) but u cannot see each others health. maybe a condition ( Great , Good , Woozy , Very Hurt, Dead on his feet)

    u start in open play where u cant do too much, maybe, catch high, catch low, duck , punch and maybe a kick. once the person it starts with chooses, nothing happens apart from giving the opponent a choice, he can do either one of them too. now say i punch and he Catches high, He will get control. or i punch he catches low, my punch will hit and i will be in CLOSED PLAY in control. now say he got control.

    now hes in CLOSED PLAY and he has a bigger selection of moves.
    say , Grab, Behind opponent , running, these are kind of setup positions, when you choose one, a NEW moveset comes up with the actual moves you can attempt from that position. say u choose, running and then dive at opponent, then the other player then has a selection of moves that could reverse that, duck, jump out way, high kick etc.. based on either random numbers again, it could hit, or the other player may reverse it. if reversed, other play then gets CLOSED PLAY in control, if it hits, player remains in CLOSED PLAY and probably have opponent on the floor. then has a new move set to choose one from.

    when opponent health = very low, can go for the finishing blow which K.O or in wrestling, can finish and then pin.

    now each Position has 1 single JPEG appear on screen, not moving. then when he attempts a move, a NEW still image shows the move thats being performed and if it hits, can show another one of them laying down, ducking, and so on.

    really sorry its long winded but i just wanted to explain my idea.

    now do you understand?

  11. #11
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Yes i see. Well the good news is that it sounds considerably
    easier than what I thought you were working towards. Classes
    deinitely seem to be the best tool for this job - when you get
    handy with them you will see that you could store the fighter's
    current status (open/closed play), the other oponents choices
    can affect your current characters status.

    It sounds like that the only hard part of the program will be
    working out your menu structures. The program is definitely
    going to be a work in progress for a while, but all of your attack
    functions will be similar, but coding all the details of all the
    character unique data will be tedious. Sounds like a solid task
    in program design structure - the individual parts of the code
    to do the various things will be easy, but arranging it well will
    be a challenge.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  12. #12
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    ok thanks.

    yes i got the idea from a game coded in mIRC lol. but everyone can get all the source in that and maybe edit it. so C++ is safer.

    i was thinking about using seperate classes per wrestler. like

    the rock
    [stats]
    int health = 120;
    float stamina = 1.2;
    float adrenalin = 12000;

    not sure what variable the moves could be set to. could be wrong as im new in classes lol just trying to get small idea.

    [open play]
    catch high(0, 0.1);
    catch low(0, 0.1);
    punch(4, 0.3):
    kick (5, 0.5);

    etc...

    [closed]
    (set of closed moves and more positions)
    [grappling]
    [in corner]
    [opponent down]
    [opponent staggered]
    [on top rope]

    etc... and each position holds like
    punch(5, 0.3) as in 5 damage and takes away 0.3 adrenalin from you.
    kick(6, 0.6)

    and like
    finishing move(19, 11.5, 10) the last 10 adds a higher winning chance for this turn.

    if you get what i mean. ne chance you could type 1 small class example of how i could store a wrestler and the positions \ moves? even just like 5 moves for the example with the damage, adren factors.

    also a match starts at Turn 0 and goes up each time a move connects. a normal match has max number or 200 turns and then its declared a draw. not likely to last that long though.

    Hugo.

  13. #13
    The Richness... Richie T's Avatar
    Join Date
    Jan 2006
    Location
    Ireland
    Posts
    469
    Well its all a matter of design choice really. Adrenaline is a good
    idea - remember in fighting games where you have to build up
    a status bar by making powerful attatcks, and when you reach
    a high enough level, you can pull of a special move?

    Your classes are going to be of a similar form as the one I
    posted earlier, so I'll just show you an implementation of one of
    the functions in in it, whereby a player kicks another player.

    here's the class again

    Code:
    class Fighter
    {
    private:
    	int health;
    	string name;
    	int kickstrength;
    	int punchstrength;
            int adrenaline;
            
    public:
    	//cxtrs here
    
    	bool kickoponent (Fighter &oponent);
    	bool punchoponent (Fighter &oponent);
    	int GetHealth ();
    	//and so on for more detailed attacks
    };
    Now an implementation of kickoponent:

    Code:
    bool Fighter::kickoponent(Fighter &oponent)
    {
    	if (oponent.health <= kickstrength)
    	{
    		oponent.health = 0;
    		return false	//oponent is dead!
    	}
    
    	oponent.health -= kickstrength;	//performing damage of amount kickstrength
    	adrenaline += 10;	        //increasing adrenaline by some amount
    	return true;	                //player still has some health, so let main know about it
    }
    I mentioned inheritance earlier, and it is a good application of it.
    What you would do would be to write a base class with some
    very basic functionality, such as basic moves such as punches
    and kicks, methods to return the health and so on. Then
    you can create a whole bunch of classes which inherit all this
    functionality and can implement extra things such as player
    specific moves. Each class will inherit the same types of attributes
    but can have different values for those attributes - one character
    can have stronger kicks than another, but the code that executes
    a kick is the same - you only write it once!

    You should get started on implementing the above class - just
    do one class type and test it out in a program that looks like the
    pseudo-program I posted earlier.
    No No's:
    fflush (stdin); gets (); void main ();


    Goodies:
    Example of fgets (); The FAQ, C/C++ Reference


    My Gear:
    OS - Windows XP
    IDE - MS Visual C++ 2008 Express Edition


    ASCII stupid question, get a stupid ANSI

  14. #14
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    nice, thanks mate.

    how do i set health to a certain number at the start?

    thing is, i need to make the consol fight back or i dont know if its working well... :/

  15. #15
    Registered User
    Join Date
    Apr 2006
    Posts
    132
    could i

    Code:
    class Fighter
    {
    private:
    	int health;
    	string name;
    	int kickstrength;
    	int punchstrength;
            int adrenaline;
            
    public:
    	//cxtrs here
    
    	bool kickoponent (Fighter &oponent);
    	bool punchoponent (Fighter &oponent);
    	int GetHealth ();
    	//and so on for more detailed attacks
    };
    save this as a header and #include it in the main source code and it still calls the variables and does it how it should?

Page 1 of 2 12 LastLast
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, 11:50 AM
  2. health...
    By psycho88 in forum Game Programming
    Replies: 6
    Last Post: 12-04-2005, 08:37 AM
  3. Help With Health in Games
    By Mustang5670 in forum Game Programming
    Replies: 8
    Last Post: 01-04-2004, 03:43 PM
  4. AOL And your health
    By RoD in forum A Brief History of Cprogramming.com
    Replies: 24
    Last Post: 02-09-2003, 08:51 AM
  5. 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