I'm quite new to the concept of module patterns. I managed to implement the core features of my HTML5 game, but I can't figure out a good way to make certain variables available to every function of that game.
Here is a short pseudo example which should make it more clear:
var Game = {};
Game.player = (function() {
//...
return {
update : update,
draw : draw
};
});
Game.main = (function() {
var player = new Game.player();
// needed by player
var gravity = 1.0,
loop,
canvas,
ctx,
key_inputs;
//...
return {
init : init,
pause : pause,
play : play
};
});
var game = new Game.main();
game.init();