chuck.js/app/Game/Core/GameController.js

70 lines
1.7 KiB
JavaScript
Executable file

define([
"Game/" + GLOBALS.context + "/Physics/Engine",
"Game/" + GLOBALS.context + "/Loader/TiledLevel",
"Game/" + GLOBALS.context + "/Player"
],
function (PhysicsEngine, TiledLevel, Player) {
function GameController () {
this.players = {};
this.level = null;
this.gameObjects = {
animated: [],
fixed: []
};
this.physicsEngine = new PhysicsEngine();
this.physicsEngine.setCollisionDetector();
this.update();
}
GameController.prototype.update = function() {
};
GameController.prototype.getPhysicsEngine = function () {
return this.physicsEngine;
}
GameController.prototype.loadLevel = function (levelUid) {
if (this.level) {
this.level.destroy();
this.gameObjects = {
animated: [],
fixed: []
};
}
this.level = new TiledLevel(levelUid, this.physicsEngine, this.gameObjects);
}
GameController.prototype.onResetLevel = function() {
this.loadLevel(this.level.uid);
};
GameController.prototype.destroy = function () {
for(var player in this.players) {
this.players[player].destroy();
}
}
GameController.prototype.userJoined = function (user) {
this.players[user.id] = this.createPlayer(user);
}
GameController.prototype.userLeft = function (user) {
var player = this.players[user.id];
player.destroy();
delete this.players[user.id];
}
GameController.prototype.createPlayer = function(user) {
return new Player(user.id, this.physicsEngine);
};
return GameController;
});