From 6219a82fbd83d4c822b5d3a4065a4b5c1a249f65 Mon Sep 17 00:00:00 2001 From: Logsol Date: Fri, 4 Jan 2013 01:03:41 +0100 Subject: [PATCH] letting player spawn. hiding three.js canvas --- app/Game/Client/GameController.js | 9 +++------ app/Game/Client/Networker.js | 17 +++++++++++------ app/Game/Client/Physics/Engine.js | 2 ++ app/Game/Server/GameController.js | 8 +++++--- static/html/index.html | 3 +++ 5 files changed, 24 insertions(+), 15 deletions(-) diff --git a/app/Game/Client/GameController.js b/app/Game/Client/GameController.js index 274ab9a..f4cf72d 100755 --- a/app/Game/Client/GameController.js +++ b/app/Game/Client/GameController.js @@ -17,14 +17,12 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio this.me = null; this.keyboardController = null; - //NotificationCenter.on('me/joined', this.meJoined, this) - - //this.update(); + this.update(); } GameController.prototype = Object.create(Parent.prototype); -/* + GameController.prototype.getMe = function () { return this.me; } @@ -44,7 +42,6 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio GameController.prototype.meJoined = function (user) { this.me = this.userJoined(user); - this.keyboardController = new KeyboardController(this.me, this); } @@ -71,6 +68,6 @@ function (Parent, PhysicsEngine, ViewController, KeyboardController, Notificatio } } -*/ + return GameController; }); diff --git a/app/Game/Client/Networker.js b/app/Game/Client/Networker.js index 5bd1971..e5e0da6 100755 --- a/app/Game/Client/Networker.js +++ b/app/Game/Client/Networker.js @@ -1,9 +1,10 @@ define([ "Game/Core/Protocol/Helper", - "Game/Client/GameController" + "Game/Client/GameController", + "Game/Core/User" ], -function (ProtocolHelper, GameController) { +function (ProtocolHelper, GameController, User) { function Networker (socketLink) { this.socketLink = socketLink; @@ -49,11 +50,15 @@ function (ProtocolHelper, GameController) { Networker.prototype.onJoinSuccess = function (options) { this.gameController = new GameController(); - //this.gameController.loadLevel("default.json"); + this.gameController.loadLevel("default.json"); + var user = new User(options.userId); + this.gameController.meJoined(user); console.log("Joined " + options.channelName); + + /* if (options.userIds && options.userIds.length > 0) { for(var i = 0; i < options.userIds.length; i++) { @@ -71,7 +76,7 @@ function (ProtocolHelper, GameController) { Networker.prototype.onMessage = function (message) { var self = this; - + ProtocolHelper.runCommands(message, function (command, options) { self.processControlCommand(command, options); }); @@ -93,7 +98,7 @@ function (ProtocolHelper, GameController) { } Networker.prototype.processControlCommand = function (command, options) { - + switch(command) { case 'joinSuccess': this.onJoinSuccess(options); @@ -101,7 +106,7 @@ function (ProtocolHelper, GameController) { case 'gameCommand': for(var gameCommand in options) { - //this.gameController.processGameCommand(gameCommand, options[gameCommand]); + this.gameController.processGameCommand(gameCommand, options[gameCommand]); } break; diff --git a/app/Game/Client/Physics/Engine.js b/app/Game/Client/Physics/Engine.js index f619ca6..ce4d2ac 100755 --- a/app/Game/Client/Physics/Engine.js +++ b/app/Game/Client/Physics/Engine.js @@ -15,6 +15,8 @@ function (Parent, Settings, DomController, Box2D) { } } + Engine.prototype = Object.create(Parent.prototype); + Engine.prototype.setupDebugDraw = function () { //var debugSprite = Settings.DEBUG_DRAW_CANVAS_SPRITE; var debugSprite = DomController.getDebugCanvas().getContext("2d"); diff --git a/app/Game/Server/GameController.js b/app/Game/Server/GameController.js index ab32119..3ff4a6a 100755 --- a/app/Game/Server/GameController.js +++ b/app/Game/Server/GameController.js @@ -37,12 +37,11 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No } GameController.prototype.userJoined = function (user) { - console.log(Parent.prototype); - Parent.prototype.userJoined.call(this, user); var id = user.id; var player = this.players[id]; + player.spawn(50, 50); this.inputControllers[id] = new InputController(player); } @@ -67,6 +66,9 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No do { var userData = body.GetUserData(); + + + if(userData && body.IsAwake()) { update[userData] = { p: body.GetPosition(), @@ -79,7 +81,7 @@ function (Parent, PhysicsEngine, Settings, InputController, requestAnimFrame, No } while (body = body.GetNext()); if(isUpdateNeeded) { - NotificationCenter.trigger("sendControlCommandToAllUsers", ['gameCommand', {worldUpdate:update}]); + NotificationCenter.trigger("sendControlCommandToAllUsers", 'gameCommand', {worldUpdate:update}); } setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL); diff --git a/static/html/index.html b/static/html/index.html index bfb5a67..87f9a59 100755 --- a/static/html/index.html +++ b/static/html/index.html @@ -21,6 +21,9 @@ background: #333; margin: 10px; } + #canvasContainer canvas:first-child { + display: none; + }