mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 18:47:35 +00:00
implemented level restart
This commit is contained in:
parent
81611050d2
commit
3edd664412
12 changed files with 104 additions and 47 deletions
|
|
@ -17,6 +17,8 @@ function(Parent, NotificationCenter, Parser) {
|
|||
* retrieves move (and other) commands from client and executes them at the server
|
||||
*/
|
||||
PlayerController.prototype.applyCommand = function(options) {
|
||||
// FIXME: remove this function and use ProtocolHelper.applyCommand() instead
|
||||
// Don't forget to change the function names to on...
|
||||
var message;
|
||||
if (typeof options == "string") {
|
||||
message = Parser.decode(options);
|
||||
|
|
|
|||
|
|
@ -13,17 +13,16 @@ define([
|
|||
function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, NotificationCenter, Player, GameObject, Doll) {
|
||||
|
||||
function GameController (channel) {
|
||||
Parent.call(this, new PhysicsEngine());
|
||||
|
||||
this.physicsEngine.setCollisionDetector();
|
||||
|
||||
|
||||
this.channel = channel;
|
||||
|
||||
this.update();
|
||||
Parent.call(this);
|
||||
|
||||
this.updateWorld();
|
||||
|
||||
NotificationCenter.on('user/joined', this.userJoined, this);
|
||||
NotificationCenter.on('user/left', this.userLeft, this);
|
||||
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);
|
||||
|
||||
console.checkpoint('starting game controller for channel ' + channel.name);
|
||||
}
|
||||
|
|
@ -48,9 +47,10 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
|
||||
GameController.prototype.spawnPlayer = function(player) {
|
||||
var x = 150,
|
||||
var x = 150 + Math.random() * 300,
|
||||
y = 50;
|
||||
player.spawn(x, y);
|
||||
this.gameObjects.animated.push(player.getDoll());
|
||||
|
||||
var message = {
|
||||
spawnPlayer: {
|
||||
|
|
@ -128,6 +128,14 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
return spawnedPlayers;
|
||||
};
|
||||
|
||||
GameController.prototype.onResetLevel = function(userId) {
|
||||
Parent.prototype.onResetLevel.call(this);
|
||||
NotificationCenter.trigger("sendControlCommandToAllUsers", "gameCommand", {resetLevel:true});
|
||||
for (var key in this.players) {
|
||||
this.spawnPlayer(this.players[key]);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
return GameController;
|
||||
});
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
define([
|
||||
"Game/Core/User",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Protocol/Helper"
|
||||
"Lib/Utilities/Protocol/Helper",
|
||||
"Lib/Utilities/Protocol/Parser",
|
||||
],
|
||||
|
||||
function(Parent, NotificationCenter, ProtocolHelper) {
|
||||
function(Parent, NotificationCenter, ProtocolHelper, ProtocolParser) {
|
||||
|
||||
function User(id, channel) {
|
||||
Parent.call(this, id);
|
||||
|
|
@ -38,7 +39,16 @@ function(Parent, NotificationCenter, ProtocolHelper) {
|
|||
// User command callbacks
|
||||
|
||||
User.prototype.onGameCommand = function(command) {
|
||||
this.player.playerController.applyCommand(command);
|
||||
|
||||
if (typeof command == "string") {
|
||||
command = ProtocolParser.decode(command);
|
||||
} // FIXME: move this to Protocol helper as a function
|
||||
|
||||
if(command.hasOwnProperty("resetLevel")) {
|
||||
NotificationCenter.trigger("user/resetLevel", this.id);
|
||||
} else {
|
||||
this.player.playerController.applyCommand(command);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue