mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fixed #53
This commit is contained in:
parent
695008afd8
commit
aa4535cb0c
10 changed files with 73 additions and 32 deletions
|
|
@ -104,11 +104,17 @@
|
|||
}
|
||||
|
||||
Channel.prototype.broadcastGameCommand = function (command, options) {
|
||||
this.broadcastControlCommand("gameCommand", ProtocolHelper.encodeCommand(command, options));
|
||||
for(var id in this.users) {
|
||||
this.users[id].sendGameCommand(command, options);
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.broadcastGameCommandExcept = function (command, options, exceptUser) {
|
||||
this.broadcastControlCommandExcept("gameCommand", ProtocolHelper.encodeCommand(command, options), exceptUser);
|
||||
for(var id in this.users) {
|
||||
if (id != exceptUser.id) {
|
||||
this.users[id].sendGameCommand(command, options);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return Channel;
|
||||
|
|
|
|||
|
|
@ -8,10 +8,11 @@ define([
|
|||
"Lib/Vendor/Box2D",
|
||||
"Game/Server/Player",
|
||||
"Game/Server/GameObjects/GameObject",
|
||||
"Game/Server/GameObjects/Doll"
|
||||
"Game/Server/GameObjects/Doll",
|
||||
"Game/Server/GameObjects/Items/RagDoll"
|
||||
],
|
||||
|
||||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Box2D, Player, GameObject, Doll) {
|
||||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Box2D, Player, GameObject, Doll, RagDoll) {
|
||||
|
||||
function GameController (channel) {
|
||||
|
||||
|
|
@ -77,15 +78,13 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
// put it into
|
||||
self.gameObjects.animated.push(player);
|
||||
|
||||
var message = {
|
||||
spawnPlayer: {
|
||||
id: player.id,
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y
|
||||
}
|
||||
var options = {
|
||||
id: player.id,
|
||||
x: spawnPoint.x,
|
||||
y: spawnPoint.y
|
||||
};
|
||||
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", message);
|
||||
NotificationCenter.trigger("broadcastGameCommand", "spawnPlayer", options);
|
||||
}, respawnTime * 1000);
|
||||
};
|
||||
|
||||
|
|
@ -103,7 +102,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
var update = this.getWorldUpdateObject(false);
|
||||
|
||||
if(Object.getOwnPropertyNames(update).length > 0) {
|
||||
NotificationCenter.trigger("broadcastControlCommand", 'gameCommand', {worldUpdate:update});
|
||||
NotificationCenter.trigger("broadcastGameCommand", 'worldUpdate', update);
|
||||
}
|
||||
|
||||
setTimeout(this.updateWorld.bind(this), Settings.WORLD_UPDATE_BROADCAST_INTERVAL);
|
||||
|
|
@ -143,7 +142,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
GameController.prototype.getSpawnedPlayersAndTheirPositions = function() {
|
||||
var spawnedPlayers = [];
|
||||
for(id in this.players) {
|
||||
for(var id in this.players) {
|
||||
var player = this.players[id];
|
||||
if(player.isSpawned) {
|
||||
|
||||
|
|
@ -164,23 +163,21 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
return spawnedPlayers;
|
||||
};
|
||||
|
||||
GameController.prototype.getAdditionalObjects = function() {
|
||||
GameController.prototype.getRuntimeItems = function() {
|
||||
var objects = []
|
||||
|
||||
for (var i = 0; i < this.gameObjects.animated.length; i++) {
|
||||
if(this.gameObjects.animated[i] instanceof RagDoll) {
|
||||
var object = this.gameObjects.animated[i];
|
||||
var options = object.options;
|
||||
options.x = object.getPosition().x;
|
||||
options.y = object.getPosition().y;
|
||||
objects.push({
|
||||
uid: objects.uid,
|
||||
options: object.options,
|
||||
x: object.getPosition().x,
|
||||
y: object.getPosition().y
|
||||
uid: object.uid,
|
||||
options: object.options
|
||||
});
|
||||
}
|
||||
};
|
||||
var object = {
|
||||
// FIXME: finish it!
|
||||
}
|
||||
|
||||
return objects;
|
||||
};
|
||||
|
|
@ -192,6 +189,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
var options = {
|
||||
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
|
||||
worldUpdate: this.getWorldUpdateObject(true),
|
||||
runtimeItems: this.getRuntimeItems(),
|
||||
userId: userId
|
||||
}
|
||||
|
||||
|
|
@ -200,7 +198,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
GameController.prototype.onResetLevel = function(userId) {
|
||||
Parent.prototype.onResetLevel.call(this);
|
||||
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", {resetLevel:true});
|
||||
NotificationCenter.trigger("broadcastGameCommand", "resetLevel", true);
|
||||
for (var key in this.players) {
|
||||
this.spawnPlayer(this.players[key]);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
|
|||
|
||||
this.channel = channel;
|
||||
this.player = null;
|
||||
this.isReady = false;
|
||||
var self = this;
|
||||
|
||||
NotificationCenter.on('user/joined', function(user) { // FIXME: use sendToAllUsersExcept instead
|
||||
|
|
@ -51,6 +52,7 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
|
|||
if(command.hasOwnProperty("resetLevel")) {
|
||||
NotificationCenter.trigger("user/resetLevel", this.id);
|
||||
} else if(command.hasOwnProperty("clientReady")) {
|
||||
this.isReady = true;
|
||||
NotificationCenter.trigger("user/clientReady", this.id);
|
||||
} else {
|
||||
this.player.playerController.applyCommand(command);
|
||||
|
|
@ -69,8 +71,10 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
|
|||
};
|
||||
|
||||
User.prototype.sendGameCommand = function(command, options) {
|
||||
var data = ProtocolHelper.encodeCommand(command, options);
|
||||
this.sendControlCommand("gameCommand", data);
|
||||
if(this.isReady) {
|
||||
var data = ProtocolHelper.encodeCommand(command, options);
|
||||
this.sendControlCommand("gameCommand", data);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue