Computer Science Canada Simple gravity program |
Author: | Zacebdal [ Thu Oct 19, 2006 6:49 pm ] | ||
Post subject: | Simple gravity program | ||
I was just playing around and trying to figure out an algorithm to simulate gravity and i came up with this little program. I know that there is probably an easier way to do this but i thought i would submit this anyways. I have only recently started to program so for me its kinda a big deal. any comments or suggestions are much appreciated. Thanks
|
Author: | Cervantes [ Thu Oct 19, 2006 9:53 pm ] |
Post subject: | |
A good try, but it's fundamentally wrong. You should not have for loops within those if statements. Why? Because if you put a for loop in there, the execution will remain in there while the character moves and no other part of your program will run. It's like this: "You want to move a step to the right? Sure, but doing so will prevent your enemies or allies from moving." Instead, you need to create variables that store the velocity of your character. If you hit the up arrow and you're on the ground, set the y velocity to some value, say 5. Then while you're in the air, decrease the y velocity by some constant value with every iteration of the loop. That's acceletaion at work. |