mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
implemented level load, more to do see #1
This commit is contained in:
parent
b02036a019
commit
953159e6bd
12 changed files with 333 additions and 409 deletions
|
|
@ -18,14 +18,16 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
|
||||
Parent.call(this);
|
||||
|
||||
this.updateWorld();
|
||||
|
||||
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/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);
|
||||
|
||||
var nextUid = this.getNextLevelUid();
|
||||
this.loadLevel(nextUid);
|
||||
}
|
||||
|
||||
GameController.prototype = Object.create(Parent.prototype);
|
||||
|
|
@ -40,6 +42,10 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
}
|
||||
|
||||
GameController.prototype.onLevelLoaded = function() {
|
||||
this.updateWorld();
|
||||
};
|
||||
|
||||
GameController.prototype.userJoined = function (user) {
|
||||
Parent.prototype.userJoined.call(this, user);
|
||||
var player = this.players[user.id];
|
||||
|
|
@ -137,6 +143,23 @@ function (Parent, PhysicsEngine, Settings, PlayerController, requestAnimFrame, N
|
|||
}
|
||||
};
|
||||
|
||||
GameController.prototype.getNextLevelUid = function() {
|
||||
if(!this.level) return this.channel.options.levelUids[0];
|
||||
|
||||
var levelCount = this.channel.options.levelUids.length;
|
||||
|
||||
for (var i = 0; i < levelCount; i++) {
|
||||
var uid = this.channel.options.levelUids[i];
|
||||
if(uid == this.level.uid) {
|
||||
break;
|
||||
}
|
||||
};
|
||||
|
||||
var next = i + 1;
|
||||
|
||||
return this.channel.options.levelUids[next % levelCount];
|
||||
};
|
||||
|
||||
|
||||
return GameController;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue