Repaired Collision detecteion by adding one detector for each user - fixes #15

This commit is contained in:
Logsol 2013-01-06 01:40:46 +01:00
parent a1e94e1ed0
commit f07505bc20
9 changed files with 31 additions and 29 deletions

View file

@ -5,12 +5,14 @@ define([
function (Box2D, Parent) {
function Detector () {
function Detector (player) { // FIXME evtl.bind(this) ?
this.listener = new Box2D.Dynamics.b2ContactListener();
this.listener.chuckDetector = this;
this.listener.BeginContact = this.BeginContact;
this.listener.PostSolve = this.PostSolve;
this.listener.EndContact = this.EndContact;
this.player = player;
}
Detector.IDENTIFIER = {
@ -27,7 +29,12 @@ function (Box2D, Parent) {
}
Detector.prototype.handleStand = function (point, isColliding) {
throw "Overwrite this function";
if (point.GetFixtureA().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.player.id
|| point.GetFixtureB().GetUserData() == Detector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.player.id) {
this.player.onFootSensorDetection(isColliding);
}
}
/** Extension **/

View file

@ -63,7 +63,7 @@ function (Box2D, Settings, CollisionDetector) {
feetShape.SetLocalPosition(new Box2D.Common.Math.b2Vec2(0 / Settings.RATIO, 0 / Settings.RATIO));
fixtureDef.shape = feetShape;
fixtureDef.isSensor = true;
fixtureDef.userData = CollisionDetector.IDENTIFIER.FOOTSENSOR;
fixtureDef.userData = CollisionDetector.IDENTIFIER.PLAYER_FOOT_SENSOR + '-' + this.id;
this.body.CreateFixture(fixtureDef);
this.body.SetActive(false);

View file

@ -17,9 +17,9 @@ function (Settings, Box2D, CollisionDetector) {
return this.world;
}
Engine.prototype.setCollisionDetector = function (me) {
Engine.prototype.setCollisionDetector = function (player) {
var detector = new CollisionDetector(me); // FIXME: check if core collision detector works
var detector = new CollisionDetector(player);
this.world.SetContactListener(detector.getListener());
}

View file

@ -158,12 +158,12 @@ function (Doll, Settings) {
}
this.setStanding(true);
} else {
// TODO This needs some more thought to it.
// maybe take a look at collision groups for collision detection,
// to group all tiles together
// TODO This needs some more thought to it.
// maybe take a look at collision groups for collision detection,
// to group all tiles together
//this.setStanding(false);
//this.animate('jumploop');
//this.setStanding(false);
//this.animate('jumploop');
}
}
@ -174,7 +174,7 @@ function (Doll, Settings) {
this.stop();
}
if (!this.doll.getBody().IsAwake()) {
if (!this.doll.getBody().IsAwake() && !this.isStanding()) {
this.setStanding(true);
}
}