mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
fixed #38
This commit is contained in:
parent
7a59e175e0
commit
89c5e4a5d8
6 changed files with 64 additions and 25 deletions
|
|
@ -45,6 +45,19 @@
|
|||
// Channel command callbacks
|
||||
|
||||
Channel.prototype.onAddUser = function (userId) {
|
||||
var self = this;
|
||||
|
||||
if(!this.gameController.level || !this.gameController.level.isLoaded) {
|
||||
var token = NotificationCenter.on("game/level/loaded", function() {
|
||||
self.sendJoinSuccess(userId);
|
||||
NotificationCenter.off(token);
|
||||
});
|
||||
} else {
|
||||
self.sendJoinSuccess(userId);
|
||||
}
|
||||
}
|
||||
|
||||
Channel.prototype.sendJoinSuccess = function(userId) {
|
||||
var user = new User(userId, this);
|
||||
var joinedUsers = Object.keys(this.users);
|
||||
var spawnedPlayers = this.gameController.getSpawnedPlayersAndTheirPositions();
|
||||
|
|
@ -64,11 +77,11 @@
|
|||
spawnedPlayers: spawnedPlayers,
|
||||
worldUpdate: worldUpdate,
|
||||
levelUid: levelUid
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
NotificationCenter.trigger('user/' + user.id + "/joinSuccess", options);
|
||||
NotificationCenter.trigger('user/joined', user);
|
||||
}
|
||||
NotificationCenter.trigger('user/joined', user);
|
||||
};
|
||||
|
||||
Channel.prototype.onReleaseUser = function (userId) {
|
||||
var user = this.users[userId];
|
||||
|
|
|
|||
|
|
@ -5,12 +5,13 @@ define([
|
|||
"Game/Server/Control/PlayerController",
|
||||
"Lib/Utilities/RequestAnimFrame",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Game/Server/Player",
|
||||
"Game/Server/GameObjects/GameObject",
|
||||
"Game/Server/GameObjects/Doll"
|
||||
],
|
||||
|
||||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Player, GameObject, Doll) {
|
||||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Box2D, Player, GameObject, Doll) {
|
||||
|
||||
function GameController (channel) {
|
||||
|
||||
|
|
@ -22,7 +23,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
NotificationCenter.on('user/left', this.userLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
|
||||
NotificationCenter.on('user/resetLevel', this.onResetLevel, this);
|
||||
NotificationCenter.on('player/killed', this.spawnPlayer, this);
|
||||
NotificationCenter.on('game/level/loaded', this.onLevelLoaded, this);
|
||||
|
||||
console.checkpoint('starting game controller for channel ' + channel.name);
|
||||
|
||||
|
|
@ -43,6 +43,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
|
||||
GameController.prototype.onLevelLoaded = function() {
|
||||
Parent.prototype.onLevelLoaded.call(this);
|
||||
this.updateWorld();
|
||||
};
|
||||
|
||||
|
|
@ -95,7 +96,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
var body = this.physicsEngine.world.GetBodyList();
|
||||
do {
|
||||
if(getSleeping || body.IsAwake()) {
|
||||
if((getSleeping || body.IsAwake()) && body.GetType() === Box2D.Dynamics.b2Body.b2_dynamicBody) {
|
||||
var userData = body.GetUserData();
|
||||
|
||||
if (userData instanceof GameObject) {
|
||||
|
|
@ -125,11 +126,18 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
for(id in this.players) {
|
||||
var player = this.players[id];
|
||||
if(player.isSpawned) {
|
||||
spawnedPlayers.push({
|
||||
|
||||
var options = {
|
||||
id: id,
|
||||
x: player.getPosition().x * Settings.RATIO,
|
||||
y: player.getPosition().y * Settings.RATIO
|
||||
});
|
||||
};
|
||||
|
||||
if(player.holdingItem) {
|
||||
options.holdingItemUid = player.holdingItem.uid;
|
||||
}
|
||||
|
||||
spawnedPlayers.push(options);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue