first attempt to implement tiled style maps

This commit is contained in:
logsol 2014-01-28 21:34:46 +01:00
parent 3c8d3d3d8e
commit b02036a019
5 changed files with 87 additions and 16 deletions

View file

@ -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

View file

@ -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;
})

View file

@ -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;
})

View file

@ -1,9 +1,25 @@
define([
"Game/Core/Loader/Level"
"Game/Core/Loader/Level",
"Game/Config/Settings"
"fs"
],
function(Parent) {
function (Parent, Fs) {
return Parent;
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;
});

Binary file not shown.