Take the last example of Chapter 4, Applying Forces to Bodies, the one with the working sling, and let's start working on it.
First, as usual, let's add some custom data to bricks, giving them a name in the
brick
function:private function brick(pX:int,pY:int,w:Number,h:Number):void { var bodyDef:b2BodyDef=new b2BodyDef(); bodyDef.position.Set(pX/worldScale,pY/worldScale); bodyDef.type=b2Body.b2_dynamicBody; bodyDef.userData="brick"; var polygonShape:b2PolygonShape=new b2PolygonShape(); polygonShape.SetAsBox(w/2/worldScale,h/2/worldScale); var fixtureDef:b2FixtureDef=new b2FixtureDef(); fixtureDef.shape=polygonShape; fixtureDef.density=2; fixtureDef.restitution=0.4; fixtureDef.friction=0.5; var theBrick:b2Body=world.CreateBody(bodyDef); theBrick.CreateFixture(fixtureDef); }
Then, obviously, let's give the birds something to kill. It's time to create pigs, which are represented as circle shapes. There's nothing new in...