begin Round Bug improvements, player renders doll. fixes #64

This commit is contained in:
logsol 2014-05-24 17:39:19 +02:00
parent 55b56f9c12
commit c18384f502
11 changed files with 76 additions and 42 deletions

View file

@ -28,7 +28,7 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
Nc.on(Nc.ns.channel.events.user.level.reset, this.onResetLevel, this), Nc.on(Nc.ns.channel.events.user.level.reset, this.onResetLevel, this),
Nc.on(Nc.ns.channel.events.user.client.ready, this.onClientReady, this), Nc.on(Nc.ns.channel.events.user.client.ready, this.onClientReady, this),
Nc.on(Nc.ns.core.game.events.level.loaded, this.onLevelLoaded, this), Nc.on(Nc.ns.core.game.events.level.loaded, this.onLevelLoaded, this),
Nc.on(Nc.ns.core.game.player.killed, this.onPlayerKilled, this), // FIXME: move to events Nc.on(Nc.ns.channel.events.game.player.killed, this.onPlayerKilled, this),
]); ]);
console.checkpoint('starting game controller for channel (' + options.channelName + ')'); console.checkpoint('starting game controller for channel (' + options.channelName + ')');
@ -66,8 +66,9 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
GameController.prototype.onPlayerKilled = function(player, killedByPlayer) { GameController.prototype.onPlayerKilled = function(player, killedByPlayer) {
if(killedByPlayer.stats.score >= this.options.scoreLimit) { if(killedByPlayer.stats.score >= this.options.scoreLimit) {
Nc.trigger(Nc.ns.channel.events.round.end); Nc.trigger(Nc.ns.channel.events.round.end);
} else {
this.spawnPlayer(player, Settings.RESPAWN_TIME);
} }
this.spawnPlayer(player, Settings.RESPAWN_TIME);
}; };
GameController.prototype.spawnPlayer = function(player, respawnTime) { GameController.prototype.spawnPlayer = function(player, respawnTime) {
@ -186,7 +187,6 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
GameController.prototype.onClientReady = function(userId) { GameController.prototype.onClientReady = function(userId) {
var player = this.players[userId]; var player = this.players[userId];
this.spawnPlayer(player, 0);
var options = { var options = {
spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(), spawnedPlayers: this.getSpawnedPlayersAndTheirPositions(),
@ -196,9 +196,14 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
} }
Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + userId, "clientReadyResponse", options); Nc.trigger(Nc.ns.channel.to.client.user.gameCommand.send + userId, "clientReadyResponse", options);
this.spawnPlayer(player, 0);
}; };
GameController.prototype.onResetLevel = function(userId) { GameController.prototype.onResetLevel = function(userId) {
console.log('OH NO!!! ON RESET LEVEL IS CALLED AND RESPAWNES PLAYERS');
Parent.prototype.onResetLevel.call(this); Parent.prototype.onResetLevel.call(this);
Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "resetLevel", true); Nc.trigger(Nc.ns.channel.to.client.gameCommand.broadcast, "resetLevel", true);
for (var key in this.players) { for (var key in this.players) {

View file

@ -66,7 +66,7 @@ function (Parent, Nc) {
if(this.stats.health < 0) this.stats.health = 0; if(this.stats.health < 0) this.stats.health = 0;
if(this.stats.health <= 0) { if(this.stats.health <= 0) {
/*if(enemy != this) for testing! */ enemy.score(); /*if(enemy != this) self killing scores for testing! */ enemy.score();
this.kill(enemy); this.kill(enemy);
} else { } else {
this.broadcastStats(); this.broadcastStats();
@ -91,6 +91,8 @@ function (Parent, Nc) {
ragDollId: ragDollId ragDollId: ragDollId
}); });
Nc.trigger(Nc.ns.channel.events.game.player.killed, this, killedByPlayer); // sends endround
if(this.ragDoll) { if(this.ragDoll) {
this.ragDoll.delayedDestroy(); this.ragDoll.delayedDestroy();
} }

View file

@ -9,10 +9,11 @@ define([
"Game/Config/Settings", "Game/Config/Settings",
"Game/Client/GameObjects/GameObject", "Game/Client/GameObjects/GameObject",
"Game/Client/GameObjects/Doll", "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) { if (!window.cancelAnimationFrame) {
window.cancelAnimationFrame = function(id) { window.cancelAnimationFrame = function(id) {
@ -20,8 +21,9 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
}; };
} }
function GameController (options) { function GameController (options) {
this.clientIsReady = false;
this.view = ViewManager.createView(); this.view = ViewManager.createView();
this.me = null; this.me = null;
this.animationRequestId = null; this.animationRequestId = null;
@ -64,12 +66,6 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
GameController.prototype.onClientReadyResponse = function(options) { 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) { if (options.worldUpdate) {
this.onWorldUpdate(options.worldUpdate); this.onWorldUpdate(options.worldUpdate);
} }
@ -88,12 +84,19 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
if(!alreadyExists) { if(!alreadyExists) {
var item = this.level.createItem(itemDef.uid, itemDef.options); var item = this.level.createItem(itemDef.uid, itemDef.options);
//this.onGameObjectAdd("animated", item);
} }
}; };
} }
this.createMe(options.userId); 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) { GameController.prototype.onWorldUpdate = function (updateData) {
@ -128,14 +131,23 @@ function (Parent, Box2D, PhysicsEngine, ViewManager, PlayerController, Nc, reque
this.view.setMe(this.me); this.view.setMe(this.me);
} }
GameController.prototype.onGameCommand = function(message) {
ProtocolHelper.applyCommand(message, this);
};
GameController.prototype.onSpawnPlayer = function(options) { GameController.prototype.onSpawnPlayer = function(options) {
if(!this.clientIsReady) {
return;
}
var playerId = options.id, var playerId = options.id,
x = options.x, x = options.x,
y = options.y; y = options.y;
var player = this.players[playerId]; var player = this.players[playerId];
player.spawn(x, y); player.spawn(x, y);
this.gameObjects.animated.push(player); this.onGameObjectAdd('animated', player);
if(options.holdingItemUid) { if(options.holdingItemUid) {
this.onHandActionResponse({ this.onHandActionResponse({

View file

@ -20,8 +20,12 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
var self = this; var self = this;
this.socketLink.on('message', function (message) { this.socketLink.on('message', function (message) {
var m = JSON.parse(message) var m = JSON.parse(message)
if(Settings.NETWORK_LOG_INCOMING && !m.gameCommand) { if(Settings.NETWORK_LOG_INCOMING) {
console.log('INCOMING', message);
if (message.indexOf('worldUpdate') == -1 && message.indexOf('pong') == -1) {
console.log('INCOMING', message);
}
} }
ProtocolHelper.applyCommand(message, self); ProtocolHelper.applyCommand(message, self);
}); });
@ -147,7 +151,7 @@ function (ProtocolHelper, GameController, User, Nc, Settings, DomController) {
} }
Networker.prototype.onGameCommand = function(message) { Networker.prototype.onGameCommand = function(message) {
ProtocolHelper.applyCommand(message, this.gameController); this.gameController.onGameCommand(message);
} }
Networker.prototype.onPong = function(timestamp) { Networker.prototype.onPong = function(timestamp) {

View file

@ -87,7 +87,9 @@ function (Parent, Nc, Settings) {
Player.prototype.render = function() { Player.prototype.render = function() {
// dolls are self responsible if(this.doll) {
this.doll.render();
}
if(this.playerInfoViewVisible) { if(this.playerInfoViewVisible) {
var position = this.getPosition(); var position = this.getPosition();

View file

@ -63,12 +63,12 @@ define(function() {
// NETWORKING // NETWORKING
WORLD_UPDATE_BROADCAST_INTERVAL: 70, WORLD_UPDATE_BROADCAST_INTERVAL: 70,
CHANNEL_DESTRUCTION_TIME: 30, CHANNEL_DESTRUCTION_TIME: 30,
NETWORK_LOG_INCOMING: false, NETWORK_LOG_INCOMING: true,
NETWORK_LOG_OUTGOING: true, NETWORK_LOG_OUTGOING: false,
NETWORK_LOG_FILTER: ['ping', 'pong', 'worldUpdate', 'lookAt'], NETWORK_LOG_FILTER: ['ping', 'pong', 'worldUpdate', 'lookAt'],
// CHANNEL // CHANNEL
CHANNEL_END_ROUND_TIME: 10, CHANNEL_END_ROUND_TIME: 4, //10,
CHANNEL_DEFAULT_MAX_USERS: 40, CHANNEL_DEFAULT_MAX_USERS: 40,
CHANNEL_DEFAULT_SCORE_LIMIT: 10, CHANNEL_DEFAULT_SCORE_LIMIT: 10,
CHANNEL_DEFAULT_LEVELS: ['stones2', 'debug', 'stones2', 'debug'] CHANNEL_DEFAULT_LEVELS: ['stones2', 'debug', 'stones2', 'debug']

View file

@ -2,10 +2,11 @@ define([
"Game/" + GLOBALS.context + "/Physics/Engine", "Game/" + GLOBALS.context + "/Physics/Engine",
"Game/" + GLOBALS.context + "/Loader/TiledLevel", "Game/" + GLOBALS.context + "/Loader/TiledLevel",
"Game/" + GLOBALS.context + "/Player", "Game/" + GLOBALS.context + "/Player",
"Lib/Utilities/NotificationCenter" "Lib/Utilities/NotificationCenter",
"Game/" + GLOBALS.context + "/GameObjects/Doll",
], ],
function (PhysicsEngine, TiledLevel, Player, Nc) { function (PhysicsEngine, TiledLevel, Player, Nc, Doll) {
function GameController (options) { function GameController (options) {
@ -79,8 +80,7 @@ function (PhysicsEngine, TiledLevel, Player, Nc) {
return; return;
} }
var i = this.gameObjects.animated.indexOf(player); this.onGameObjectRemove('animated', player);
if(i>=0) this.gameObjects.animated.splice(i, 1);
player.destroy(); player.destroy();
delete this.players[userId]; delete this.players[userId];
@ -105,14 +105,24 @@ function (PhysicsEngine, TiledLevel, Player, Nc) {
Nc.off(this.ncTokens[i]); Nc.off(this.ncTokens[i]);
}; };
/*
* Contents of gameObject: Players, Items, Tiles, RagDolls
* No Dolls.
*/
for (var key in this.gameObjects) { for (var key in this.gameObjects) {
for (var i = 0; i < this.gameObjects[key].length; i++) { for (var i = 0; i < this.gameObjects[key].length; i++) {
var gameObject = this.gameObjects[key][i]; var gameObject = this.gameObjects[key][i];
this.onGameObjectRemove(key, gameObject);
gameObject.destroy(); gameObject.destroy();
}; };
}; };
this.gameObjects = {
fixed: [],
animated: []
};
this.physicsEngine.destroy(); this.physicsEngine.destroy();
} }

View file

@ -38,7 +38,6 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
this.createFixtures(); this.createFixtures();
this.body.SetActive(false); this.body.SetActive(false);
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
} }
Doll.prototype = Object.create(Parent.prototype); Doll.prototype = Object.create(Parent.prototype);
@ -372,7 +371,6 @@ function (Parent, Box2D, Settings, CollisionDetector, Item, Nc) {
}; };
Doll.prototype.destroy = function() { Doll.prototype.destroy = function() {
Nc.trigger(Nc.ns.core.game.gameObject.remove, 'animated', this);
}; };
return Doll; return Doll;

View file

@ -161,9 +161,6 @@ function (Parent, Box2D, Settings, Nc) {
0, 0,
options.limbs.upperRightArm.height / 2 options.limbs.upperRightArm.height / 2
); );
Nc.trigger(Nc.ns.core.game.gameObject.add, 'animated', this);
} }
RagDoll.prototype = Object.create(Parent.prototype); RagDoll.prototype = Object.create(Parent.prototype);

View file

@ -99,7 +99,7 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.throw(0, 0, this.holdingItem) this.throw(0, 0, this.holdingItem)
} }
// get forces // prepare for creating the ragdoll
var options = { var options = {
x: this.getPosition().x * Settings.RATIO, x: this.getPosition().x * Settings.RATIO,
y: this.getPosition().y * Settings.RATIO, y: this.getPosition().y * Settings.RATIO,
@ -123,9 +123,6 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
this.doll = null; this.doll = null;
this.ragDoll = ragDoll; this.ragDoll = ragDoll;
Nc.trigger(Nc.ns.core.game.player.killed, this, killedByPlayer);
}; };
Player.prototype.update = function () { Player.prototype.update = function () {
@ -145,9 +142,14 @@ function (Doll, Settings, Nc, Exception, SpectatorDoll, RagDoll) {
} }
this.spectatorDoll.destroy(); this.spectatorDoll.destroy();
if(this.doll) this.doll.destroy();
this.playerController.destroy(); if(this.doll) {
this.doll.destroy();
}
if(this.playerController) {
this.playerController.destroy();
}
} }
Player.prototype.setPlayerController = function(playerController) { Player.prototype.setPlayerController = function(playerController) {

View file

@ -79,9 +79,6 @@ function (Exception) {
add: null, add: null,
remove: null remove: null
}, },
player: {
killed: null
},
events: { events: {
level: { level: {
loaded: null loaded: null
@ -107,6 +104,11 @@ function (Exception) {
}, },
round: { round: {
end: null end: null
},
game: {
player: {
killed: null
}
} }
}, },
engine: { engine: {
@ -231,5 +233,5 @@ function (Exception) {
} }
return new NotificationCenter(); // making it singletone return new NotificationCenter(); // making it singleton
}); });