implemented clientReady and changed loading of assets, fixed unique ragdoll id

This commit is contained in:
Jeena 2014-02-24 17:41:01 +01:00
parent f578b92734
commit 695008afd8
278 changed files with 306 additions and 287 deletions

View file

@ -60,8 +60,6 @@
Channel.prototype.sendJoinSuccess = function(userId) {
var user = new User(userId, this);
var joinedUsers = Object.keys(this.users);
var spawnedPlayers = this.gameController.getSpawnedPlayersAndTheirPositions();
var worldUpdate = this.gameController.getWorldUpdateObject(true);
var levelUid = null;
if(this.gameController.level) {
@ -74,8 +72,6 @@
userId: user.id,
channelName: this.name,
joinedUsers: joinedUsers,
spawnedPlayers: spawnedPlayers,
worldUpdate: worldUpdate,
levelUid: levelUid
};

View file

@ -19,10 +19,11 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Parent.call(this);
NotificationCenter.on('user/joined', this.userJoined, this);
NotificationCenter.on('user/left', this.userLeft, this); // FIXME: refactor this.userLeft -> this.onUserLeft, even in core and client
NotificationCenter.on('user/joined', this.onUserJoined, this);
NotificationCenter.on('user/left', this.onUserLeft, 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('user/clientReady', this.onClientReady, this);
NotificationCenter.on('player/killed', this.onPlayerKilled, this);
console.checkpoint('starting game controller for channel ' + channel.name);
@ -49,13 +50,20 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
this.updateWorld();
};
GameController.prototype.userJoined = function (user) {
Parent.prototype.userJoined.call(this, user);
var player = this.players[user.id];
user.setPlayer(player);
this.spawnPlayer(player, 0);
GameController.prototype.onUserJoined = function (user) {
this.createPlayer(user);
}
GameController.prototype.createPlayer = function(user) {
var player = Parent.prototype.createPlayer.call(this, user);
player.setPlayerController(new PlayerController(player))
user.setPlayer(player);
};
GameController.prototype.onPlayerKilled = function(player, respawnTime) {
this.spawnPlayer(player, respawnTime);
};
GameController.prototype.spawnPlayer = function(player, respawnTime) {
var self = this;
var spawnPoint = this.level.getRandomSpawnPoint();
@ -81,12 +89,14 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
}, respawnTime * 1000);
};
/*
GameController.prototype.createPlayer = function(user) {
var player = new Player(user.id, this.physicsEngine);
player.setPlayerController(new PlayerController(player))
return player;
};
*/
GameController.prototype.updateWorld = function () {
@ -154,6 +164,40 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
return spawnedPlayers;
};
GameController.prototype.getAdditionalObjects = 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];
objects.push({
uid: objects.uid,
options: object.options,
x: object.getPosition().x,
y: object.getPosition().y
});
}
};
var object = {
// FIXME: finish it!
}
return objects;
};
GameController.prototype.onClientReady = function(userId) {
var player = this.players[userId];
this.spawnPlayer(player, 0);
var options = {
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
worldUpdate: this.getWorldUpdateObject(true),
userId: userId
}
NotificationCenter.trigger('user/' + userId + "/gameCommand", "clientReadyResponse", options);
};
GameController.prototype.onResetLevel = function(userId) {
Parent.prototype.onResetLevel.call(this);
NotificationCenter.trigger("broadcastControlCommand", "gameCommand", {resetLevel:true});

View file

@ -80,12 +80,15 @@ function (Parent, NotificationCenter) {
};
Player.prototype.kill = function(killedByPlayer) {
Parent.prototype.kill.call(this, killedByPlayer);
this.stats.deaths++;
var ragDollId = this.stats.deaths;
Parent.prototype.kill.call(this, killedByPlayer, ragDollId);
this.broadcastStats();
NotificationCenter.trigger("broadcastGameCommand", "playerKill", {
playerId: this.id,
killedByPlayerId: killedByPlayer.id
killedByPlayerId: killedByPlayer.id,
ragDollId: ragDollId
});
if(this.ragDoll) {

View file

@ -50,9 +50,12 @@ function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
if(command.hasOwnProperty("resetLevel")) {
NotificationCenter.trigger("user/resetLevel", this.id);
} else if(command.hasOwnProperty("clientReady")) {
NotificationCenter.trigger("user/clientReady", this.id);
} else {
this.player.playerController.applyCommand(command);
}
};