Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

compfanatic

Making a frog jump...

This topic is 6625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I am in the process of creating my first game, and it is a frog game. I am trying to figure out how to make the frog jump. Here is my idea, but I have not tried it, and I definitely doubt it works: if (KEY_DOWN(VK_UP)) { frog.y+=8; // have the frog increase y-coords frog.y-=8; // then have the frog''s y-coords decrease } This isn''t all of the code that would be involved in making it jump, but I would like to know how you would do it. Thanks! -Alex

Share this post


Link to post
Share on other sites
Advertisement
Have you had any physics classes ?

Jumping is all about physics........
                
#define INIT_VELOCITY 20

#define GRAVITY_FACTOR 1

#define MAX_VELOCITY_DOWN -90

#define RUN_RATE 8

#define FLOOR_HEIGHT 480 // if bottom of screen 480



if (jump key pressed)
{
playerVelocity = INIT_VELOCITY;
do{
if (key over is pressed)
{
player.x += RUN_RATE;
}
player.y -= player.velocity;
player.velocity -= GRAVITY_FACTOR;
}
while(playerHeight >= FLOORHEIGHT);
}






Edited by - ncsu121978 on June 14, 2000 5:10:44 PM

Share this post


Link to post
Share on other sites
now instead of doing to do while loop like a have it in the above example, for a game you would do it like this

if the jump key is pressed then set the player velocity to the initvelocity like i have it

then in the update fram loop of your game


if (playerHeight > FLOORHEIGHT)
{
player.y -= player.velocity;
player.velocity -= GRAVITY_FACTOR;
}




"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
if you increase then init_velocity then he will jump higher and jump up faster

if you increase the gravity factor he will jump lower and fall faster

this two values work hand in hand so you can mess with both of them until you reach the jump height and jump speed you want

"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
Do you mean that he jumps in the air but then not back down ?
If that is the case then make sure you have all your signs right (all the pluses and minus)..........it should work fine......as long as when you
#define FLOOR_HEIGHT 480

if 480 is at the bottom of your screen ?
answer me some questions
what compiler are you using ?
what language ?
what graphics library ?


"Now go away or I shall taunt you a second time"
- Monty Python and the Holy Grail
themGames Productions

Share this post


Link to post
Share on other sites
Ok, I am using Visual Studio 5, DirectX, C++. The bottom of my screen IS 480. I noticed that you defined MAX_VELOCITY_DOWN but did not use it, and when you say "player.velocity," which velocity are you talking about? y-velocity, or x-velociy?

Thanks Again!!!
-Alex

Share this post


Link to post
Share on other sites
Why don't you try using a sine wave. Then when his y position is < or = to the minumum value you stop the jump.
    
frog_state=JUMP;
if(frog_x<min)
frog_state=WALK;

or something like that.

Edited by - Julio on June 15, 2000 3:15:12 PM

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!