Jump to content

  • Log In with Google      Sign In   
  • Create Account

We're offering banner ads on our site from just $5!

1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


#ActualSHC

Posted 24 January 2013 - 07:21 AM

Let's say you would like to jump up for 3 tiles each of height 16, check this

 

int x_pos, y_pos; // Current position
boolean jump = false;

int jump_y = 0; // The position to jump

public void doFrame(){
    if (onGround()){ // Implement this method
        if (isPressed(VK_SPACE) && !jump){
            jump = true;
            jump_y = y_pos - 16*3; // 3 tiles of height 16 px
        }
    }
    if (jump){
        y_pos -= y_vel;    // Move the character up
        if (y_pos <= jump_y){
            jump = false;
        }
    } else {
        // Apply gravity
        y_pos += y_vel;
    }

}

 

 

Hope this code helps.


#1SHC

Posted 24 January 2013 - 07:21 AM

Let's say you would like to jump up for 3 tiles each of size 16, check this

 

int x_pos, y_pos; // Current position
boolean jump = false;

int jump_y = 0; // The position to jump

public void doFrame(){
    if (onGround()){ // Implement this method
        if (isPressed(VK_SPACE) && !jump){
            jump = true;
            jump_y = y_pos - 16*3; // 3 tiles of height 16 px
        }
    }
    if (jump){
        y_pos -= y_vel;    // Move the character up
        if (y_pos <= jump_y){
            jump = false;
        }
    } else {
        // Apply gravity
        y_pos += y_vel;
    }

}

 

 

Hope this code helps.


PARTNERS