diff --git a/src/isometric/diamond-iso.js b/src/isometric/diamond-iso.js index 349ceba9..fba4ebc8 100644 --- a/src/isometric/diamond-iso.js +++ b/src/isometric/diamond-iso.js @@ -14,9 +14,6 @@ Crafty.extend({ width: 0, height: 0 }, - getTileDimensions: function(){ - return {w:this._tile.width,h:this._tile.height}; - }, _map: { width: 0, height: 0 @@ -25,28 +22,32 @@ Crafty.extend({ x: 0, y: 0 }, - _tiles: [], - getTile: function(x,y,z){ - return this._tiles[x][y][z]; - }, + _grid: [], + //false if there is no collision in this square + _collisionMap: [], + _tileLocations: {}, + //This looks totally random, but it lets the grid subdivide different parts of each tile into different integer Z layers so that entities can move + //smoothly across it. + _tileZSpacing: 6, /**@ * #Crafty.diamondIso.init * @comp Crafty.diamondIso - * @sign public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight) + * @sign public this Crafty.diamondIso.init(Number tileWidth,Number tileHeight,Number mapWidth,Number mapHeight, Number x, Number Y) * @param tileWidth - The size of base tile width's grid space in Pixel * @param tileHeight - The size of base tile height grid space in Pixel * @param mapWidth - The width of whole map in Tiles * @param mapHeight - The height of whole map in Tiles * @param x - the x coordinate of the TOP corner of the 0,0 tile - * @param y - the y coordinate of the TOP corner of the 0,0, tile + * @param y - the y coordinate of the TOP corner of the 0,0,tile * * Method used to initialize the size of the isometric placement. * Recommended to use a size alues in the power of `2` (128, 64 or 32). * This makes it easy to calculate positions and implement zooming. + * If TH isn't equal to TW*2, this won't work. * * @example * ~~~ - * var iso = Crafty.diamondIso.init(64,128,20,20); + * var iso = Crafty.diamondIso.init(64,128,20,20,0,0); * ~~~ * * @see Crafty.diamondIso.place @@ -59,99 +60,191 @@ Crafty.extend({ this._map.width = parseInt(mw, 10); this._map.height = parseInt(mh, 10) || parseInt(mw, 10); for (var i=0; i 0; + var hasTopLevelTile = this._grid[x][y][1].length >0; + if (hasTopLevelTile){ + topTileIsObstacle = this._grid[x][y][1][0].has("Obstacle"); + } else { + topTileIsObstacle = false; + } + var impassable = !hasGroundLevelTile || topTileIsObstacle; + this._collisionMap[x][y] = impassable; + }, + /**@ + * #Crafty.diamondIso.detachTile + * @comp Crafty.diamondIso + * @sign private [number x, number y] Crafty.diamondIso.detachTile(Entity obj) + * @param obj - the object to remove + * When passed an entity, removes that entity from the grid and returns its previous location. + * Does not delete the tile. + */ detachTile: function(obj){ - for (var _x=0; _x