Custom attributes can be of any type, but at the moment we'll just add a string: breakable
for breakable bricks, and unbreakable
for unbreakable bricks.
First, we'll be passing the string as an argument of the
brick
function, so to reproduce the first level of Totem Destroyer we'll modify theMain
function in the following way:public function Main() { world=new b2World(new b2Vec2(0,5),true); debugDraw(); brick(275,435,30,30,"breakable"); brick(365,435,30,30,"breakable"); brick(320,405,120,30,"breakable"); brick(320,375,60,30,"unbreakable"); brick(305,345,90,30,"breakable"); brick(320,300,120,60,"unbreakable"); idol(320,242); floor(); addEventListener(Event.ENTER_FRAME,updateWorld); stage.addEventListener(MouseEvent.CLICK,destroyBrick); }
And now let's have a look at how the
brick
function changes:private function brick(pX:int,pY:int,w:Number,h:Number,s:String):void { var bodyDef:b2BodyDef=new b2BodyDef(); bodyDef.position.Set...