diff --git a/lib/Chuck/Game.js b/lib/Chuck/Game.js index 2c7cc9f..a2eb3a9 100644 --- a/lib/Chuck/Game.js +++ b/lib/Chuck/Game.js @@ -1,11 +1,23 @@ -define(["Chuck/Processor"], function(Processor){ +define(["Chuck/Settings", "Chuck/Processors/ServerProcessor", "Chuck/Processors/ClientProcessor"], function(Settings, ServerProcessor, ClientProcessor){ function Game(networker){ this.networker = networker; - this.processor = new Processor(); + this.processor = this.createProcessor(); + this.processor.loadLevel("default.json"); } + Game.prototype.createProcessor = function(){ + var processor; + + if(Settings.IS_BROWSER_ENVIRONMENT){ + processor = new ClientProcessor(); + } else { + processor = new ServerProcessor(); + } + return processor; + } + Game.prototype.processGameCommand = function(command, options){ console.log('(not implemented) processGameCommand:', command, options); } diff --git a/lib/Chuck/Processor.js b/lib/Chuck/Processors/ClientProcessor.js similarity index 51% rename from lib/Chuck/Processor.js rename to lib/Chuck/Processors/ClientProcessor.js index 5ee2a33..bbef4e3 100755 --- a/lib/Chuck/Processor.js +++ b/lib/Chuck/Processors/ClientProcessor.js @@ -11,15 +11,11 @@ var requires = [ define(requires, function(ViewController, PhysicsEngine, Player, InputControlUnit, Settings, Box2D, Level, requestAnimFrame){ - function Processor () { - if(Settings.IS_BROWSER_ENVIRONMENT) { - this.initClient(); - } else { - this.initServer(); - } + function ClientGame () { + this.init(); }; - Processor.prototype.initClient = function() { + ClientGame.prototype.init = function() { this.viewController = new ViewController(); this.physicsEngine = new PhysicsEngine(); this.me = new Player(this.physicsEngine, null); @@ -30,14 +26,7 @@ define(requires, function(ViewController, PhysicsEngine, Player, InputControlUni this.update(); } - Processor.prototype.initServer = function() { - this.physicsEngine = new PhysicsEngine(); - //this.physicsEngine.setCollisionDetector(players); - - this.update(); - } - - Processor.prototype.loadLevel = function(path) { + ClientGame.prototype.loadLevel = function(path) { if (this.level) { this.level.unload(); } @@ -46,35 +35,27 @@ define(requires, function(ViewController, PhysicsEngine, Player, InputControlUni this.level.loadLevelInToEngine(); } - Processor.prototype.getPhysicsEngine = function() { + ClientGame.prototype.getPhysicsEngine = function() { return this.physicsEngine; } - Processor.prototype.getMe = function() { + ClientGame.prototype.getMe = function() { return this.me; } - Processor.prototype.update = function() { - + ClientGame.prototype.update = function() { requestAnimFrame(this.update.bind(this)); - //console.log(self.physicsEngine.getWorld().GetBodyList().GetPosition()); - this.physicsEngine.update(); - - if(Settings.IS_BROWSER_ENVIRONMENT) { - this.viewController.update(); - this.inputControlUnit.update(); - this.me.update(); - //self.camera.update(); - //self.repository.update(); - } + this.viewController.update(); + this.inputControlUnit.update(); + this.me.update(); } - Processor.prototype.destruct = function() { + ClientGame.prototype.destruct = function() { } - return Processor; + return ClientGame; }); diff --git a/lib/Chuck/Processors/ServerProcessor.js b/lib/Chuck/Processors/ServerProcessor.js new file mode 100755 index 0000000..a8fecce --- /dev/null +++ b/lib/Chuck/Processors/ServerProcessor.js @@ -0,0 +1,46 @@ +var requires = [ + "Chuck/Physics/Engine", + "Chuck/Player", + "Vendor/Box2D", + "Chuck/Loader/Level", + "RequestAnimationFrame" +]; + +define(requires, function(PhysicsEngine, Player, Box2D, Level, requestAnimFrame){ + + function ServerGame () { + this.init(); + }; + + ServerGame.prototype.init = function() { + this.physicsEngine = new PhysicsEngine(); + + this.update(); + } + + ServerGame.prototype.loadLevel = function(path) { + if (this.level) { + this.level.unload(); + } + + this.level = new Level(path, this.physicsEngine); + this.level.loadLevelInToEngine(); + + console.log(this.level); + } + + ServerGame.prototype.getPhysicsEngine = function() { + return this.physicsEngine; + } + + ServerGame.prototype.update = function() { + requestAnimFrame(this.update.bind(this)); + this.physicsEngine.update(); + } + + ServerGame.prototype.destruct = function() { + + } + + return ServerGame; +}); diff --git a/lib/Server/Channel.js b/lib/Server/Channel.js index 4ae561a..e35f34b 100644 --- a/lib/Server/Channel.js +++ b/lib/Server/Channel.js @@ -1,9 +1,9 @@ -define(function() { +define(["Chuck/Game"], function(Game) { function Channel(name) { this.name = name; this.users = {}; - + this.game = new Game(); // create game here }