Some games require handling gravity from multiple variable sources. In this recipe, we'll handle this and create a simple miniature solar system to demonstrate it using ThrusterControl
from the Building a rocket engine recipe. To (greatly) simplify the relation between the planets, they won't affect each other with their gravity, but only the ship. It will also be made in a 2D-asteroids-like fashion, although the gravity would still apply for a 3D game.
We'll add some basic controls to rotate the ship to the left and right, and you can use the thruster to make the ship move forward.
Apart from ThrusterControl
, we'll create two more small classes and an application class that joins everything together. Let's start with a class that represents the player's ship. This will consist of the following six steps:
Create a new class called
SpaceShip
, which has aNode
field calledshipNode
in it.In the constructor, we set up the physics for it by creating...