mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
begin Round Bug improvements, player renders doll. fixes #64
This commit is contained in:
parent
55b56f9c12
commit
c18384f502
11 changed files with 76 additions and 42 deletions
|
|
@ -9,10 +9,11 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Game/Client/GameObjects/GameObject",
|
||||
"Game/Client/GameObjects/Doll",
|
||||
"Game/Client/View/DomController"
|
||||
"Game/Client/View/DomController",
|
||||
"Lib/Utilities/Protocol/Helper"
|
||||
],
|
||||
|
||||
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController) {
|
||||
function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, requestAnimFrame, Settings, GameObject, Doll, DomController, ProtocolHelper) {
|
||||
|
||||
if (!window.cancelAnimationFrame) {
|
||||
window.cancelAnimationFrame = function(id) {
|
||||
|
|
@ -20,8 +21,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
};
|
||||
}
|
||||
|
||||
|
||||
function GameController (options) {
|
||||
|
||||
this.clientIsReady = false;
|
||||
this.view = ViewManager.createView();
|
||||
this.me = null;
|
||||
this.animationRequestId = null;
|
||||
|
|
@ -64,12 +66,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
GameController.prototype.onClientReadyResponse = function(options) {
|
||||
|
||||
if (options.spawnedPlayers) {
|
||||
for(var i = 0; i < options.spawnedPlayers.length; i++) {
|
||||
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (options.worldUpdate) {
|
||||
this.onWorldUpdate(options.worldUpdate);
|
||||
}
|
||||
|
|
@ -88,12 +84,19 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
|
||||
if(!alreadyExists) {
|
||||
var item = this.level.createItem(itemDef.uid, itemDef.options);
|
||||
//this.onGameObjectAdd("animated", item);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
this.createMe(options.userId);
|
||||
|
||||
this.clientIsReady = true; // needs to stay before onSpawnPlayer
|
||||
|
||||
if (options.spawnedPlayers) {
|
||||
for(var i = 0; i < options.spawnedPlayers.length; i++) {
|
||||
this.onSpawnPlayer(options.spawnedPlayers[i]);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
GameController.prototype.onWorldUpdate = function (updateData) {
|
||||
|
|
@ -128,14 +131,23 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
|
|||
this.view.setMe(this.me);
|
||||
}
|
||||
|
||||
GameController.prototype.onGameCommand = function(message) {
|
||||
ProtocolHelper.applyCommand(message, this);
|
||||
};
|
||||
|
||||
GameController.prototype.onSpawnPlayer = function(options) {
|
||||
|
||||
if(!this.clientIsReady) {
|
||||
return;
|
||||
}
|
||||
|
||||
var playerId = options.id,
|
||||
x = options.x,
|
||||
y = options.y;
|
||||
|
||||
var player = this.players[playerId];
|
||||
player.spawn(x, y);
|
||||
this.gameObjects.animated.push(player);
|
||||
this.onGameObjectAdd('animated', player);
|
||||
|
||||
if(options.holdingItemUid) {
|
||||
this.onHandActionResponse({
|
||||
|
|
|
|||
|
|
@ -20,8 +20,12 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
|
|||
var self = this;
|
||||
this.socketLink.on('message', function (message) {
|
||||
var m = JSON.parse(message)
|
||||
if(Settings.NETWORK_LOG_INCOMING && !m.gameCommand) {
|
||||
console.log('INCOMING', message);
|
||||
if(Settings.NETWORK_LOG_INCOMING) {
|
||||
|
||||
if (message.indexOf('worldUpdate') == -1 && message.indexOf('pong') == -1) {
|
||||
console.log('INCOMING', message);
|
||||
}
|
||||
|
||||
}
|
||||
ProtocolHelper.applyCommand(message, self);
|
||||
});
|
||||
|
|
@ -147,7 +151,7 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
|
|||
}
|
||||
|
||||
Networker.prototype.onGameCommand = function(message) {
|
||||
ProtocolHelper.applyCommand(message, this.gameController);
|
||||
this.gameController.onGameCommand(message);
|
||||
}
|
||||
|
||||
Networker.prototype.onPong = function(timestamp) {
|
||||
|
|
|
|||
|
|
@ -87,7 +87,9 @@ function (Parent, Nc, Settings) {
|
|||
|
||||
Player.prototype.render = function() {
|
||||
|
||||
// dolls are self responsible
|
||||
if(this.doll) {
|
||||
this.doll.render();
|
||||
}
|
||||
|
||||
if(this.playerInfoViewVisible) {
|
||||
var position = this.getPosition();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue