Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top


Input input = gc.getInput();
            int xpos = Mouse.getX();
            int ypos = Mouse.getY();
            emu = "Enemy Life : " + enemyLife; 
            Life = "Your Life Is" + life;
            Mousepos = "X:" + xpos + "Y:" + ypos;
            test1 = "Test INT" + test1int;
                       //if this button is press, the damage will add up. When 
                        //pressed fight, it would start reducing the enemy health.

                test1int += 1;

            if((xpos>1007 &xpos<1297)&&(ypos>881 && ypos<971))
                            //Fight button
                  //fight has started
                         //this would reduce the enemy life
                           //PROBLEM: Does not stop reducing! 

                           //the below code was not successful. It did not stop it //         from reducing further.

QUESTION: Ok now, this is what is does. When I press the key, 1, it adds up the damage to the enemy. When I press fight, It will then start to reduce the enemy's health. Now my problem is, it kept on reducing and deducting it until negative! How do I deduct it to my desired damage (My desired damage is the one when press key 1)?

share|improve this question

closed as too localized by Jari Komppa, doppelgreener, bummzack, Byte56, Nicol Bolas Sep 28 '12 at 15:27

This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center.If this question can be reworded to fit the rules in the help center, please edit the question.

-1 This is not a question about game development, but about a basic programming problem. – Markus von Broady Sep 28 '12 at 11:17
SystemNetworks. You really, really need to read the FAQ about what kinds of questions to ask here. I've told you this a few times, and you're still posting these localized-asking-for-code questions. That's not what this site is about. Please read and understand the FAQ. – Byte56 Sep 28 '12 at 14:49

Just make a global field that records the damage to be dealt (the value obtained when pressing one), then when you press left, before decrementing the life, deduct the amount to decrement it with from the damage to be dealt value and check if that damage to be dealt value is still positive. When it becomes negative that means you've dealt enough damage and you should stop.

share|improve this answer
can you give me a code at least? I don't understand – SystemNetworks Sep 28 '12 at 12:10

Your will stop decrementing enemyLife when the floodControl1 is set to true right?

And you do:


test1int is incremented when you press the key 1. I can't see how you initialize the test1int variable in your code but assuming the following:

  • test1int = 0
  • I press the key 1 less than 10 times (so the value of test1int will be lower than 10)
  • I press the left click of the mouse

You will never stop decreasing your enemyLife variable since test1int < 10.

Here is a more natural way to do what you want:

if (floodControl1==false) {
    if (enemyLife - test1int < 0) { //check if reducing the enemyLife will not make it negative
        //stop decreasing
        enemyLife = 0;
        floodControl1 = true;
    } else {
        //continue decreasing
        enemyLife -= test1int;
share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.