2017-11-10 02:50:25 +00:00
|
|
|
var Class = require('../../utils/Class');
|
2017-11-14 21:34:33 +00:00
|
|
|
var Components = require('../components');
|
2017-11-10 02:50:25 +00:00
|
|
|
|
|
|
|
var Tile = new Class({
|
|
|
|
|
2017-11-16 19:09:07 +00:00
|
|
|
// TODO: custom rotation or use transform component
|
2017-11-14 21:34:33 +00:00
|
|
|
// TODO: Add in bounds mixin, or custom replacement
|
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.Flip,
|
|
|
|
Components.Visible
|
|
|
|
],
|
|
|
|
|
2017-11-10 02:50:25 +00:00
|
|
|
initialize:
|
|
|
|
|
|
|
|
function Tile (layer, index, x, y, width, height)
|
|
|
|
{
|
|
|
|
this.layer = layer;
|
|
|
|
this.index = index;
|
|
|
|
this.x = x;
|
|
|
|
this.y = y;
|
2017-11-14 21:34:33 +00:00
|
|
|
this.worldX = x * width;
|
|
|
|
this.worldY = y * height;
|
2017-11-10 02:50:25 +00:00
|
|
|
this.width = width;
|
|
|
|
this.height = height;
|
2017-11-16 19:09:07 +00:00
|
|
|
this.properties = {};
|
2017-11-10 02:50:25 +00:00
|
|
|
|
2017-11-14 21:34:33 +00:00
|
|
|
// TODO: update renders to allow for using Components.Tint
|
|
|
|
this.tint = 0xFFFFFF;
|
2017-11-16 19:09:07 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
// Copy everything except position
|
|
|
|
copy: function (tile)
|
|
|
|
{
|
|
|
|
this.index = tile.index;
|
|
|
|
this.alpha = tile.alpha;
|
|
|
|
this.properties = tile.properties;
|
|
|
|
this.visible = tile.visible;
|
|
|
|
this.setFlip(tile.flipX, tile.flipY);
|
|
|
|
this.tint = tile.tint;
|
|
|
|
|
|
|
|
// this.collideUp = tile.collideUp;
|
|
|
|
// this.collideDown = tile.collideDown;
|
|
|
|
// this.collideLeft = tile.collideLeft;
|
|
|
|
// this.collideRight = tile.collideRight;
|
|
|
|
// this.collisionCallback = tile.collisionCallback;
|
|
|
|
// this.collisionCallbackContext = tile.collisionCallbackContext;
|
|
|
|
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
|
|
|
left: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldX;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
right: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldX + this.width;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
top: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldY;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
bottom: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldY + this.height;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
centerX: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldX + this.width / 2;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
centerY: {
|
|
|
|
get: function ()
|
|
|
|
{
|
|
|
|
return this.worldY + this.height / 2;
|
|
|
|
}
|
2017-11-14 21:34:33 +00:00
|
|
|
}
|
2017-11-16 19:09:07 +00:00
|
|
|
|
2017-11-10 02:50:25 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
module.exports = Tile;
|