letting player spawn. hiding three.js canvas

This commit is contained in:
Logsol 2013-01-04 01:03:41 +01:00
parent 4767632f3d
commit 6219a82fbd
5 changed files with 24 additions and 15 deletions

View file

@ -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;
});

View file

@ -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;

View file

@ -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");

View file

@ -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);