added inheritance to last moved Item

This commit is contained in:
Jeena 2014-01-20 18:44:58 +01:00
parent 38b5023410
commit 2a4327c5cf
2 changed files with 33 additions and 5 deletions

View file

@ -60,13 +60,9 @@ function (Parent, Box2D, Settings) {
fixtureDef.isSensor = false; fixtureDef.isSensor = false;
/*
fixtureDef.userData = { fixtureDef.userData = {
onCollisionChange: function(isColliding, fixture) { onCollisionChange: this.onCollisionChange.bind(this)
self.onFixtureWithinReach(isColliding, "right", fixture);
} }
}
*/
this.body.CreateFixture(fixtureDef); this.body.CreateFixture(fixtureDef);
} }
@ -85,6 +81,10 @@ function (Parent, Box2D, Settings) {
// overwrite if necessary // overwrite if necessary
}; };
Item.prototype.onCollisionChange = function(isColliding, fixture, info) {
// overwrite if necessary
};
return Item; return Item;
}); });

View file

@ -54,6 +54,34 @@ function (Parent) {
} }
}; };
Item.prototype.onCollisionChange = function(isColliding, fixture) {
if(isColliding) {
var otherBody = fixture.GetBody();
if(otherBody) {
var otherItem = otherBody.GetUserData();
if(otherItem instanceof Item) {
if(!this.lastMoved && !otherItem.lastMoved) return;
if(this.lastMoved && otherItem.lastMoved) {
if(this.lastMoved.timestamp > otherItem.lastMoved.timestamp) {
this.setLastMovedBy(otherItem.lastMoved.player);
} else {
otherItem.setLastMovedBy(this.lastMoved.player);
}
} else {
if(!this.lastMoved) {
this.setLastMovedBy(otherItem.lastMoved.player);
} else {
otherItem.setLastMovedBy(this.lastMoved.player);
}
}
}
}
}
}
return Item; return Item;
}); });