### Simple Physics Movement Engine by Butts Fredkin

 Submitted By: LincolnB Date: December 07, 2011, 10:33:50 am Views: 1670 First off, let me say thanks to Builderboy, cause I learned how to do this type of stuff from his awesome physics tutorials. I just hope that I can maybe make things easier for people who are new to calculator programming and maybe need a little extra clarification. I'm trying to be in depth, so PM me or post somewhere or find me on IRC if you have questions. Other people know this stuff as well, so you can ask them also.People say all the time, "I see these little details in games like realistic jumping and movement, how do I add those?" This tutorial hopes to answer that question. What you're referring to is known as acceleration, deceleration, and gravity, and those three are actually fairly easy to implement.Say you have a sprite for your character in Pic1, and the characters position in two variables, X and Y. Every frame, to update the screen, you go like this:Code: [Select].Initialize0->X->Y.Main Game LoopRepeat getkey(15)ClrDrawPt-On(X/256,Y/256,Pic1)Dispgraph.Just so it's not too fast...Pause 75EndBecause you'll probably want to use 256x inflation, to insure smoothness and acuracy. Some say 256x is too much, but dividing by 256 is a highly optimized procedure (read: it's way fast)So to do gravity, you need to implement constant acceleration along the Y-Axis. To do that, you need a variable to store the current velocity on the Y-Axis, and add to it every frame. I'm going to use the variable E.Adding to our previous code:Code: [Select]0->X->Y->ERepeat getkey(15).Add Y_Velocity to Y_PositionY+E->Y.Add a constant acceleration to Y_VelocityE+100->EClrDrawPt-On(X/256,Y/256,Pic1)DispgraphPause 75EndIf you run that code, you'll notice a problem - the character falls right off the bottom of the screen! You need to add some code to prevent that.[code]0->X->Y->ERepeat getkey(15)Y+E->YE+100->E.Make sure he doesn't fall off the bottom of the screenIf Y>>14336.^^make sure it's >>, not >. Rating: This article has not been rated yet.