Skip to content

Instantly share code, notes, and snippets.

@davidB
Created October 27, 2013 13:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save davidB/7181741 to your computer and use it in GitHub Desktop.
Save davidB/7181741 to your computer and use it in GitHub Desktop.
class Game {
var _world;
var _renderSystem;
var _gameLoop;
Game(){
// create instance
var container = query("#game");
_world = new World();
_gameLoop = new GameLoopHtml(container);
_renderSystem = new System_RenderX(container);
// setup instance an allow circular dependencies gameLoop <-> world'system
_setupWorld();
_setupGameLoop();
}
void _setupWorld() {
//...
_world.addSystem(new System_XXXX());
_world.addSystem(new System_YYYY(_gameLoop));
// System(s) in charge of rendering will not run when world.process()
_world.addSystem(_renderSystem, passive: true);
_world.initialize();
}
void _setupGameLoop(){
_gameLoop.pointerLock.lockOnClick = false; // to keep mouse cursor
_gameLoop.onUpdate = (gameLoop){
_world.delta = gameLoop.dt * 1000.0; // world.delta in ms
_world.process();
};
_gameLoop.onRender = (gameLoop){
_renderSystem.process();
};
}
void start() => _gameLoop.start();
void stop() => _gameLoop.stop();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment