Game Development Reference
In-Depth Information
// Allows client code to start/stop the game
loop
this.setRunning = function(running) {
isRunning = running;
return isRunning;
};
this.isRunning = function() {
return isRunning;
};
this.run = run;
// Allows client code to override default
update function
this.setOnUpdate = function(cb){
update = cb;
};
};
When we create an instance of this class, we tell it how fast we want the game loop
to run in terms of frames per second and the class takes care of the rest. Once this
is set up, the class will class its own update class at whatever frequency we tell it
to. As an added bonus, we can also specify our own update function to be executed
every time the game loop ticks.
PhysicsManager.js
Similar to the EnemyManager class, the PhysicsManager class is responsible for
isolating complex functionality so that the client code is cleaner and the functionality
can be reused elsewhere. Since this class is a bit more involved, we won't be show-
ing the complete source code for it in the topic. As with the other chapters, check out
Packt's website for this topic.
In summary, the PhysicsManager class takes a reference to all of the enemy entit-
ies (which it can get from the EnemyManager object), all of the player's laser beams,
Search WWH ::




Custom Search