Making my sprites jump
Author |
Message |
rcbhs
|
Posted: Fri Dec 21, 2007 5:25 pm Post subject: Making my sprites jump |
|
|
Ok so I am not good at all with for loops and I need to make my sprite jump diagonally when I press space (space because he will need to use up to climb ladders eventually). Anyways, I am awful with for loops but I do know that I need to use one for jumping. I honestly don't even know where to start with this one, so if somebody wouldn't mind teaching me how to do this or at least getting me started, that'd be awesome. Thanks in advance. |
|
|
|
|
|
Sponsor Sponsor
|
|
|
syntax_error
|
Posted: Fri Dec 21, 2007 8:37 pm Post subject: Re: Making my sprites jump |
|
|
ok to move in a diagonally movement
one needs to think what is changing
BOTH teh x and y are moving so you would use a for loop to control
then increments on how fast teh figure will move rest
jsut keep adding the increments to the x and y values of the image location |
|
|
|
|
|
rcbhs
|
Posted: Sat Dec 22, 2007 12:58 am Post subject: Re: Making my sprites jump |
|
|
I hoestly don't even know where to start with the for loop, like not a clue at all... |
|
|
|
|
|
HeavenAgain
|
Posted: Sat Dec 22, 2007 9:00 am Post subject: RE:Making my sprites jump |
|
|
a for loop is a counted loop, which goes around itself (whats inside of it) the number of times according to a counter. now, how to use it
code: | for i : 1..10
put i
end for |
the first line is to tell the computer, we are starting a for loop, with a counter variable i, and it will start from 1, and go all the way to 10, by adding 1 to itself every time it reaches to the end. and the 2nd, we are using the variable counter i and displaying it. finally, the last line shows that we have ended this for loop.
i hope that helps... or at least get you started |
|
|
|
|
|
Mazer
|
Posted: Sat Dec 22, 2007 10:22 am Post subject: RE:Making my sprites jump |
|
|
Stop, why would you use a for loop?
I'm assuming you already have one loop for your game; you should be running through this loop once each time you draw a frame. DO NOT PUT ADDITIONAL LOOPS INSIDE OF THIS UNLESS YOU INTEND FOR THEM TO FINISH THEIR EXECUTION WITHIN A SINGLE FRAME.
I'm also assuming you have some variables to keep track of the sprite's x and y position. You should also have variables to keep track of the x and y velocity. When you are running right your x velocity should be 10 (or whatever) and when running left, -10.
Your y velocity is somewhat different. You should always be subtracting some value (9.8m/s^2 is acceleration due to gravity, but the units you are using may not correspond so use a value that looks about right) from the y velocity. When the player presses the jump button, first make sure that they are on the ground (y position is 0 or something like that) and then set the y velocity to something relatively high. Don't worry about it looking like the value is too high, you're still decreasing it every time you go through the loop. In this way the y velocity will eventually reach zero and then go below zero, so your character should move through the air in a smooth arc. Don't forget to stop the character when it hits the ground. |
|
|
|
|
|
|
|