Gravity-Based Platform Game

1

Stats

4,724 visits, 6,859 views

Tools

Translations

This tutorial hasn't been translated.

License

This tutorial is licensed under CC BY 4.0. Please refer to the license text if you wish to reuse, share or remix the content contained within this tutorial.

Published on 23 Jun, 2012. Last updated 19 Feb, 2019

Special Thanks

Before I begin on this tutorial, i'd like to thank Sqiddster and a very nice Scirra user who helped me understand the code and work me through bugs. I'd also like to thank Yann Granjon for teaching me some pretty advance Math, which unfortunately, I did not however use it in my current game, but do indeed plan to use it in my next.

Basics

So let's begin shall we? If you've player Sqiddsters game AirScape, you'll notice the nice rotation effect and gravity effect, this is all done with a couple variables and some math. Along with some invisible sprites known as GravityZones, or as Sqiddster used; gravzones. As shown below, you can see a simple map. The map has 2 islands, and a player. This map can be downloaded at the bottom of the tutorial.

How do we create the effects?

The gravity effect is set by getting the directional angel and using the Platform behavior to set the gravitational angle. The platform behavior already however has a Gravitational pull based upon angle. So using the angular direction equation [angle(Start.X,Start.X,End.X,End)] we can get the angle in which if our character had a bullet, the character would move toward that direction. But how do we know when we have a Straight surface or curved surface? Well, Yann suggested, Sqiddster implemented, I followed. GravityZones/gravzones. These are actually just Sprites that are invisible to you. With around 5-6 different animations for different locations of a map, our code will look to see what our character is touching, and then choose the way for our gravitational pull. This is all based on a Boolean instance variable named "Relative". Shown below is the gravitational code.

(Please note that in the code above, the System>Every tick is out of place. Why? I moved it for the picture, and the position of that event is actually at the bottom of all the code, shown correctly in the "flip" image)

Epic jumping/180 flip

As Sqiddster created the 180 rotation for his game AirScape, he couldn't just have his character jump into a new set of GravityZones, he had to add another Sprite. What is it though? flip_assist. A flip_assist would change the characters angle in which it would go forward (Act as if it would continue to jump), and because it would continue going forward, once it hits a new GravityZone, if it did, then it would "attach" to that GravityZone and do all the angular direction stuff over again. Here's the shot of the flip_assist code.

Thanks

Again, I couldn't have done it without Sqiddster or Yann Granjon. Please, if you liked this tutorial or understood it very well, +1 this tutorial.

Links

As said, I have created a download for the basic map. Enjoy. :)

**EDIT FROM SQIDDSTER:

The code linked here had numerous severe bugs as well as ripped graphics from my game. I've removed the link mainly to stop beginners from running into issues with bad code, but also for copyright reasons.**

  • 0 Comments

Want to leave a comment? Login or Register an account!