mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
fixed #38
This commit is contained in:
parent
7a59e175e0
commit
89c5e4a5d8
6 changed files with 64 additions and 25 deletions
|
|
@ -1,10 +1,11 @@
|
|||
define([
|
||||
"Game/" + GLOBALS.context + "/Physics/Engine",
|
||||
"Game/" + GLOBALS.context + "/Loader/TiledLevel",
|
||||
"Game/" + GLOBALS.context + "/Player"
|
||||
"Game/" + GLOBALS.context + "/Player",
|
||||
"Lib/Utilities/NotificationCenter"
|
||||
],
|
||||
|
||||
function (PhysicsEngine, TiledLevel, Player) {
|
||||
function (PhysicsEngine, TiledLevel, Player, NotificationCenter) {
|
||||
|
||||
function GameController () {
|
||||
this.players = {};
|
||||
|
|
@ -17,7 +18,7 @@ function (PhysicsEngine, TiledLevel, Player) {
|
|||
this.physicsEngine = new PhysicsEngine();
|
||||
this.physicsEngine.setCollisionDetector();
|
||||
|
||||
this.update();
|
||||
NotificationCenter.on("game/level/loaded", this.onLevelLoaded, this);
|
||||
}
|
||||
|
||||
GameController.prototype.update = function() {
|
||||
|
|
@ -45,6 +46,10 @@ function (PhysicsEngine, TiledLevel, Player) {
|
|||
this.loadLevel(this.level.uid);
|
||||
};
|
||||
|
||||
GameController.prototype.onLevelLoaded = function() {
|
||||
this.update();
|
||||
};
|
||||
|
||||
|
||||
GameController.prototype.destroy = function () {
|
||||
for(var player in this.players) {
|
||||
|
|
|
|||
|
|
@ -2,18 +2,20 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Exception",
|
||||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard"
|
||||
|
||||
], function (Settings, Box2D, NotificationCenter, CollisionDetector, Tile, Item, Skateboard) {
|
||||
], function (Settings, Box2D, NotificationCenter, Exception, CollisionDetector, Tile, Item, Skateboard) {
|
||||
|
||||
function Level (uid, engine, gameObjects) {
|
||||
this.uid = uid;
|
||||
this.engine = engine;
|
||||
this.levelObject = null;
|
||||
this.gameObjects = gameObjects;
|
||||
this.isLoaded = false;
|
||||
this.load(this.uid);
|
||||
}
|
||||
|
||||
|
|
@ -24,6 +26,7 @@ define([
|
|||
self.levelData = levelData;
|
||||
self.createTiles();
|
||||
self.createItems();
|
||||
self.isLoaded = true;
|
||||
NotificationCenter.trigger("game/level/loaded");
|
||||
});
|
||||
}
|
||||
|
|
@ -33,8 +36,8 @@ define([
|
|||
for (var i = 0; i < this.gameObjects[key].length; i++) {
|
||||
this.gameObjects[key][i].destroy();
|
||||
}
|
||||
//this.gameObjects[key] = [];
|
||||
}
|
||||
this.isLoaded = false;
|
||||
}
|
||||
|
||||
Level.prototype.createTiles = function () {
|
||||
|
|
@ -77,9 +80,10 @@ define([
|
|||
};
|
||||
|
||||
Level.prototype.getRandomSpawnPoint = function() {
|
||||
throw new Error("Level not loaded.");
|
||||
return {
|
||||
x: 150 + Math.random() * 300,
|
||||
y: 0
|
||||
y: -500
|
||||
};
|
||||
};
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue