2012-06-21 10:13:21 +02:00
|
|
|
ig.module(
|
|
|
|
'impact.map'
|
|
|
|
)
|
2012-06-22 17:26:53 +02:00
|
|
|
.defines(function(){ "use strict";
|
2012-06-21 10:13:21 +02:00
|
|
|
|
|
|
|
ig.Map = ig.Class.extend({
|
|
|
|
tilesize: 8,
|
|
|
|
width: 1,
|
|
|
|
height: 1,
|
|
|
|
data: [[]],
|
2012-06-22 17:26:53 +02:00
|
|
|
name: null,
|
2012-06-21 10:13:21 +02:00
|
|
|
|
|
|
|
|
|
|
|
init: function( tilesize, data ) {
|
|
|
|
this.tilesize = tilesize;
|
|
|
|
this.data = data;
|
|
|
|
this.height = data.length;
|
|
|
|
this.width = data[0].length;
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
getTile: function( x, y ) {
|
|
|
|
var tx = Math.floor( x / this.tilesize );
|
|
|
|
var ty = Math.floor( y / this.tilesize );
|
|
|
|
if(
|
|
|
|
(tx >= 0 && tx < this.width) &&
|
|
|
|
(ty >= 0 && ty < this.height)
|
|
|
|
) {
|
|
|
|
return this.data[ty][tx];
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
|
|
setTile: function( x, y, tile ) {
|
|
|
|
var tx = Math.floor( x / this.tilesize );
|
|
|
|
var ty = Math.floor( y / this.tilesize );
|
|
|
|
if(
|
|
|
|
(tx >= 0 && tx < this.width) &&
|
|
|
|
(ty >= 0 && ty < this.height)
|
|
|
|
) {
|
|
|
|
this.data[ty][tx] = tile;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
});
|