Prog jump

Advice on general approaches or feasibility and discussions about game design

Prog jump

Postby Maxime84 » 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
Maxime84
 
Posts: 2
Joined: Sun Sep 20, 2015 10:00 am

Re: Prog jump

Postby adekto » Tue Sep 29, 2015 11:27 am

you have to work with a velocity

somthing along the lines like this
Code: Select all
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
User avatar
adekto
 
Posts: 448
Joined: Tue Feb 25, 2014 9:47 pm
Location: belgium

Re: Prog jump

Postby Maxime84 » Fri Oct 02, 2015 6:46 pm

Thanks à lot !!!!!
Maxime84
 
Posts: 2
Joined: Sun Sep 20, 2015 10:00 am


Return to Project Guidance & Game development

Who is online

Users browsing this forum: No registered users and 19 guests

cron