Making a frog jump...

Started by
19 comments, last by compfanatic 23 years, 9 months ago
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
I looooove programming! Even at my young age.
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
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

Thanks!

Completely different from what I thought, but thanks!

I am 13, of course I haven''t had physics.

-Alex
I looooove programming! Even at my young age.
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

I finally tried it, but the frog only goes up, not down. Could you please tell me the solution to this?

THanks!
-Alex
I looooove programming! Even at my young age.
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

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
I looooove programming! Even at my young age.
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
My HomepageSome shoot to kill, others shoot to mame. I say clear the chamber and let the lord decide. - Reno 911
I know I need to do that, but I don''t know HOW to do that.

-Alex
I looooove programming! Even at my young age.

This topic is closed to new replies.

Advertisement