Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: testing is player is jumping or not jumping. falling or not falling.

  1. #1
    Member
    Join Date
    Oct 2012
    Posts
    133
    Thanks
    16
    Thanked 0 Times in 0 Posts

    Default testing is player is jumping or not jumping. falling or not falling.

    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.


  2. #2
    Super Moderator jps's Avatar
    Join Date
    Jul 2012
    Posts
    2,642
    My Mood
    Daring
    Thanks
    90
    Thanked 263 Times in 232 Posts

    Default Re: testing is player is jumping or not jumping. falling or not falling.

    in my paint method iam printing different images. bc testing what is player is doing.
    You should prepare and update an image based on what the player is doing when the player does something, not when it is time to paint the screen.

    I press space bar, player jumps, image updates, speedY updates, everything changes...

    When the paint method is called, you just paint the image made earlier with a call like:
    player.drawYourself(g);
    or:
    g.drawImage(player.getImage(), player.posX, player.posY, observer);



    i need some ideas how can i test in paint method
    Any time this thought crosses your mind, remember never make decisions on what to draw while drawing. Just draw what has been prepared. Prepare what to draw as the changes are made rather than during drawing time.

Similar Threads

  1. Java automated testing tools for Unit testing
    By rameezraja in forum Member Introductions
    Replies: 2
    Last Post: April 14th, 2012, 08:51 AM
  2. Heads up! Satellite falling...
    By Sean4u in forum Totally Off Topic
    Replies: 18
    Last Post: September 23rd, 2011, 03:19 AM
  3. Frog jumping code (AP comp science help!)
    By CompScienceStudent1 in forum What's Wrong With My Code?
    Replies: 14
    Last Post: September 21st, 2011, 05:42 PM
  4. java game, both players move for player 2 but not player 1
    By ajakking789 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: August 21st, 2011, 12:52 PM
  5. Cant get my code to stop jumping
    By Mob31 in forum What's Wrong With My Code?
    Replies: 1
    Last Post: March 2nd, 2011, 07:03 AM