Game Development Reference
In-Depth Information
Packt.Components.Physics = function(entity) {
var entity = entity;
// Check if these two rectangles are
intersecting
this.collide = function(x, y, w, h) {
var sprite = entity.getComponent("sprite");
if (sprite) {
var pos = entity.getPosition();
var size = sprite.getSize();
if (pos.x > x + w) {
return false;
}
if (pos.x + size.width < x) {
return false;
}
if (pos.y > y + h) {
return false;
}
if (pos.y + size.height < y) {
return false;
}
return true;
}
return false;
};
// Return the entity's location and dimensions
this.getBodyDef = function() {
var pos = entity.getPosition();
var sprite = entity.getComponent("sprite");
Search WWH ::




Custom Search