mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
Refactored abstract method creation
This commit is contained in:
parent
1a71fa38f9
commit
7c783d19e8
6 changed files with 72 additions and 163 deletions
|
|
@ -2,6 +2,7 @@ define([
|
|||
"Game/Config/Settings",
|
||||
"Lib/Vendor/Box2D",
|
||||
"Lib/Utilities/NotificationCenter",
|
||||
"Lib/Utilities/Abstract",
|
||||
"Game/" + GLOBALS.context + "/Collision/Detector",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Tile",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Item",
|
||||
|
|
@ -9,7 +10,7 @@ define([
|
|||
"Game/" + GLOBALS.context + "/GameObjects/Items/RagDoll",
|
||||
"Game/" + GLOBALS.context + "/GameObjects/Items/Rube"
|
||||
|
||||
], function (Settings, Box2D, Nc, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) {
|
||||
], function (Settings, Box2D, Nc, Abstract, CollisionDetector, Tile, Item, Skateboard, RagDoll, Rube) {
|
||||
|
||||
function Level (uid, engine) {
|
||||
this.uid = uid;
|
||||
|
|
@ -19,19 +20,26 @@ define([
|
|||
this.load(this.uid);
|
||||
}
|
||||
|
||||
Abstract.prototype.addMethod.call(Level, "createTiles");
|
||||
Abstract.prototype.addMethod.call(Level, "createItems");
|
||||
Abstract.prototype.addMethod.call(Level, "addBackground");
|
||||
|
||||
Level.prototype.load = function (uid) {
|
||||
var self = this;
|
||||
var path = Settings.MAPS_PATH + uid + ".json"
|
||||
this.loadLevelDataFromPath(path, function(levelData) {
|
||||
self.levelData = levelData;
|
||||
self.addBackground();
|
||||
self.createTiles();
|
||||
self.createItems();
|
||||
self.isLoaded = true;
|
||||
Nc.trigger(Nc.ns.core.game.events.level.loaded);
|
||||
this.loadLevelDataFromPath(path, function (levelData) {
|
||||
self.setup(levelData);
|
||||
});
|
||||
}
|
||||
|
||||
Level.prototype.setup = function(levelData) {
|
||||
this.levelData = levelData;
|
||||
this.createTiles();
|
||||
this.createItems();
|
||||
this.isLoaded = true;
|
||||
Nc.trigger(Nc.ns.core.game.events.level.loaded);
|
||||
};
|
||||
|
||||
Level.prototype.createItem = function(uid, options) {
|
||||
switch(options.type) {
|
||||
//case 'skateboard':
|
||||
|
|
@ -54,55 +62,8 @@ define([
|
|||
};
|
||||
|
||||
Level.prototype.destroy = function () {
|
||||
/*
|
||||
for (var key in this.gameObjects) {
|
||||
for (var i = 0; i < this.gameObjects[key].length; i++) {
|
||||
this.gameObjects[key][i].destroy();
|
||||
}
|
||||
}
|
||||
*/
|
||||
this.isLoaded = false;
|
||||
}
|
||||
|
||||
/* Extended by TiledLevel
|
||||
Level.prototype.createTiles = function () {
|
||||
|
||||
if (!this.levelData || !this.levelData.tiles || this.levelData.tiles.length < 1) {
|
||||
throw "Level: Can't create physic tiles, no tiles found";
|
||||
}
|
||||
|
||||
var tiles = this.levelData.tiles;
|
||||
|
||||
for (var i = 0; i < tiles.length; i++) {
|
||||
var options = tiles[i];
|
||||
//options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil";
|
||||
options.m = "Soil";
|
||||
//this.gameObjects.fixed.push(
|
||||
new Tile(this.engine, "tile-" + i, options);
|
||||
//);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
/* Extended by TiledLevel
|
||||
Level.prototype.createItems = function() {
|
||||
if (!this.levelData || !this.levelData.items) {
|
||||
return;
|
||||
}
|
||||
var items = this.levelData.items;
|
||||
|
||||
for (var i = 0; i < items.length; i++) {
|
||||
var options = items[i];
|
||||
var uid = "item-" + i;
|
||||
var item = this.createItem(uid, options);
|
||||
//this.gameObjects.animated.push(item);
|
||||
};
|
||||
};
|
||||
|
||||
// Extended by TiledLevel
|
||||
Level.prototype.addBackground = function() {
|
||||
}
|
||||
*/
|
||||
|
||||
return Level;
|
||||
})
|
||||
Loading…
Add table
Add a link
Reference in a new issue