Destroying bricks and killing pigs in Angry Birds

Take the last example of Chapter 4, Applying Forces to Bodies, the one with the working sling, and let's start working on it.

  1. 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 ...

Get Box2D for Flash Games now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.