work in progress... worked on channel attributes and game goal. fixes #45 and references #48

This commit is contained in:
logsol 2014-03-30 00:12:04 +01:00
parent 039213cf50
commit 55256ada95
23 changed files with 409 additions and 110 deletions

View file

@ -14,21 +14,27 @@ define([
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController) {
function GameController () {
if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) {
clearTimeout(id);
};
}
function GameController (options) {
this.view = ViewManager.createView();
this.me = null;
this.animationRequestId = null;
Nc.on(Nc.ns.client.game.gameInfo.toggle, this.toggleInfo, this);
Parent.call(this, options);
Parent.call(this);
this.ncTokens = this.ncTokens.concat([
Nc.on(Nc.ns.client.game.gameInfo.toggle, this.toggleInfo, this)
]);
}
GameController.prototype = Object.create(Parent.prototype);
GameController.prototype.destruct = function() {
//destroy box2d world etc.
};
GameController.prototype.getMe = function () {
return this.me;
}
@ -39,7 +45,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
DomController.statsBegin();
requestAnimFrame(this.update.bind(this));
this.animationRequestId = requestAnimFrame(this.update.bind(this));
this.physicsEngine.update();
@ -82,7 +88,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
if(!alreadyExists) {
var item = this.level.createItem(itemDef.uid, itemDef.options);
this.onGameObjectAdd("animated", item);
//this.onGameObjectAdd("animated", item);
}
};
}
@ -189,7 +195,7 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
}
}
if(object) {
this.onGameObjectRemove(options.type, object);
//this.onGameObjectRemove(options.type, object);
object.destroy();
} else {
console.warn("GameObject for removal can not be found locally. " + options.uid);
@ -253,5 +259,15 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
this.view.toggleInfo(show, string);
};
GameController.prototype.destroy = function() {
cancelAnimationFrame(this.animationRequestId);
Parent.prototype.destroy.call(this);
this.view.render();
this.view.test();
};
return GameController;
});

View file

@ -99,6 +99,9 @@ function (Parent, CoreItem, Settings, Nc) {
};
RagDoll.prototype.destroy = function() {
console.log('ragdoll destroy');
for (var name in this.limbMeshes) {
Nc.trigger(Nc.ns.client.view.mesh.remove, this.limbMeshes[name]);
};

View file

@ -48,8 +48,8 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
}
Networker.prototype.onDisconnect = function () {
if(this.gameController) this.gameController.destruct();
this.gameController = null;
//if(this.gameController) this.gameController.destruct();
//this.gameController = null;
console.log('disconnected. game destroyed. no auto-reconnect');
document.body.style.backgroundColor = '#aaaaaa';
}
@ -57,9 +57,6 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
Networker.prototype.onJoinSuccess = function (options) {
console.log("join success")
this.gameController = new GameController();
this.gameController.loadLevel(options.levelUid);
this.onUserJoined(options.user);
if (options.joinedUsers) {
@ -140,6 +137,21 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
setTimeout(this.ping.bind(this), 1000);
};
Networker.prototype.onBeginRound = function(options) {
if(this.gameController) {
this.gameController.destroy();
delete this.gameController;
}
console.log('GameController')
this.gameController = new GameController(options);
};
Networker.prototype.onEndRound = function() {
this.gameController.toggleInfo(true);
};
return Networker;
});

View file

@ -101,8 +101,9 @@ function (Parent, Nc, Settings) {
};
Player.prototype.destroy = function() {
Parent.prototype.destroy.call(this);
clearTimeout(this.playerInfoViewVisibleTimeout);
Nc.trigger(Nc.ns.client.view.playerInfo.remove, this.playerInfoView);
Parent.prototype.destroy.call(this);
};
return Player;

View file

@ -32,7 +32,7 @@ function (Parent, DomController, PIXI, Settings, Nc) {
var transparent = false;
var antialias = true;
var canvas = null; // lets pixi create one
var canvas = DomController.getCanvas();
if(Settings.USE_WEBGL) {
this.renderer = new PIXI.WebGLRenderer(Settings.STAGE_WIDTH, Settings.STAGE_HEIGHT, canvas, transparent, antialias);
@ -42,7 +42,7 @@ function (Parent, DomController, PIXI, Settings, Nc) {
console.log('CanvasRenderer - not using WebGL!')
}
this.stage = new PIXI.Stage(0x333333);
this.stage = new PIXI.Stage(/*0x333333*/);
this.initCamera();
this.initInfo();
@ -305,5 +305,9 @@ function (Parent, DomController, PIXI, Settings, Nc) {
this.loader.visible = progress < 100;
};
PixiView.prototype.test = function() {
console.log(this.stage.children)
};
return PixiView;
});