mirror of
https://github.com/logsol/chuck.js.git
synced 2026-05-11 10:37:34 +00:00
added inheritance to last moved Item
This commit is contained in:
parent
38b5023410
commit
2a4327c5cf
2 changed files with 33 additions and 5 deletions
|
|
@ -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;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
@ -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;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue