Thread: increasing players life

  1. #1
    Registered User
    Join Date
    Aug 2001
    Posts
    380

    increasing players life

    In my game I would like it so that every 1000pts the players life increases by one.

    if((player.score % 1000) == 0))
    player.life++;

    Would this be the correct way to write the condition?

    Also, how do I make it so that the player's life only increases when they do have a 1000pts? And not to have their lives continue to increase until
    their score changes.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  2. #2
    Registered User sean345's Avatar
    Join Date
    Mar 2002
    Posts
    346
    I believe you just want to do this:
    Code:
    PlayerLife = PlayerLife + (Points/1000)
    - Sean
    If cities were built like software is built, the first woodpecker to come along would level civilization.
    Black Frog Studios

  3. #3
    Registered User Nutshell's Avatar
    Join Date
    Jan 2002
    Posts
    1,020
    Another way to do it is to set a counter, when the counter reaches 1000 add 1 to the life and reset the counter. But that would be pretti much a waste of mem.

    Oh sean clever stuff...

  4. #4
    Rambling Man
    Join Date
    Jan 2002
    Posts
    1,050
    or even better yet

    Code:
    PlayerLife += Points/1000
    how's that for being clever

  5. #5
    Registered User
    Join Date
    Aug 2001
    Posts
    380
    Code:
    int score 1000;
    lives = 3;
    while(1)
    {
    	getInput();
    		if((score % 1000) == 0)
    		lives++;
    	score++;
    }
    You code would work, but all I want to do is keep the score the same and just add to lives. And about the other problem is that if the score is 1000 and there is no input or change, lives continues to increase which I don't want to happen either.

    Hope this makes things more clear.
    Don't you dare hit me on the head, you know I'm not normal.
    A Stooge Site
    Green Frog Software

  6. #6
    Confused Magos's Avatar
    Join Date
    Sep 2001
    Location
    Sweden
    Posts
    3,145
    Simple, use another variable to keep track on how much score you need to get an extra life, then increase it by 1000 when getting a life.
    Code:
    int Life = 3;
    int Score = 0;
    int ScoreToGetLife = 1000;
    
    void CheckForExtraLife()
    {
       if(Score >= ScoreToGetLife)
       {
          Life++;
          ScoreToGetLife += 1000;
       }
    }
    <edit>
    If there is something in your game that gives more than 1000 points, you can change the if to a while, so you gain all lives at once instead one per time the function runs.
    </edit>
    Last edited by Magos; 10-20-2002 at 04:55 AM.
    MagosX.com

    Give a man a fish and you feed him for a day.
    Teach a man to fish and you feed him for a lifetime.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Artificial Life: Where to Start?
    By Mr.Sellars in forum General AI Programming
    Replies: 11
    Last Post: 09-22-2007, 02:03 AM
  2. Personal Program that is making me go wtf?
    By Submeg in forum C Programming
    Replies: 20
    Last Post: 06-27-2006, 12:13 AM
  3. Game of life
    By JoshR in forum C++ Programming
    Replies: 30
    Last Post: 04-03-2005, 02:17 PM
  4. The Meaning of Life: A Trick Question?
    By chix/w/guns in forum A Brief History of Cprogramming.com
    Replies: 14
    Last Post: 07-12-2004, 07:53 PM
  5. Life, The Universe, and everything else
    By ZooTrigger1191 in forum A Brief History of Cprogramming.com
    Replies: 7
    Last Post: 03-29-2003, 05:33 PM