[Actionscript3] 纯文本查看 复制代码
package
{
import Box2D.Dynamics.*;
import Box2D.Collision.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.Math.*;
import flash.utils.Dictionary;
public class PhysicsData extends Object
{
// ptm ratio
public var ptm_ratio:Number = 30;
// the physcis data
var dict:Dictionary;
//
// bodytype:
// b2_staticBody
// b2_kinematicBody
// b2_dynamicBody
public function createBody(name:String, world:b2World, bodyType:uint, userData:*):b2Body
{
var fixtures:Array = dict[name];
var body:b2Body;
var f:Number;
// prepare body def
var bodyDef:b2BodyDef = new b2BodyDef();
bodyDef.type = bodyType;
bodyDef.userData = userData;
// create the body
body = world.CreateBody(bodyDef);
// prepare fixtures
for(f=0; f<fixtures.length; f++)
{
var fixture:Array = fixtures[f];
var fixtureDef:b2FixtureDef = new b2FixtureDef();
fixtureDef.density=fixture[0];
fixtureDef.friction=fixture[1];
fixtureDef.restitution=fixture[2];
fixtureDef.filter.categoryBits = fixture[3];
fixtureDef.filter.maskBits = fixture[4];
fixtureDef.filter.groupIndex = fixture[5];
fixtureDef.isSensor = fixture[6];
if(fixture[7] == "POLYGON")
{
var p:Number;
var polygons:Array = fixture[8];
for(p=0; p<polygons.length; p++)
{
var polygonShape:b2PolygonShape = new b2PolygonShape();
polygonShape.SetAsArray(polygons[p], polygons[p].length);
fixtureDef.shape=polygonShape;
body.CreateFixture(fixtureDef);
}
}
else if(fixture[7] == "CIRCLE")
{
var circleShape:b2CircleShape = new b2CircleShape(fixture[9]);
circleShape.SetLocalPosition(fixture[8]);
fixtureDef.shape=circleShape;
body.CreateFixture(fixtureDef);
}
}
return body;
}
public function PhysicsData(): void
{
dict = new Dictionary();
dict["ladeng6666"] = [
[
// density, friction, restitution
2, 3, 0.2,
// categoryBits, maskBits, groupIndex, isSensor
1, 65535, 0, false,
'POLYGON',
// vertexes of decomposed polygons
[
[ new b2Vec2(80/ptm_ratio, 82/ptm_ratio) , new b2Vec2(0/ptm_ratio, 82/ptm_ratio) , new b2Vec2(69/ptm_ratio, 62/ptm_ratio) , new b2Vec2(80/ptm_ratio, 68/ptm_ratio) ] ,
[ new b2Vec2(64/ptm_ratio, 53/ptm_ratio) , new b2Vec2(26/ptm_ratio, 26/ptm_ratio) , new b2Vec2(29/ptm_ratio, 9/ptm_ratio) , new b2Vec2(36/ptm_ratio, 1/ptm_ratio) , new b2Vec2(56/ptm_ratio, 0/ptm_ratio) , new b2Vec2(77/ptm_ratio, 24/ptm_ratio) , new b2Vec2(77/ptm_ratio, 36/ptm_ratio) , new b2Vec2(72/ptm_ratio, 52/ptm_ratio) ] ,
[ new b2Vec2(9/ptm_ratio, 73/ptm_ratio) , new b2Vec2(0/ptm_ratio, 82/ptm_ratio) , new b2Vec2(4/ptm_ratio, 74/ptm_ratio) ] ,
[ new b2Vec2(77/ptm_ratio, 24/ptm_ratio) , new b2Vec2(56/ptm_ratio, 0/ptm_ratio) , new b2Vec2(67/ptm_ratio, 3/ptm_ratio) ] ,
[ new b2Vec2(29/ptm_ratio, 61/ptm_ratio) , new b2Vec2(9/ptm_ratio, 73/ptm_ratio) , new b2Vec2(12/ptm_ratio, 68/ptm_ratio) ] ,
[ new b2Vec2(0/ptm_ratio, 82/ptm_ratio) , new b2Vec2(9/ptm_ratio, 73/ptm_ratio) , new b2Vec2(29/ptm_ratio, 61/ptm_ratio) , new b2Vec2(64/ptm_ratio, 53/ptm_ratio) , new b2Vec2(69/ptm_ratio, 62/ptm_ratio) ] ,
[ new b2Vec2(26/ptm_ratio, 26/ptm_ratio) , new b2Vec2(64/ptm_ratio, 53/ptm_ratio) , new b2Vec2(29/ptm_ratio, 61/ptm_ratio) , new b2Vec2(23/ptm_ratio, 28/ptm_ratio) ]
]
]
];
dict["drink"] = [
[
// density, friction, restitution
2, 3, 0.2,
// categoryBits, maskBits, groupIndex, isSensor
1, 65535, 0, false,
'POLYGON',
// vertexes of decomposed polygons
[
[ new b2Vec2(13/ptm_ratio, 5/ptm_ratio) , new b2Vec2(41/ptm_ratio, 28/ptm_ratio) , new b2Vec2(34/ptm_ratio, 31/ptm_ratio) , new b2Vec2(8/ptm_ratio, 11/ptm_ratio) , new b2Vec2(8/ptm_ratio, 6/ptm_ratio) ] ,
[ new b2Vec2(13/ptm_ratio, 65/ptm_ratio) , new b2Vec2(39/ptm_ratio, 62/ptm_ratio) , new b2Vec2(14/ptm_ratio, 80/ptm_ratio) , new b2Vec2(11/ptm_ratio, 72/ptm_ratio) ] ,
[ new b2Vec2(67/ptm_ratio, 169/ptm_ratio) , new b2Vec2(58/ptm_ratio, 172/ptm_ratio) , new b2Vec2(32/ptm_ratio, 172/ptm_ratio) , new b2Vec2(23/ptm_ratio, 170/ptm_ratio) , new b2Vec2(39/ptm_ratio, 62/ptm_ratio) , new b2Vec2(47/ptm_ratio, 61/ptm_ratio) , new b2Vec2(77/ptm_ratio, 65/ptm_ratio) ] ,
[ new b2Vec2(39/ptm_ratio, 62/ptm_ratio) , new b2Vec2(23/ptm_ratio, 170/ptm_ratio) , new b2Vec2(14/ptm_ratio, 80/ptm_ratio) ] ,
[ new b2Vec2(41/ptm_ratio, 28/ptm_ratio) , new b2Vec2(47/ptm_ratio, 61/ptm_ratio) , new b2Vec2(40/ptm_ratio, 57/ptm_ratio) , new b2Vec2(34/ptm_ratio, 31/ptm_ratio) ] ,
[ new b2Vec2(47/ptm_ratio, 61/ptm_ratio) , new b2Vec2(39/ptm_ratio, 62/ptm_ratio) , new b2Vec2(40/ptm_ratio, 57/ptm_ratio) ]
]
]
];
dict["icecream2"] = [
[
// density, friction, restitution
2, 3, 0.2,
// categoryBits, maskBits, groupIndex, isSensor
1, 65535, 0, false,
'POLYGON',
// vertexes of decomposed polygons
[
[ new b2Vec2(44/ptm_ratio, 19/ptm_ratio) , new b2Vec2(44/ptm_ratio, 70/ptm_ratio) , new b2Vec2(38/ptm_ratio, 73/ptm_ratio) , new b2Vec2(30/ptm_ratio, 72/ptm_ratio) , new b2Vec2(26/ptm_ratio, 71/ptm_ratio) , new b2Vec2(25/ptm_ratio, 11/ptm_ratio) , new b2Vec2(33/ptm_ratio, 6/ptm_ratio) ] ,
[ new b2Vec2(11/ptm_ratio, 73/ptm_ratio) , new b2Vec2(19/ptm_ratio, 73/ptm_ratio) , new b2Vec2(19/ptm_ratio, 97/ptm_ratio) , new b2Vec2(11/ptm_ratio, 98/ptm_ratio) ] ,
[ new b2Vec2(3/ptm_ratio, 68/ptm_ratio) , new b2Vec2(2/ptm_ratio, 19/ptm_ratio) , new b2Vec2(11/ptm_ratio, 8/ptm_ratio) , new b2Vec2(25/ptm_ratio, 11/ptm_ratio) , new b2Vec2(26/ptm_ratio, 71/ptm_ratio) , new b2Vec2(19/ptm_ratio, 73/ptm_ratio) , new b2Vec2(11/ptm_ratio, 73/ptm_ratio) , new b2Vec2(4/ptm_ratio, 71/ptm_ratio) ] ,
[ new b2Vec2(31/ptm_ratio, 98/ptm_ratio) , new b2Vec2(30/ptm_ratio, 72/ptm_ratio) , new b2Vec2(38/ptm_ratio, 73/ptm_ratio) , new b2Vec2(38/ptm_ratio, 98/ptm_ratio) ] ,
[ new b2Vec2(25/ptm_ratio, 11/ptm_ratio) , new b2Vec2(11/ptm_ratio, 8/ptm_ratio) , new b2Vec2(17/ptm_ratio, 7/ptm_ratio) ]
]
]
];
}
}
}