summaryrefslogtreecommitdiff
path: root/jaws/jaws.js
diff options
context:
space:
mode:
authorMichele Bini <michele.bini@gmail.com>2014-10-05 14:38:17 (GMT)
committerMichele Bini <michele.bini@gmail.com>2014-10-05 14:38:17 (GMT)
commit26e282e626be8d16eb40fe1ddf4454f96037a3e1 (patch)
tree5711a4aa5c679d24b3bfeddb90b1f88b371347eb /jaws/jaws.js
parent251eb1a64f07b5267ddc6a15c9cc1b1187dfe53e (diff)
jaws: Remove tilemap support
Diffstat (limited to 'jaws/jaws.js')
-rwxr-xr-x[-rw-r--r--]jaws/jaws.js217
1 files changed, 2 insertions, 215 deletions
diff --git a/jaws/jaws.js b/jaws/jaws.js
index 6c6be90..ac9c43e 100644..100755
--- a/jaws/jaws.js
+++ b/jaws/jaws.js
@@ -1,4 +1,4 @@
-/* Built at: Sun Oct 05 2014 13:16:46 GMT+0200 (CEST) */
+/* Built at: Sun Oct 05 2014 16:27:46 GMT+0200 (CEST) */
/**
* @namespace JawsJS core functions.
*
@@ -39,7 +39,6 @@ var jaws = (function(jaws) {
//jaws.Parallax = function() { throw("To use jaws.Parallax() you need to include src/extras/parallax.js") }
//jaws.QuadTree = function() { throw("To use QuadTree() you need to include src/extras/quadtree.js") }
//jaws.PixelMap = function() { throw("To use PixelMap() you need to include src/extras/pixel_map.js") }
- //jaws.TileMap = function() { throw("To use TileMap() you need to include src/extras/tile_map.js") }
jaws.SpriteList = function() { throw("To use SpriteList() you need to include src/extras/sprite_list.js") }
jaws.Audio = function() { throw("To use jaws.Audio() you need to include src/extras/audio.js") }
@@ -67,7 +66,7 @@ var jaws = (function(jaws) {
* If a global property is already taken, a warning will be written to jaws log.
*/
jaws.unpack = function() {
- var make_global = ["Sprite", "SpriteList", "Animation", "Viewport", "SpriteSheet", "Parallax", "TileMap", "pressed", "QuadTree"];
+ var make_global = ["Sprite", "SpriteList", "Animation", "Viewport", "SpriteSheet", "Parallax", "pressed", "QuadTree"];
make_global.forEach(function(item) {
if (window[item]) {
@@ -2694,17 +2693,6 @@ jaws.Viewport = function ViewPort(options) {
});
}
- /**
- * draws all items of 'tile_map' that's lies inside the viewport
- * this is simular to viewport.draw( tile_map.all() ) but optmized for Huge game worlds (tile maps)
- */
- this.drawTileMap = function( tile_map ) {
- var sprites = tile_map.atRect({ x: this.x, y: this.y, right: this.x + this.width, bottom: this.y + this.height })
- this.apply( function() {
- for(var i=0; i < sprites.length; i++) sprites[i].draw();
- });
- }
-
/** draws 'item' if it's partly inside the viewport */
this.drawIfPartlyInside = function(item) {
if(that.isPartlyInside(item)) item.draw();
@@ -2967,207 +2955,6 @@ var jaws = (function(jaws) {
})(jaws || {});
-if(typeof require !== "undefined") { var jaws = require("./core.js"); }
-
-var jaws = (function(jaws) {
- /**
- * @class Create and access tilebased 2D maps with very fast access of invidual tiles. "Field Summary" contains options for the TileMap()-constructor.
- *
- * @property {array} cell_size Size of each cell in tilemap, defaults to [32,32]
- * @property {array} size Size of tilemap, defaults to [100,100]
- * @property {function} sortFunction Function used by sortCells() to sort cells, defaults to no sorting
- *
- * @example
- * var tile_map = new TileMap({size: [10, 10], cell_size: [16,16]})
- * var sprite = new jaws.Sprite({x: 40, y: 40})
- * var sprite2 = new jaws.Sprite({x: 41, y: 41})
- * tile_map.push(sprite)
- *
- * tile_map.at(10,10) // []
- * tile_map.at(40,40) // [sprite]
- * tile_map.cell(0,0) // []
- * tile_map.cell(1,1) // [sprite]
- *
- */
- jaws.TileMap = function TileMap(options) {
- if( !(this instanceof arguments.callee) ) return new arguments.callee( options );
-
- jaws.parseOptions(this, options, this.default_options);
- this.cells = new Array(this.size[0]);
-
- for(var col=0; col < this.size[0]; col++) {
- this.cells[col] = new Array(this.size[1]);
- for(var row=0; row < this.size[1]; row++) {
- this.cells[col][row] = [] // populate each cell with an empty array
- }
- }
- }
-
- jaws.TileMap.prototype.default_options = {
- cell_size: [32,32],
- size: [100,100],
- sortFunction: null
- }
-
- /** Clear all cells in tile map */
- jaws.TileMap.prototype.clear = function() {
- for(var col=0; col < this.size[0]; col++) {
- for(var row=0; row < this.size[1]; row++) {
- this.cells[col][row] = [];
- }
- }
- }
-
- /** Sort arrays in each cell in tile map according to sorter-function (see Array.sort) */
- jaws.TileMap.prototype.sortCells = function(sortFunction) {
- for(var col=0; col < this.size[0]; col++) {
- for(var row=0; row < this.size[1]; row++) {
- this.cells[col][row].sort( sortFunction )
- }
- }
- }
-
- /**
- * Push obj (or array of objs) into our cell-grid.
- *
- * Tries to read obj.x and obj.y to calculate what cell to occopy
- */
- jaws.TileMap.prototype.push = function(obj) {
- var that = this;
- if(obj.forEach) {
- obj.forEach( function(item) { that.push(item) } );
- return obj;
- }
- if(obj.rect) {
- return this.pushAsRect(obj, obj.rect());
- }
- else {
- var col = parseInt(obj.x / this.cell_size[0]);
- var row = parseInt(obj.y / this.cell_size[1]);
- return this.pushToCell(col, row, obj);
- }
- }
- /**
- * Push objects into tilemap.
- * Disregard height and width and only use x/y when calculating cell-position
- */
- jaws.TileMap.prototype.pushAsPoint = function(obj) {
- if(Array.isArray(obj)) {
- for(var i=0; i < obj.length; i++) { this.pushAsPoint(obj[i]) }
- return obj;
- }
- else {
- var col = parseInt(obj.x / this.cell_size[0]);
- var row = parseInt(obj.y / this.cell_size[1]);
- return this.pushToCell(col, row, obj);
- }
- }
-
- /** push obj into cells touched by rect */
- jaws.TileMap.prototype.pushAsRect = function(obj, rect) {
- var from_col = parseInt(rect.x / this.cell_size[0]);
- var to_col = parseInt((rect.right-1) / this.cell_size[0]); // -1
- //jaws.log("rect.right: " + rect.right + " from/to col: " + from_col + " " + to_col, true)
-
- for(var col = from_col; col <= to_col; col++) {
- var from_row = parseInt(rect.y / this.cell_size[1]);
- var to_row = parseInt((rect.bottom-1) / this.cell_size[1]); // -1
-
- //jaws.log("rect.bottom " + rect.bottom + " from/to row: " + from_row + " " + to_row, true)
- for(var row = from_row; row <= to_row; row++) {
- // console.log("pushAtRect() col/row: " + col + "/" + row + " - " + this.cells[col][row])
- this.pushToCell(col, row, obj);
- }
- }
- return obj
- }
-
- /**
- * Push obj to a specific cell specified by col and row
- * If cell is already occupied we create an array and push to that
- */
- jaws.TileMap.prototype.pushToCell = function(col, row, obj) {
- this.cells[col][row].push(obj);
- if(this.sortFunction) this.cells[col][row].sort(this.sortFunction);
- return this
- }
-
- //
- // READERS
- //
-
- /** Get objects in cell that exists at coordinates x / y */
- jaws.TileMap.prototype.at = function(x, y) {
- var col = parseInt(x / this.cell_size[0]);
- var row = parseInt(y / this.cell_size[1]);
- // console.log("at() col/row: " + col + "/" + row)
- return this.cells[col][row];
- }
-
- /** Returns occupants of all cells touched by 'rect' */
- jaws.TileMap.prototype.atRect = function(rect) {
- var objects = [];
- var items;
-
- try {
- var from_col = parseInt(rect.x / this.cell_size[0]);
- if (from_col < 0) {
- from_col = 0;
- }
- var to_col = parseInt(rect.right / this.cell_size[0]);
- if (to_col >= this.size[0]) {
- to_col = this.size[0] - 1;
- }
- var from_row = parseInt(rect.y / this.cell_size[1]);
- if (from_row < 0) {
- from_row = 0;
- }
- var to_row = parseInt(rect.bottom / this.cell_size[1]);
- if (to_row >= this.size[1]) {
- to_row = this.size[1] - 1;
- }
-
- for(var col = from_col; col <= to_col; col++) {
- for(var row = from_row; row <= to_row; row++) {
- this.cells[col][row].forEach( function(item, total) {
- if(objects.indexOf(item) == -1) { objects.push(item) }
- })
- }
- }
- }
- catch(e) {
- // ... problems
- }
- return objects
- }
-
- /** Returns all objects in tile map */
- jaws.TileMap.prototype.all = function() {
- var all = [];
- for(var col=0; col < this.size[0]; col++) {
- for(var row=0; row < this.size[1]; row++) {
- this.cells[col][row].forEach( function(element, total) {
- all.push(element)
- });
- }
- }
- return all
- }
-
- /** Get objects in cell at col / row */
- jaws.TileMap.prototype.cell = function(col, row) {
- return this.cells[col][row]
- }
-
- /** Debugstring for TileMap() */
- jaws.TileMap.prototype.toString = function() { return "[TileMap " + this.size[0] + " cols, " + this.size[1] + " rows]" }
-
- return jaws;
-})(jaws || {});
-
-// Support CommonJS require()
-if(typeof module !== "undefined" && ('exports' in module)) { module.exports = jaws.TileMap }
-
var jaws = (function(jaws) {
/**
* @class jaws.PixelMap