implemented level load, more to do see #1

This commit is contained in:
Jeena 2014-01-29 03:24:08 +01:00
parent b02036a019
commit 953159e6bd
12 changed files with 333 additions and 409 deletions

View file

@ -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;
});