character jump

This is a discussion on character jump within the Game Programming forums, part of the General Programming Boards category; hi all! know a good way to jump the character when a key is hit. i'm trying to make a ...

  1. #1
    Registered User
    Join Date
    Dec 2001
    Posts
    479

    character jump

    hi all!

    know a good way to jump the character
    when a key is hit. i'm trying to make a
    super-mario clone.
    i'm making this in allegro.

  2. #2
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    I've never used allegro, personally, but here's how you'd do it with just about any API -- Use vectors for velocity and acceleration, come up with some constant for gravity (9.8 m/sec is about earth's gravity), then when the player jumps add an arbitrary amount to his velocity vector in his jump direction (usually straight up), then everytime you update your scene, subtract from the y value of the velocity vector (assuming gravity is straight down) the amount of time passed times the gravity constant you created.

  3. #3
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    how would i make the character first go
    up then back down?

  4. #4
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    Actually, gravity is 9.8 meters a second per second.

    You don't need vectors. The simplist way would be just to have a velocity variable, you could use int float or double to store this. Have a constant value defined on how much gravity effects this variable, and initial velocity. When the player presses the jump button, make the velocity variable equal the initial velocity. Everytime you update the player's movement add the velocity variable to the y value of the player. Make sure initial value is a positive number. Then subtract the gravity from the velocity over and over.

    To sum it up: have a variable hold velocity, change character's y value according to the variable, then subtract gravity from velocity.

  5. #5
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Vectors make it easier -- you don't always have motion in a single direction -- jumping while moving for instance isn't a direct upward jump -- with vectors you can just add to the y component of the vector to get the new vector.

  6. #6
    Registered User
    Join Date
    Dec 2001
    Posts
    479
    THAT WAS EASY as %&%/(/)#"

    you just need to -- its value while the
    character isnt touching ground
    then just ++ it when hit key!

    simple as that!!!?
    i cant believe it i didnt figure this out in the first place.
    anyway guys thanks alot for your replies
    so now i need velocity, btw can u explain how velocity works?? i got no idea
    thanks again.

  7. #7
    Banned frenchfry164's Avatar
    Join Date
    Oct 2001
    Posts
    1,552
    dude, it doesn't restrict your x movement. You can still change your character's x value.

  8. #8
    Programming Sex-God Polymorphic OOP's Avatar
    Join Date
    Nov 2002
    Posts
    1,078
    Actually, gravity is 9.8 meters a second per second.
    Yeah, thanks for the correction. I actually was gonna look up the ascii character for a to put after the sec when I finished the post, but I forgot to by the time I finished.

    dude, it doesn't restrict your x movement. You can still change your character's x value.
    Well then you do have an x velocity and a y velocity -- you're just not storing it in one data structure. Velocity with x and y direction makes a vector, that's why most people store it as one.

    so now i need velocity, btw can u explain how velocity works?? i got no idea
    thanks again.
    Velocity is your rate of movement -- similar to speed but can have direction.
    Last edited by Polymorphic OOP; 12-31-2002 at 06:32 AM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Character literals incorrectly interpreted
    By DL1 in forum C Programming
    Replies: 11
    Last Post: 04-05-2009, 05:35 PM
  2. Using a character array in a switch question.
    By bajanElf in forum C Programming
    Replies: 10
    Last Post: 11-08-2008, 07:06 AM
  3. LoadFromFile() from a txt
    By Snoopy104 in forum C++ Programming
    Replies: 6
    Last Post: 03-14-2006, 09:05 AM
  4. Any help would be appreciated.....
    By SprinterSteve in forum C Programming
    Replies: 6
    Last Post: 05-01-2003, 09:25 AM
  5. Replies: 12
    Last Post: 01-12-2002, 08:57 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21