i want to how when is my player is jumping, statding, or falling. for some reason it only goes in fall == true if statment.
in my paint method iam printing different images. bc testing what is player is doing.

i have main_class and player_class.

    //in player class
    public void paint(Graphics g)
      {
        if(jump == false)
        {
          //..print stand image
         }
       else if(jump == true)
       {
        //..print jump image
       }
       else if(fall == true)
       {
        //print fall image here
       }



-------------------------------------------------------------------------------------------------------------
boolean jump = false;  
boolean fall = true;       //bc when game start player will fall down first
private double dy = 6.0;  //change in y over time
    private double gravity = 0.2;    

in main method i keypress method. if i presss up key it will run hitJump() method from player_class

public void keyPressed(KeyEvent e)
    {
        int keys = e.getKeyCode();
                 if (keys == KeyEvent.VK_UP)
        {
          player_class.hitJUMP(ground_class);
        }

//in player_class seting up hitJump method. this just set jump to true only if only is not jumping.
public void hitJUMP(Ground g)
{
    if(jump == false)//if on ground 
    { 
        jump = true; //go in jump true if statment
        dy = 6.0;   //reset 
    } 
}


//than also in player_class iam creating so my player will go up and down 
//this method is in while loop. so it will keep on going.
public void PLAYER_MOVE(Main m, Ground g) //player move's
 {
    if(jump == true) //move dy up ..and than down..
    {   
          dy -= gravity; 
          y -= dy;       

          if(y + height >= g.getY()) //if on ground set jump to false
        {
            jump = false; 
                    fall = false;
        }
    }
    else if(jump == false) //if player is not jumping so that mean player is falling
     {
        y += 4; //player falling speed
    fall = true;
      }
}

mostly i need help in paint method and player_move method. i know how to test when is my player is jumping or not jumping. but falling part is confusing to me. i need some ideas how can i test in paint method and player_move method when is my player is falling or not.

Edited 4 Years Ago by Dani: Formatting fixed

What are the possible combination of values of the variables you are testing in the paint method? With the chained if/else if statements the first one that is true is the only one that will be executed.
Is that what you intend?

BTW if(jump) is sufficient. You don't need == true: if(jump == true)

Edited 4 Years Ago by NormR1

This article has been dead for over six months. Start a new discussion instead.