Game Development Reference
In-Depth Information
var projectileX:Number=(pX-80)/worldScale;
var projectileY:Number=(pY-115)/worldScale;
bodyDef.position.Set(projectileX,projectileY);
bodyDef.userData="projectile";
polygonShape.SetAsBox(5/worldScale,5/worldScale);
fixtureDef.shape=polygonShape;
var projectile:b2Body=world.CreateBody(bodyDef);
projectile.CreateFixture(fixtureDef);
var slingJoint:b2DistanceJointDef;
slingJoint=new b2DistanceJointDef();
slingJoint.bodyA=arm;
slingJoint.bodyB=projectile;
slingJoint.localAnchorA.Set(-40/worldScale,0);
slingJoint.localAnchorB.Set(0,0);
slingJoint.length=40/worldScale;
sling=world.CreateJoint(slingJoint) as b2DistanceJoint;
}
var frontWheel:b2Body=addWheel(pX+20,pY+15);
var rearWheel:b2Body=addWheel(pX-20,pY+15);
var rJoint:b2RevoluteJointDef=new b2RevoluteJointDef();
rJoint.bodyA=body;
rJoint.bodyB=frontWheel;
rJoint.localAnchorA.Set(20/worldScale,15/worldScale);
rJoint.localAnchorB.Set(0,0);
if (motor) {
rJoint.enableMotor=true;
rJoint.maxMotorTorque=1000;
rJoint.motorSpeed=0;
frj=world.CreateJoint(rJoint) as b2RevoluteJoint;
}
else {
var rj:b2RevoluteJoint;
rj=world.CreateJoint(rJoint) as b2RevoluteJoint;
}
rJoint.bodyB=rearWheel;
rJoint.localAnchorA.Set(-20/worldScale,15/worldScale);
if (motor) {
rrj=world.CreateJoint(rJoint) as b2RevoluteJoint;
}
else {
rj=world.CreateJoint(rJoint) as b2RevoluteJoint;
}
return body;
}
 
Search WWH ::




Custom Search