Detecting when the idol falls on the floor in Totem Destroyer

We want the player to fail the level if the idol hits the ground, that is the static body at the bottom. Let's perform the following steps to achieve this:

  1. Take the last Totem Destroyer we made in Chapter 3, Interacting with Bodies, the one with the text field monitoring idol attributes, and assign a custom data to the floor body changing the floor function in the following way:
    private function floor():void {
      var bodyDef:b2BodyDef=new b2BodyDef();
      bodyDef.userData="floor"; var polygonShape:b2PolygonShape=new b2PolygonShape(); polygonShape.SetAsBox(320/worldScale,15/worldScale); var fixtureDef:b2FixtureDef=new b2FixtureDef(); fixtureDef.shape=polygonShape; ...

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.