All of the previous gravity examples had loads of lines of code for each object that you wanted to apply gravity to, so if you had more than 10, your game would take ages to compile and save and stuff, so I thought: "Wouldn't it be good if you could add gravity to any instance you wanted with one line in the object?"
And here it is!
(This also includes the code writen below and a sample background... Everything you need to compile it into the nds at the bottom of this post.)
I put all of the complex stuff in scripts, so the only code I had to use in the object was:
- Code: Select all
Run Script,Fall;[Me],this
And it adds gravity and collision detection to your object without cluttering up the whole object code.
Then I added this for jumping:
- Code: Select all
If,Pad.Newpress.A && Touching_Floor([Me]),this
Start Block,,this
Run Script,Set_Velocity;[Me]<com> -1700,this
End Block,,this
And this for moving left and right:
- Code: Select all
Set Variable,[X];[X] + ((Pad.Held.Right && [X] < 224) - (Pad.Held.Left && [X] > 0)),this
And then put a background on the same screen as the object.
Which is all you need if you have the gravity template in your project to build something like this!
The collision detection isn't the best, but I'll update it so it looks better later. Until then though, what do you think?
