Switch to full style
Advice on general approaches or feasibility and discussions about game design
Post a reply

Prog jump

Sun Sep 20, 2015 10:05 am

Hi everyone i would like a bit of help !

Well, i want to creat e a game like a doodle jump style, but my main problem is the jump function !
I've tried with for loop but i think i goes to fast. It only make a big vertical line in the middle of the screen !

Please give me an example code of that !!!!

Cause i've searched and find nothing on the net, this could help me for other games wich would need some jump !

Thanks

Re: Prog jump

Tue Sep 29, 2015 11:27 am

you have to work with a velocity

somthing along the lines like this
Code:
float positionX, positionY;     // Position of the character
float velocityX, velocityY;     // Velocity of the character
float gravity = 0.5f;           // How strong is gravity

void loop() {
  if(gb.update()){
    positionX += velocityX;      // Apply horizontal velocity to X position
    positionY += velocityY;      // Apply vertical velocity to X position
    velocityY += gravity;        // Apply gravity to vertical velocity
  }
  if(gb.buttons.released(BTN_A)) velocityY = -12.0f; //add vertical velocity
}

this is not considering any colision detection, but it wil help you out for the most part

P.S the for loop you did happens every frame

Re: Prog jump

Fri Oct 02, 2015 6:46 pm

Thanks à lot !!!!!
Post a reply