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