This site requires JavaScript, please enable it in your browser!
Greenfoot back
JackVolp5
JackVolp5 wrote ...

2019/1/13

Health is not going down.

JackVolp5 JackVolp5

2019/1/13

#
public void hitDetection()
    {
         Actor b = getOneIntersectingObject(player2.class);  
      
         if(b != null)  
         {  
             System.out.println("player 2 Hit");
             healthP2--;
             System.out.println(healthP2);             
             getWorld().removeObject(this);
         }
    }
This is the hit detection method for my bullet class. Unfortunately, it does not subtract one integer from my health variable when my player2 actor is hit. It only subtracts after the first hit and does not subtract everytime my player2 class is hit like I want it to. I am a very inexperienced programmer, so bear with me. Thanks for your help in advance. After shooting my player2 actor seven times my terminal window looks like this: player 2 Hit 99 player 2 Hit 99 player 2 Hit 99 player 2 Hit 99 player 2 Hit 99 player 2 Hit 99 player 2 Hit 99
danpost danpost

2019/1/13

#
Is it your bullet or your player that has health? Why is healthP2 in the class of your bullet? As is, each bullet created will get a playerP2 field assigned a value of 100 and when a bullet hits a player, it decreases it to 99 and the bullet is disposed of (along with its playerP2 field).
You need to login to post a reply.