Game Development Reference
In-Depth Information
3.
Obviously, you must also add brick and pig functions from the latest Angry
Birds prototype, as well as the customContact class to handle collisions.
4.
Then we modify a bit the addCart function, giving a name to our cart parts
using custom data, making them heavier—heavy enough to damage the pigs'
castle with a small projectile, and we also remove the filtering.
private function addCart(pX:Number,pY:Number,motor:Boolean):b2Body
{
var bodyDef:b2BodyDef=new b2BodyDef();
bodyDef.position.Set(pX/worldScale,pY/worldScale);
bodyDef.type=b2Body.b2_dynamicBody;
bodyDef.userData="cart";
var polygonShape:b2PolygonShape=new b2PolygonShape();
polygonShape.SetAsBox(40/worldScale,20/worldScale);
var fixtureDef:b2FixtureDef=new b2FixtureDef();
fixtureDef.shape=polygonShape;
fixtureDef.density=10;
fixtureDef.restitution=0.5;
fixtureDef.friction=0.5;
var body:b2Body=world.CreateBody(bodyDef);
body.CreateFixture(fixtureDef);
if (! motor) {
var armOrigin:b2Vec2=new b2Vec2(0,-60/worldScale);
var armW:Number=5/worldScale;
var armH:Number=60/worldScale;
polygonShape.SetAsOrientedBox(armW,armH,armOrigin);
body.CreateFixture(fixtureDef);
bodyDef.position.Set(pX/worldScale,
(pY-115)/worldScale);
polygonShape.SetAsBox(40/worldScale,5/worldScale);
fixtureDef.shape=polygonShape;
var arm:b2Body=world.CreateBody(bodyDef);
arm.CreateFixture(fixtureDef);
var armJoint:b2RevoluteJointDef;
armJoint=new b2RevoluteJointDef();
armJoint.bodyA=body;
armJoint.bodyB=arm;
armJoint.localAnchorA.Set(0,-115/worldScale);
armJoint.localAnchorB.Set(0,0);
armJoint.enableMotor=true;
armJoint.maxMotorTorque=1000;
armJoint.motorSpeed=6;
var siege:b2RevoluteJoint;
siege=world.CreateJoint(armJoint) as b2RevoluteJoint;
 
Search WWH ::




Custom Search