Building a physics engine to get things moving

Create a new package private class called PhysicsEngine and add the following code.

class PhysicsEngine {

   // This signature and much more will 
   //change later in the project
   boolean update(long fps, ParticleSystem ps){

        if(ps.mIsRunning){
            ps.update(fps);
        }

        return false;
    }

   // Collision detection method will go here

}

The PhysicsEngine class only has one method for now, update. By the end of the project it will have another method for checking collisions. The signature of the update method receives the frames per second and a ParticleSystem. The code simply checks if the ParticleSystem is running and if it is calls its update method and passes in the required fps.

Now we can create an instance of the PhysicsEngine ...

Get Learning Java by Building Android Games - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.