Game Development Reference
In-Depth Information
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
var dataA:String=fixtureA.GetBody().GetUserData();
var dataB:String=fixtureB.GetBody().GetUserData();
var force:Number=impulse.normalImpulses[0];
switch (dataA) {
case "pig" :
if (force>KILLPIG) {
fixtureA.GetBody().SetUserData("remove");
}
break;
case "brick" :
if (force>KILLBRICK) {
fixtureA.GetBody().SetUserData("remove");
}
break;
}
switch (dataB) {
case "pig" :
if (force>KILLPIG) {
fixtureB.GetBody().SetUserData("remove");
}
break;
case "brick" :
if (force>KILLBRICK) {
fixtureB.GetBody().SetUserData("remove");
}
break;
}
}
}
}
5.
You have already learned at the beginning of this chapter how things work
in the customContact class. Anyway, let's take a recap:
private const KILLBRICK:Number=25;
private const KILLPIG:Number=5;
KILLBRICK and KILLPIG are two constants with the amount of impulse
needed to destroy a brick or kill a pig, respectively.
This means, a brick will be destroyed if involved in a collision that generates
an impulse greater than 25 Newton-seconds, while a pig will die if involved
in a collision that generates an impulse greater than 5 Newton-seconds.
 
Search WWH ::




Custom Search