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.position.Set(320/worldScale,465/worldScale);
      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 O’Reilly online learning.

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