diff --git a/app/Game/Config/Settings.js b/app/Game/Config/Settings.js index fa88c81..dbeb854 100755 --- a/app/Game/Config/Settings.js +++ b/app/Game/Config/Settings.js @@ -10,11 +10,12 @@ define({ BOX2D_POSITION_ITERATIONS: 5, BOX2D_TIME_STEP: 1 / 60, - // GRAPHIC PATHS + // PATHS GRAPHICS_PATH: 'static/img/', GRAPHICS_SUBPATH_ITEMS: 'Items/', GRAPHICS_SUBPATH_CHARACTERS: 'Characters/', GRAPHICS_SUBPATH_TILES: 'Tiles/', + MAPS_PATH: 'static/maps/' RATIO: 21, //35 TILE_SIZE: 15, //15, 25 is original picture diff --git a/app/Game/Core/Loader/Level.js b/app/Game/Core/Loader/Level.js index a23a937..74791b5 100755 --- a/app/Game/Core/Loader/Level.js +++ b/app/Game/Core/Loader/Level.js @@ -16,10 +16,12 @@ define([ this.gameObjects = gameObjects; } - Level.prototype.loadLevelInToEngine = function () { - this.loadLevelObjectFromPath(this.path); - this.createTiles(); - this.createItems(); + Level.prototype.loadLevelInToEngine = function (callback) { + this.loadLevelObjectFromPath(this.path, function(levelData){ + this.createTiles(levelData); + this.createItems(levelData); + callback(); + }); } Level.prototype.destroy = function () { @@ -33,22 +35,26 @@ define([ // Private - Level.prototype.createTiles = function () { - if (!this.levelObject || !this.levelObject.tiles || this.levelObject.tiles.length < 1) { + Level.prototype.createTiles = function (levelData) { + + if (!levelData || !levelData.tiles || levelData.tiles.length < 1) { throw "Level: Can't create physic tiles, no tiles found"; } - var tiles = this.levelObject.tiles; + var tiles = 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 = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil"; this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options)); } } Level.prototype.createItems = function() { - var items = this.levelObject.items; + if (!levelData || !levelData.tiles) { + return; + } + var items = levelData.items; for (var i = 0; i < items.length; i++) { var options = items[i]; @@ -358,6 +364,7 @@ microwave: 3.744 } // TODO remove hack + /* Level.prototype.tileAtPositionExists = function(x, y) { for (var i = 0; i < this.levelObject.tiles.length; i++) { @@ -366,6 +373,7 @@ microwave: 3.744 } return false; }; + */ return Level; }) \ No newline at end of file diff --git a/app/Game/Core/Loader/TiledLevel.js b/app/Game/Core/Loader/TiledLevel.js new file mode 100755 index 0000000..ccde020 --- /dev/null +++ b/app/Game/Core/Loader/TiledLevel.js @@ -0,0 +1,46 @@ +define([ + "Game/Config/Settings", + "Lib/Vendor/Box2D", + "Game/" + GLOBALS.context + "/Collision/Detector", + "Game/" + GLOBALS.context + "/GameObjects/Tile", + "Game/" + GLOBALS.context + "/GameObjects/Item", + "Game/" + GLOBALS.context + "/GameObjects/Items/Skateboard", + +], function (Settings, Box2D, CollisionDetector, Tile, Item, Skateboard) { + + // Public + function Level (path, engine, gameObjects) { + this.path = path; + this.engine = engine; + this.levelObject = null; + this.gameObjects = gameObjects; + } + + Level.prototype.loadLevelInToEngine = function () { + this.loadLevelObjectFromPath(this.path); + this.createTiles(); + //this.createItems(); + } + + // Private + + Level.prototype.createTiles = function () { + if (!this.levelObject || !this.levelObject.tiles || this.levelObject.tiles.length < 1) { + throw "Level: Can't create physic tiles, no tiles found"; + } + + var tiles = this.levelObject.tiles; + + for (var i = 0; i < tiles.length; i++) { + var options = tiles[i]; + options.m = this.tileAtPositionExists(options.x, options.y - 1) ? "Soil" : "GrassSoil"; + this.gameObjects.fixed.push(new Tile(this.engine, "tile-" + i, options)); + } + } + + Level.prototype.loadLevelObjectFromPath = function (path) { + + } + + return Level; +}) \ No newline at end of file diff --git a/app/Game/Server/Loader/Level.js b/app/Game/Server/Loader/Level.js index dbf60f5..547ac4a 100755 --- a/app/Game/Server/Loader/Level.js +++ b/app/Game/Server/Loader/Level.js @@ -1,9 +1,25 @@ define([ - "Game/Core/Loader/Level" + "Game/Core/Loader/Level", + "Game/Config/Settings" + "fs" ], - -function(Parent) { - - return Parent; - + +function (Parent, Fs) { + + function Level () { + Parent.call(this); + } + + Level.prototype = Object.create(Parent.prototype); + + Level.prototype.loadLevelObjectFromPath = function (path, callback) { + // overwriting parent + + fs.readFile( + path, function (err, data) { + if (err) throw err; + callback(data); + }); + } + + return Level; }); \ No newline at end of file diff --git a/static/img/Characters/Chuck/chuck-hats.psd b/static/img/Characters/Chuck/chuck-hats.psd new file mode 100644 index 0000000..189cc3f Binary files /dev/null and b/static/img/Characters/Chuck/chuck-hats.psd differ