mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added layers
This commit is contained in:
parent
7c783d19e8
commit
d29c64385d
4 changed files with 142 additions and 108 deletions
|
|
@ -18,12 +18,9 @@ define([
|
|||
this.levelObject = null;
|
||||
this.isLoaded = false;
|
||||
this.load(this.uid);
|
||||
this.spawnPoints = null;
|
||||
}
|
||||
|
||||
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"
|
||||
|
|
@ -33,13 +30,17 @@ define([
|
|||
}
|
||||
|
||||
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.createItems = function(options) {
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
var uid = "item-" + i;
|
||||
this.createItem(uid, options[i]);
|
||||
};
|
||||
};
|
||||
|
||||
Level.prototype.createItem = function(uid, options) {
|
||||
switch(options.type) {
|
||||
//case 'skateboard':
|
||||
|
|
@ -53,14 +54,33 @@ define([
|
|||
}
|
||||
};
|
||||
|
||||
Level.prototype.getRandomSpawnPoint = function() {
|
||||
throw new Error("Level not loaded.");
|
||||
return {
|
||||
x: 150 + Math.random() * 300,
|
||||
y: -500
|
||||
Level.prototype.createTiles = function(options) {
|
||||
for (var i = 0; i < options.length; i++) {
|
||||
new Tile(this.engine, "tile-" + i, options[i]);
|
||||
};
|
||||
};
|
||||
|
||||
Level.prototype.createSpawnPoints = function(points) {
|
||||
this.spawnPoints = points;
|
||||
};
|
||||
|
||||
Level.prototype.getRandomSpawnPoint = function() {
|
||||
if(!this.spawnPoints) {
|
||||
return {
|
||||
x: 150 + Math.random() * 300,
|
||||
y: -500
|
||||
};
|
||||
}
|
||||
|
||||
var size = this.spawnPoints.length;
|
||||
var object = this.spawnPoints[parseInt(Math.random() * (size -1), 10)];
|
||||
|
||||
return {
|
||||
x: object.x / Settings.TILE_RATIO,
|
||||
y: object.y / Settings.TILE_RATIO
|
||||
}
|
||||
};
|
||||
|
||||
Level.prototype.destroy = function () {
|
||||
this.isLoaded = false;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue