Game Development Reference
In-Depth Information
These are two arbitrary values I have set just to show you how to make
things work, and you can change them as you want. Just remember, this
will heavily affect gameplay. Setting these values too high will generate
indestructible bricks and immortal pigs, while setting them too low can
even make the structure collapse due to its weight. It's up to you.
Also, in the original Angry Birds game there are different kinds of materials,
such as glass and wood, which affect bricks' impulse needed to be destroyed.
You should be able to set materials as you already did during the making of
Totem Destroyer. Anyway, don't worry about it as you will fix it later.
6. Time to know which fixtures collided:
var fixtureA:b2Fixture=contact.GetFixtureA();
var fixtureB:b2Fixture=contact.GetFixtureB();
7.
And the custom data of their bodies:
var dataA:String=fixtureA.GetBody().GetUserData();
var dataB:String=fixtureB.GetBody().GetUserData();
8.
Finally, the force of the collision:
var force:Number=impulse.normalImpulses[0];
9.
Now we have all the information needed to see what happened during
each collision. Time to take some decisions:
switch (dataA) {
case "pig" :
if (force>KILLPIG) {
fixtureA.GetBody().SetUserData("remove");
}
break;
case "brick" :
if (force>KILLBRICK) {
fixtureA.GetBody().SetUserData("remove");
}
break;
}
10. Starting from the first body, we check with a switch statement if we are
dealing with a brick or with a pig, then we see if the collision was hard
enough to destroy/kill it.
 
Search WWH ::




Custom Search