Game and Simulation Logic

We’re going to make a new function to move and rotate the Earth. We could put this inside the animate() function, but separating game or simulation code from animation code will make our code more flexible. Game programmers often refer to this as separating game logic from animation code.

The properties that we’ll control in this simulation are the speed at which it runs, whether or not the simulation is paused, and the number of days that have passed inside the simulation. We’ll also need another internal clock to help track the time inside the simulation.

Add the following at the very end of our code, below the call to animate():

​ ​var​ speed = 10;
​ ​var​ pause = ​false​;
​ ​var​ days ...

Get 3D Game Programming for Kids, 2nd 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.