Putting it all together

Time to take all of our Box2D knowledge and put it all together, to create the ultimate mix between Angry Birds and Crush the Castle.

  1. First, we modify a little the ground function to let it create the ground in the same place as we created it during our latest Angry Birds prototype:
    private function ground():void {
      var bodyDef:b2BodyDef=new b2BodyDef();
      bodyDef.position.Set(320/worldScale,465/worldScale);
      var polygonShape:b2PolygonShape=new b2PolygonShape();
      polygonShape.SetAsBox(320/worldScale,10/worldScale);
      var fixtureDef:b2FixtureDef=new b2FixtureDef();
      fixtureDef.shape=polygonShape;
      var groundBody:b2Body=world.CreateBody(bodyDef);
      groundBody.CreateFixture(fixtureDef);
    }
  2. Then, we need to update the Main function to include ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.