Section 1
//b2CircleDef (Box2D.Collision.Shapes.b2CircleDef)
package Box2D.Collision.Shapes {
import Box2D.Common.Math.*;
public class b2CircleDef extends b2ShapeDef {
public var radius:Number;
public var localPosition:b2Vec2;
public function b2CircleDef(){
localPosition = new b2Vec2(0, 0);
super();
type = b2Shape.e_circleShape;
radius = 1;
}
}
}//package Box2D.Collision.Shapes
Section 2
//b2CircleShape (Box2D.Collision.Shapes.b2CircleShape)
package Box2D.Collision.Shapes {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2CircleShape extends b2Shape {
public var m_localPosition:b2Vec2;
public var m_radius:Number;
public function b2CircleShape(def:b2ShapeDef){
m_localPosition = new b2Vec2();
super(def);
var circleDef:b2CircleDef = (def as b2CircleDef);
m_type = e_circleShape;
m_localPosition.SetV(circleDef.localPosition);
m_radius = circleDef.radius;
}
override public function TestSegment(transform:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{
var sY:Number;
var tMat:b2Mat22 = transform.R;
var positionX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y)));
var positionY:Number = (transform.position.x + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y)));
var sX:Number = (segment.p1.x - positionX);
sY = (segment.p1.y - positionY);
var b:Number = (((sX * sX) + (sY * sY)) - (m_radius * m_radius));
if (b < 0){
return (false);
};
var rX:Number = (segment.p2.x - segment.p1.x);
var rY:Number = (segment.p2.y - segment.p1.y);
var c:Number = ((sX * rX) + (sY * rY));
var rr:Number = ((rX * rX) + (rY * rY));
var sigma:Number = ((c * c) - (rr * b));
if ((((sigma < 0)) || ((rr < Number.MIN_VALUE)))){
return (false);
};
var a:Number = -((c + Math.sqrt(sigma)));
if ((((0 <= a)) && ((a <= (maxLambda * rr))))){
a = (a / rr);
lambda[0] = a;
normal.x = (sX + (a * rX));
normal.y = (sY + (a * rY));
normal.Normalize();
return (true);
};
return (false);
}
public function GetLocalPosition():b2Vec2{
return (m_localPosition);
}
public function GetRadius():Number{
return (m_radius);
}
override public function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void{
var tMat:b2Mat22;
tMat = transform1.R;
var p1X:Number = (transform1.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y)));
var p1Y:Number = (transform1.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y)));
tMat = transform2.R;
var p2X:Number = (transform2.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y)));
var p2Y:Number = (transform2.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y)));
aabb.lowerBound.Set((((p1X < p2X)) ? p1X : p2X - m_radius), (((p1Y < p2Y)) ? p1Y : p2Y - m_radius));
aabb.upperBound.Set((((p1X > p2X)) ? p1X : p2X + m_radius), (((p1Y > p2Y)) ? p1Y : p2Y + m_radius));
}
override public function ComputeMass(massData:b2MassData):void{
massData.mass = (((m_density * b2Settings.b2_pi) * m_radius) * m_radius);
massData.center.SetV(m_localPosition);
massData.I = (massData.mass * (((0.5 * m_radius) * m_radius) + ((m_localPosition.x * m_localPosition.x) + (m_localPosition.y * m_localPosition.y))));
}
override public function UpdateSweepRadius(center:b2Vec2):void{
var dX:Number = (m_localPosition.x - center.x);
var dY:Number = (m_localPosition.y - center.y);
dX = Math.sqrt(((dX * dX) + (dY * dY)));
m_sweepRadius = ((dX + m_radius) - b2Settings.b2_toiSlop);
}
override public function ComputeAABB(aabb:b2AABB, transform:b2XForm):void{
var tMat:b2Mat22 = transform.R;
var pX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y)));
var pY:Number = (transform.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y)));
aabb.lowerBound.Set((pX - m_radius), (pY - m_radius));
aabb.upperBound.Set((pX + m_radius), (pY + m_radius));
}
override public function TestPoint(transform:b2XForm, p:b2Vec2):Boolean{
var tMat:b2Mat22 = transform.R;
var dX:Number = (transform.position.x + ((tMat.col1.x * m_localPosition.x) + (tMat.col2.x * m_localPosition.y)));
var dY:Number = (transform.position.y + ((tMat.col1.y * m_localPosition.x) + (tMat.col2.y * m_localPosition.y)));
dX = (p.x - dX);
dY = (p.y - dY);
return ((((dX * dX) + (dY * dY)) <= (m_radius * m_radius)));
}
}
}//package Box2D.Collision.Shapes
Section 3
//b2FilterData (Box2D.Collision.Shapes.b2FilterData)
package Box2D.Collision.Shapes {
public class b2FilterData {
public var maskBits:uint;// = 0xFFFF
public var groupIndex:int;// = 0
public var categoryBits:uint;// = 1
public function b2FilterData(){
super();
}
public function Copy():b2FilterData{
var copy:b2FilterData = new b2FilterData();
copy.categoryBits = categoryBits;
copy.maskBits = maskBits;
copy.groupIndex = groupIndex;
return (copy);
}
}
}//package Box2D.Collision.Shapes
Section 4
//b2MassData (Box2D.Collision.Shapes.b2MassData)
package Box2D.Collision.Shapes {
import Box2D.Common.Math.*;
public class b2MassData {
public var mass:Number;// = 0
public var center:b2Vec2;
public var I:Number;// = 0
public function b2MassData(){
center = new b2Vec2(0, 0);
super();
}
}
}//package Box2D.Collision.Shapes
Section 5
//b2PolygonDef (Box2D.Collision.Shapes.b2PolygonDef)
package Box2D.Collision.Shapes {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PolygonDef extends b2ShapeDef {
public var vertices:Array;
public var vertexCount:int;
private static var s_mat:b2Mat22 = new b2Mat22();
public function b2PolygonDef(){
vertices = new Array(b2Settings.b2_maxPolygonVertices);
super();
type = b2Shape.e_polygonShape;
vertexCount = 0;
var i:int;
while (i < b2Settings.b2_maxPolygonVertices) {
vertices[i] = new b2Vec2();
i++;
};
}
public function SetAsOrientedBox(hx:Number, hy:Number, center:b2Vec2=null, angle:Number=0):void{
var xfPosition:b2Vec2;
var xfR:b2Mat22;
var i:int;
vertexCount = 4;
vertices[0].Set(-(hx), -(hy));
vertices[1].Set(hx, -(hy));
vertices[2].Set(hx, hy);
vertices[3].Set(-(hx), hy);
if (center){
xfPosition = center;
xfR = s_mat;
xfR.Set(angle);
i = 0;
while (i < vertexCount) {
center = vertices[i];
hx = (xfPosition.x + ((xfR.col1.x * center.x) + (xfR.col2.x * center.y)));
center.y = (xfPosition.y + ((xfR.col1.y * center.x) + (xfR.col2.y * center.y)));
center.x = hx;
i++;
};
};
}
public function SetAsBox(hx:Number, hy:Number):void{
vertexCount = 4;
vertices[0].Set(-(hx), -(hy));
vertices[1].Set(hx, -(hy));
vertices[2].Set(hx, hy);
vertices[3].Set(-(hx), hy);
}
}
}//package Box2D.Collision.Shapes
Section 6
//b2PolygonShape (Box2D.Collision.Shapes.b2PolygonShape)
package Box2D.Collision.Shapes {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2PolygonShape extends b2Shape {
public var m_coreVertices:Array;
public var m_vertices:Array;
private var s_supportVec:b2Vec2;
public var m_centroid:b2Vec2;
public var m_normals:Array;
public var m_obb:b2OBB;
public var m_vertexCount:int;
private static var s_computeMat:b2Mat22 = new b2Mat22();
private static var s_sweptAABB1:b2AABB = new b2AABB();
private static var s_sweptAABB2:b2AABB = new b2AABB();
public function b2PolygonShape(def:b2ShapeDef){
var i:int;
var edgeX:Number;
var edgeY:Number;
var len:Number;
var n1X:Number;
var n1Y:Number;
var n2X:Number;
var n2Y:Number;
var vX:Number;
var vY:Number;
var dX:Number;
var dY:Number;
var det:Number;
s_supportVec = new b2Vec2();
m_obb = new b2OBB();
m_vertices = new Array(b2Settings.b2_maxPolygonVertices);
m_normals = new Array(b2Settings.b2_maxPolygonVertices);
m_coreVertices = new Array(b2Settings.b2_maxPolygonVertices);
super(def);
m_type = e_polygonShape;
var poly:b2PolygonDef = (def as b2PolygonDef);
m_vertexCount = poly.vertexCount;
var i1:int = i;
var i2:int = i;
i = 0;
while (i < m_vertexCount) {
m_vertices[i] = poly.vertices[i].Copy();
i++;
};
i = 0;
while (i < m_vertexCount) {
i1 = i;
i2 = (((i + 1) < m_vertexCount)) ? (i + 1) : 0;
edgeX = (m_vertices[i2].x - m_vertices[i1].x);
edgeY = (m_vertices[i2].y - m_vertices[i1].y);
len = Math.sqrt(((edgeX * edgeX) + (edgeY * edgeY)));
m_normals[i] = new b2Vec2((edgeY / len), (-(edgeX) / len));
i++;
};
m_centroid = ComputeCentroid(poly.vertices, poly.vertexCount);
ComputeOBB(m_obb, m_vertices, m_vertexCount);
i = 0;
while (i < m_vertexCount) {
i1 = (((i - 1) >= 0)) ? (i - 1) : (m_vertexCount - 1);
i2 = i;
n1X = m_normals[i1].x;
n1Y = m_normals[i1].y;
n2X = m_normals[i2].x;
n2Y = m_normals[i2].y;
vX = (m_vertices[i].x - m_centroid.x);
vY = (m_vertices[i].y - m_centroid.y);
dX = (((n1X * vX) + (n1Y * vY)) - b2Settings.b2_toiSlop);
dY = (((n2X * vX) + (n2Y * vY)) - b2Settings.b2_toiSlop);
det = (1 / ((n1X * n2Y) - (n1Y * n2X)));
m_coreVertices[i] = new b2Vec2(((det * ((n2Y * dX) - (n1Y * dY))) + m_centroid.x), ((det * ((n1X * dY) - (n2X * dX))) + m_centroid.y));
i++;
};
}
override public function ComputeSweptAABB(aabb:b2AABB, transform1:b2XForm, transform2:b2XForm):void{
var aabb1:b2AABB = s_sweptAABB1;
var aabb2:b2AABB = s_sweptAABB2;
ComputeAABB(aabb1, transform1);
ComputeAABB(aabb2, transform2);
aabb.lowerBound.Set(((aabb1.lowerBound.x < aabb2.lowerBound.x)) ? aabb1.lowerBound.x : aabb2.lowerBound.x, ((aabb1.lowerBound.y < aabb2.lowerBound.y)) ? aabb1.lowerBound.y : aabb2.lowerBound.y);
aabb.upperBound.Set(((aabb1.upperBound.x > aabb2.upperBound.x)) ? aabb1.upperBound.x : aabb2.upperBound.x, ((aabb1.upperBound.y > aabb2.upperBound.y)) ? aabb1.upperBound.y : aabb2.upperBound.y);
}
public function GetVertices():Array{
return (m_vertices);
}
public function GetCoreVertices():Array{
return (m_coreVertices);
}
public function GetCentroid():b2Vec2{
return (m_centroid);
}
public function GetOBB():b2OBB{
return (m_obb);
}
public function GetFirstVertex(xf:b2XForm):b2Vec2{
return (b2Math.b2MulX(xf, m_coreVertices[0]));
}
public function Centroid(xf:b2XForm):b2Vec2{
return (b2Math.b2MulX(xf, m_centroid));
}
override public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{
var tX:Number;
var tY:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var numerator:Number;
var denominator:Number;
var lower:Number = 0;
var upper:Number = maxLambda;
tX = (segment.p1.x - xf.position.x);
tY = (segment.p1.y - xf.position.y);
tMat = xf.R;
var p1X:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
var p1Y:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
tX = (segment.p2.x - xf.position.x);
tY = (segment.p2.y - xf.position.y);
tMat = xf.R;
var p2X:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
var p2Y:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
var dX:Number = (p2X - p1X);
var dY:Number = (p2Y - p1Y);
var index = -1;
var i:int;
while (i < m_vertexCount) {
tVec = m_vertices[i];
tX = (tVec.x - p1X);
tY = (tVec.y - p1Y);
tVec = m_normals[i];
numerator = ((tVec.x * tX) + (tVec.y * tY));
denominator = ((tVec.x * dX) + (tVec.y * dY));
if ((((denominator < 0)) && ((numerator < (lower * denominator))))){
lower = (numerator / denominator);
index = i;
} else {
if ((((denominator > 0)) && ((numerator < (upper * denominator))))){
upper = (numerator / denominator);
};
};
if (upper < lower){
return (false);
};
i++;
};
if (index >= 0){
lambda[0] = lower;
tMat = xf.R;
tVec = m_normals[index];
normal.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
normal.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
return (true);
};
return (false);
}
override public function ComputeMass(massData:b2MassData):void{
var p2:b2Vec2;
var p3:b2Vec2;
var e1X:Number;
var e1Y:Number;
var e2X:Number;
var e2Y:Number;
var D:Number;
var triangleArea:Number;
var px:Number;
var py:Number;
var ex1:Number;
var ey1:Number;
var ex2:Number;
var ey2:Number;
var intx2:Number;
var inty2:Number;
var centerX:Number = 0;
var centerY:Number = 0;
var area:Number = 0;
var I:Number = 0;
var p1X:Number = 0;
var p1Y:Number = 0;
var k_inv3:Number = (1 / 3);
var i:int;
while (i < m_vertexCount) {
p2 = m_vertices[i];
p3 = (((i + 1) < m_vertexCount)) ? m_vertices[int((i + 1))] : m_vertices[0];
e1X = (p2.x - p1X);
e1Y = (p2.y - p1Y);
e2X = (p3.x - p1X);
e2Y = (p3.y - p1Y);
D = ((e1X * e2Y) - (e1Y * e2X));
triangleArea = (0.5 * D);
area = (area + triangleArea);
centerX = (centerX + ((triangleArea * k_inv3) * ((p1X + p2.x) + p3.x)));
centerY = (centerY + ((triangleArea * k_inv3) * ((p1Y + p2.y) + p3.y)));
px = p1X;
py = p1Y;
ex1 = e1X;
ey1 = e1Y;
ex2 = e2X;
ey2 = e2Y;
intx2 = ((k_inv3 * ((0.25 * (((ex1 * ex1) + (ex2 * ex1)) + (ex2 * ex2))) + ((px * ex1) + (px * ex2)))) + ((0.5 * px) * px));
inty2 = ((k_inv3 * ((0.25 * (((ey1 * ey1) + (ey2 * ey1)) + (ey2 * ey2))) + ((py * ey1) + (py * ey2)))) + ((0.5 * py) * py));
I = (I + (D * (intx2 + inty2)));
i++;
};
massData.mass = (m_density * area);
centerX = (centerX * (1 / area));
centerY = (centerY * (1 / area));
massData.center.Set(centerX, centerY);
massData.I = (m_density * I);
}
public function GetNormals():Array{
return (m_normals);
}
public function Support(xf:b2XForm, dX:Number, dY:Number):b2Vec2{
var tVec:b2Vec2;
var tMat:b2Mat22;
var value:Number;
tMat = xf.R;
var dLocalX:Number = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
var dLocalY:Number = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
var bestIndex:int;
tVec = m_coreVertices[0];
var bestValue:Number = ((tVec.x * dLocalX) + (tVec.y * dLocalY));
var i = 1;
while (i < m_vertexCount) {
tVec = m_coreVertices[i];
value = ((tVec.x * dLocalX) + (tVec.y * dLocalY));
if (value > bestValue){
bestIndex = i;
bestValue = value;
};
i++;
};
tMat = xf.R;
tVec = m_coreVertices[bestIndex];
s_supportVec.x = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
s_supportVec.y = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
return (s_supportVec);
}
public function GetVertexCount():int{
return (m_vertexCount);
}
override public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void{
var tMat:b2Mat22;
var tVec:b2Vec2;
var R:b2Mat22 = s_computeMat;
tMat = xf.R;
tVec = m_obb.R.col1;
R.col1.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
R.col1.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tVec = m_obb.R.col2;
R.col2.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
R.col2.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
R.Abs();
var absR:b2Mat22 = R;
tVec = m_obb.extents;
var hX:Number = ((absR.col1.x * tVec.x) + (absR.col2.x * tVec.y));
var hY:Number = ((absR.col1.y * tVec.x) + (absR.col2.y * tVec.y));
tMat = xf.R;
tVec = m_obb.center;
var positionX:Number = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var positionY:Number = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
aabb.lowerBound.Set((positionX - hX), (positionY - hY));
aabb.upperBound.Set((positionX + hX), (positionY + hY));
}
override public function UpdateSweepRadius(center:b2Vec2):void{
var tVec:b2Vec2;
var dX:Number;
var dY:Number;
m_sweepRadius = 0;
var i:int;
while (i < m_vertexCount) {
tVec = m_coreVertices[i];
dX = (tVec.x - center.x);
dY = (tVec.y - center.y);
dX = Math.sqrt(((dX * dX) + (dY * dY)));
if (dX > m_sweepRadius){
m_sweepRadius = dX;
};
i++;
};
}
override public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{
var tVec:b2Vec2;
var dot:Number;
var tMat:b2Mat22 = xf.R;
var tX:Number = (p.x - xf.position.x);
var tY:Number = (p.y - xf.position.y);
var pLocalX:Number = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
var pLocalY:Number = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
var i:int;
while (i < m_vertexCount) {
tVec = m_vertices[i];
tX = (pLocalX - tVec.x);
tY = (pLocalY - tVec.y);
tVec = m_normals[i];
dot = ((tVec.x * tX) + (tVec.y * tY));
if (dot > 0){
return (false);
};
i++;
};
return (true);
}
public static function ComputeCentroid(vs:Array, count:int):b2Vec2{
var c:b2Vec2;
var inv3:Number;
var p2:b2Vec2;
var p3:b2Vec2;
var e1X:Number;
var e1Y:Number;
var e2X:Number;
var e2Y:Number;
var D:Number;
var triangleArea:Number;
c = new b2Vec2();
var area:Number = 0;
var p1X:Number = 0;
var p1Y:Number = 0;
inv3 = (1 / 3);
var i:int;
while (i < count) {
p2 = vs[i];
p3 = (((i + 1) < count)) ? vs[int((i + 1))] : vs[0];
e1X = (p2.x - p1X);
e1Y = (p2.y - p1Y);
e2X = (p3.x - p1X);
e2Y = (p3.y - p1Y);
D = ((e1X * e2Y) - (e1Y * e2X));
triangleArea = (0.5 * D);
area = (area + triangleArea);
c.x = (c.x + ((triangleArea * inv3) * ((p1X + p2.x) + p3.x)));
c.y = (c.y + ((triangleArea * inv3) * ((p1Y + p2.y) + p3.y)));
i++;
};
c.x = (c.x * (1 / area));
c.y = (c.y * (1 / area));
return (c);
}
public static function ComputeOBB(obb:b2OBB, vs:Array, count:int):void{
var i:int;
var root:b2Vec2;
var uxX:Number;
var uxY:Number;
var length:Number;
var uyX:Number;
var uyY:Number;
var lowerX:Number;
var lowerY:Number;
var upperX:Number;
var upperY:Number;
var j:int;
var area:Number;
var dX:Number;
var dY:Number;
var rX:Number;
var rY:Number;
var centerX:Number;
var centerY:Number;
var tMat:b2Mat22;
var p:Array = new Array((b2Settings.b2_maxPolygonVertices + 1));
i = 0;
while (i < count) {
p[i] = vs[i];
i++;
};
p[count] = p[0];
var minArea:Number = Number.MAX_VALUE;
i = 1;
while (i <= count) {
root = p[int((i - 1))];
uxX = (p[i].x - root.x);
uxY = (p[i].y - root.y);
length = Math.sqrt(((uxX * uxX) + (uxY * uxY)));
uxX = (uxX / length);
uxY = (uxY / length);
uyX = -(uxY);
uyY = uxX;
lowerX = Number.MAX_VALUE;
lowerY = Number.MAX_VALUE;
upperX = -(Number.MAX_VALUE);
upperY = -(Number.MAX_VALUE);
j = 0;
while (j < count) {
dX = (p[j].x - root.x);
dY = (p[j].y - root.y);
rX = ((uxX * dX) + (uxY * dY));
rY = ((uyX * dX) + (uyY * dY));
if (rX < lowerX){
lowerX = rX;
};
if (rY < lowerY){
lowerY = rY;
};
if (rX > upperX){
upperX = rX;
};
if (rY > upperY){
upperY = rY;
};
j++;
};
area = ((upperX - lowerX) * (upperY - lowerY));
if (area < (0.95 * minArea)){
minArea = area;
obb.R.col1.x = uxX;
obb.R.col1.y = uxY;
obb.R.col2.x = uyX;
obb.R.col2.y = uyY;
centerX = (0.5 * (lowerX + upperX));
centerY = (0.5 * (lowerY + upperY));
tMat = obb.R;
obb.center.x = (root.x + ((tMat.col1.x * centerX) + (tMat.col2.x * centerY)));
obb.center.y = (root.y + ((tMat.col1.y * centerX) + (tMat.col2.y * centerY)));
obb.extents.x = (0.5 * (upperX - lowerX));
obb.extents.y = (0.5 * (upperY - lowerY));
};
i++;
};
}
}
}//package Box2D.Collision.Shapes
Section 7
//b2Shape (Box2D.Collision.Shapes.b2Shape)
package Box2D.Collision.Shapes {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
public class b2Shape {
public var m_next:b2Shape;
public var m_type:int;
public var m_sweepRadius:Number;
public var m_density:Number;
public var m_filter:b2FilterData;
public var m_friction:Number;
public var m_isSensor:Boolean;
public var m_restitution:Number;
public var m_userData;
public var m_proxyId:uint;
public var m_body:b2Body;
public static const e_polygonShape:int = 1;
public static const e_unknownShape:int = -1;
public static const e_circleShape:int = 0;
public static const e_shapeTypeCount:int = 2;
private static var s_resetAABB:b2AABB = new b2AABB();
private static var s_syncAABB:b2AABB = new b2AABB();
private static var s_proxyAABB:b2AABB = new b2AABB();
public function b2Shape(def:b2ShapeDef){
super();
m_userData = def.userData;
m_friction = def.friction;
m_restitution = def.restitution;
m_density = def.density;
m_body = null;
m_sweepRadius = 0;
m_next = null;
m_proxyId = b2Pair.b2_nullProxy;
m_filter = def.filter.Copy();
m_isSensor = def.isSensor;
}
public function SetUserData(data):void{
m_userData = data;
}
public function GetSweepRadius():Number{
return (m_sweepRadius);
}
public function GetNext():b2Shape{
return (m_next);
}
public function ComputeSweptAABB(aabb:b2AABB, xf1:b2XForm, xf2:b2XForm):void{
}
public function GetType():int{
return (m_type);
}
public function GetRestitution():Number{
return (m_restitution);
}
public function GetFriction():Number{
return (m_friction);
}
public function GetFilterData():b2FilterData{
return (m_filter.Copy());
}
public function TestSegment(xf:b2XForm, lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{
return (false);
}
public function RefilterProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{
if (m_proxyId == b2Pair.b2_nullProxy){
return;
};
broadPhase.DestroyProxy(m_proxyId);
var aabb:b2AABB = s_resetAABB;
ComputeAABB(aabb, transform);
var inRange:Boolean = broadPhase.InRange(aabb);
if (inRange){
m_proxyId = broadPhase.CreateProxy(aabb, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
}
public function SetFilterData(filter:b2FilterData):void{
m_filter = filter.Copy();
}
public function GetUserData(){
return (m_userData);
}
public function Synchronize(broadPhase:b2BroadPhase, transform1:b2XForm, transform2:b2XForm):Boolean{
if (m_proxyId == b2Pair.b2_nullProxy){
return (false);
};
var aabb:b2AABB = s_syncAABB;
ComputeSweptAABB(aabb, transform1, transform2);
if (broadPhase.InRange(aabb)){
broadPhase.MoveProxy(m_proxyId, aabb);
return (true);
};
return (false);
}
public function ComputeMass(massData:b2MassData):void{
}
public function IsSensor():Boolean{
return (m_isSensor);
}
public function DestroyProxy(broadPhase:b2BroadPhase):void{
if (m_proxyId != b2Pair.b2_nullProxy){
broadPhase.DestroyProxy(m_proxyId);
m_proxyId = b2Pair.b2_nullProxy;
};
}
public function UpdateSweepRadius(center:b2Vec2):void{
}
public function ComputeAABB(aabb:b2AABB, xf:b2XForm):void{
}
public function GetBody():b2Body{
return (m_body);
}
public function CreateProxy(broadPhase:b2BroadPhase, transform:b2XForm):void{
var aabb:b2AABB = s_proxyAABB;
ComputeAABB(aabb, transform);
var inRange:Boolean = broadPhase.InRange(aabb);
if (inRange){
m_proxyId = broadPhase.CreateProxy(aabb, this);
} else {
m_proxyId = b2Pair.b2_nullProxy;
};
}
public function TestPoint(xf:b2XForm, p:b2Vec2):Boolean{
return (false);
}
public static function Destroy(shape:b2Shape, allocator):void{
}
public static function Create(def:b2ShapeDef, allocator):b2Shape{
switch (def.type){
case e_circleShape:
return (new b2CircleShape(def));
case e_polygonShape:
return (new b2PolygonShape(def));
default:
return (null);
};
}
}
}//package Box2D.Collision.Shapes
Section 8
//b2ShapeDef (Box2D.Collision.Shapes.b2ShapeDef)
package Box2D.Collision.Shapes {
public class b2ShapeDef {
public var friction:Number;// = 0.2
public var isSensor:Boolean;// = false
public var density:Number;// = 0
public var restitution:Number;// = 0
public var userData;// = null
public var filter:b2FilterData;
public var type:int;
public function b2ShapeDef(){
type = b2Shape.e_unknownShape;
filter = new b2FilterData();
super();
}
}
}//package Box2D.Collision.Shapes
Section 9
//b2AABB (Box2D.Collision.b2AABB)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class b2AABB {
public var upperBound:b2Vec2;
public var lowerBound:b2Vec2;
public function b2AABB(){
lowerBound = new b2Vec2();
upperBound = new b2Vec2();
super();
}
public function IsValid():Boolean{
var dX:Number = (upperBound.x - lowerBound.x);
var dY:Number = (upperBound.y - lowerBound.y);
var valid:Boolean = (((dX >= 0)) && ((dY >= 0)));
valid = ((((valid) && (lowerBound.IsValid()))) && (upperBound.IsValid()));
return (valid);
}
}
}//package Box2D.Collision
Section 10
//b2Bound (Box2D.Collision.b2Bound)
package Box2D.Collision {
public class b2Bound {
public var value:uint;
public var proxyId:uint;
public var stabbingCount:uint;
public function b2Bound(){
super();
}
public function Swap(b:b2Bound):void{
var tempValue:uint = value;
var tempProxyId:uint = proxyId;
var tempStabbingCount:uint = stabbingCount;
value = b.value;
proxyId = b.proxyId;
stabbingCount = b.stabbingCount;
b.value = tempValue;
b.proxyId = tempProxyId;
b.stabbingCount = tempStabbingCount;
}
public function IsLower():Boolean{
return (((value & 1) == 0));
}
public function IsUpper():Boolean{
return (((value & 1) == 1));
}
}
}//package Box2D.Collision
Section 11
//b2BoundValues (Box2D.Collision.b2BoundValues)
package Box2D.Collision {
public class b2BoundValues {
public var lowerValues:Array;
public var upperValues:Array;
public function b2BoundValues(){
lowerValues = [0, 0];
upperValues = [0, 0];
super();
}
}
}//package Box2D.Collision
Section 12
//b2BroadPhase (Box2D.Collision.b2BroadPhase)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2BroadPhase {
public var m_bounds:Array;
public var m_quantizationFactor:b2Vec2;
public var m_worldAABB:b2AABB;
public var m_freeProxy:uint;
public var m_proxyCount:int;
public var m_proxyPool:Array;
public var m_queryResultCount:int;
public var m_pairManager:b2PairManager;
public var m_timeStamp:uint;
public var m_queryResults:Array;
public static const b2_nullEdge:uint = 0xFFFF;
public static const b2_invalid:uint = 0xFFFF;
public static var s_validate:Boolean = false;
public function b2BroadPhase(worldAABB:b2AABB, callback:b2PairCallback){
var i:int;
var dY:Number;
var tProxy:b2Proxy;
var j:int;
m_pairManager = new b2PairManager();
m_proxyPool = new Array(b2Settings.b2_maxPairs);
m_bounds = new Array((2 * b2Settings.b2_maxProxies));
m_queryResults = new Array(b2Settings.b2_maxProxies);
m_quantizationFactor = new b2Vec2();
super();
m_pairManager.Initialize(this, callback);
m_worldAABB = worldAABB;
m_proxyCount = 0;
i = 0;
while (i < b2Settings.b2_maxProxies) {
m_queryResults[i] = 0;
i++;
};
m_bounds = new Array(2);
i = 0;
while (i < 2) {
m_bounds[i] = new Array((2 * b2Settings.b2_maxProxies));
j = 0;
while (j < (2 * b2Settings.b2_maxProxies)) {
m_bounds[i][j] = new b2Bound();
j++;
};
i++;
};
var dX:Number = (worldAABB.upperBound.x - worldAABB.lowerBound.x);
dY = (worldAABB.upperBound.y - worldAABB.lowerBound.y);
m_quantizationFactor.x = (b2Settings.USHRT_MAX / dX);
m_quantizationFactor.y = (b2Settings.USHRT_MAX / dY);
i = 0;
while (i < (b2Settings.b2_maxProxies - 1)) {
tProxy = new b2Proxy();
m_proxyPool[i] = tProxy;
tProxy.SetNext((i + 1));
tProxy.timeStamp = 0;
tProxy.overlapCount = b2_invalid;
tProxy.userData = null;
i++;
};
tProxy = new b2Proxy();
m_proxyPool[int((b2Settings.b2_maxProxies - 1))] = tProxy;
tProxy.SetNext(b2Pair.b2_nullProxy);
tProxy.timeStamp = 0;
tProxy.overlapCount = b2_invalid;
tProxy.userData = null;
m_freeProxy = 0;
m_timeStamp = 1;
m_queryResultCount = 0;
}
public function QueryAABB(aabb:b2AABB, userData, maxCount:int):int{
var lowerIndex:uint;
var upperIndex:uint;
var proxy:b2Proxy;
var lowerValues:Array = new Array();
var upperValues:Array = new Array();
ComputeBounds(lowerValues, upperValues, aabb);
var lowerIndexOut:Array = [lowerIndex];
var upperIndexOut:Array = [upperIndex];
Query(lowerIndexOut, upperIndexOut, lowerValues[0], upperValues[0], m_bounds[0], (2 * m_proxyCount), 0);
Query(lowerIndexOut, upperIndexOut, lowerValues[1], upperValues[1], m_bounds[1], (2 * m_proxyCount), 1);
var count:int;
var i:int;
while ((((i < m_queryResultCount)) && ((count < maxCount)))) {
proxy = m_proxyPool[m_queryResults[i]];
userData[i] = proxy.userData;
i++;
count++;
};
m_queryResultCount = 0;
IncrementTimeStamp();
return (count);
}
public function Commit():void{
m_pairManager.Commit();
}
public function GetProxy(proxyId:int):b2Proxy{
var proxy:b2Proxy = m_proxyPool[proxyId];
if ((((proxyId == b2Pair.b2_nullProxy)) || ((proxy.IsValid() == false)))){
return (null);
};
return (proxy);
}
private function IncrementTimeStamp():void{
var i:uint;
if (m_timeStamp == b2Settings.USHRT_MAX){
i = 0;
while (i < b2Settings.b2_maxProxies) {
(m_proxyPool[i] as b2Proxy).timeStamp = 0;
i++;
};
m_timeStamp = 1;
} else {
m_timeStamp++;
};
}
private function Query(lowerQueryOut:Array, upperQueryOut:Array, lowerValue:uint, upperValue:uint, bounds:Array, boundCount:uint, axis:int):void{
var bound:b2Bound;
var i:int;
var s:int;
var proxy:b2Proxy;
var lowerQuery:uint = BinarySearch(bounds, boundCount, lowerValue);
var upperQuery:uint = BinarySearch(bounds, boundCount, upperValue);
var j:uint = lowerQuery;
while (j < upperQuery) {
bound = bounds[j];
if (bound.IsLower()){
IncrementOverlapCount(bound.proxyId);
};
j++;
};
if (lowerQuery > 0){
i = (lowerQuery - 1);
bound = bounds[i];
s = bound.stabbingCount;
while (s) {
bound = bounds[i];
if (bound.IsLower()){
proxy = m_proxyPool[bound.proxyId];
if (lowerQuery <= proxy.upperBounds[axis]){
IncrementOverlapCount(bound.proxyId);
s--;
};
};
i--;
};
};
lowerQueryOut[0] = lowerQuery;
upperQueryOut[0] = upperQuery;
}
private function TestOverlapValidate(p1:b2Proxy, p2:b2Proxy):Boolean{
var bounds:Array;
var bound1:b2Bound;
var bound2:b2Bound;
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
bound1 = bounds[p1.lowerBounds[axis]];
bound2 = bounds[p2.upperBounds[axis]];
if (bound1.value > bound2.value){
return (false);
};
bound1 = bounds[p1.upperBounds[axis]];
bound2 = bounds[p2.lowerBounds[axis]];
if (bound1.value < bound2.value){
return (false);
};
axis++;
};
return (true);
}
private function ComputeBounds(lowerValues:Array, upperValues:Array, aabb:b2AABB):void{
var minVertexX:Number = aabb.lowerBound.x;
var minVertexY:Number = aabb.lowerBound.y;
minVertexX = b2Math.b2Min(minVertexX, m_worldAABB.upperBound.x);
minVertexY = b2Math.b2Min(minVertexY, m_worldAABB.upperBound.y);
minVertexX = b2Math.b2Max(minVertexX, m_worldAABB.lowerBound.x);
minVertexY = b2Math.b2Max(minVertexY, m_worldAABB.lowerBound.y);
var maxVertexX:Number = aabb.upperBound.x;
var maxVertexY:Number = aabb.upperBound.y;
maxVertexX = b2Math.b2Min(maxVertexX, m_worldAABB.upperBound.x);
maxVertexY = b2Math.b2Min(maxVertexY, m_worldAABB.upperBound.y);
maxVertexX = b2Math.b2Max(maxVertexX, m_worldAABB.lowerBound.x);
maxVertexY = b2Math.b2Max(maxVertexY, m_worldAABB.lowerBound.y);
lowerValues[0] = (uint((m_quantizationFactor.x * (minVertexX - m_worldAABB.lowerBound.x))) & (b2Settings.USHRT_MAX - 1));
upperValues[0] = ((uint((m_quantizationFactor.x * (maxVertexX - m_worldAABB.lowerBound.x))) & 0xFFFF) | 1);
lowerValues[1] = (uint((m_quantizationFactor.y * (minVertexY - m_worldAABB.lowerBound.y))) & (b2Settings.USHRT_MAX - 1));
upperValues[1] = ((uint((m_quantizationFactor.y * (maxVertexY - m_worldAABB.lowerBound.y))) & 0xFFFF) | 1);
}
public function CreateProxy(aabb:b2AABB, userData):uint{
var index:uint;
var proxy:b2Proxy;
var bounds:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerIndexOut:Array;
var upperIndexOut:Array;
var tArr:Array;
var j:int;
var tEnd:int;
var tBound1:b2Bound;
var tBound2:b2Bound;
var tBoundAS3:b2Bound;
var tIndex:int;
var proxy2:b2Proxy;
var proxyId:uint = m_freeProxy;
proxy = m_proxyPool[proxyId];
m_freeProxy = proxy.GetNext();
proxy.overlapCount = 0;
proxy.userData = userData;
var boundCount:uint = (2 * m_proxyCount);
var lowerValues:Array = new Array();
var upperValues:Array = new Array();
ComputeBounds(lowerValues, upperValues, aabb);
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndexOut = [lowerIndex];
upperIndexOut = [upperIndex];
Query(lowerIndexOut, upperIndexOut, lowerValues[axis], upperValues[axis], bounds, boundCount, axis);
lowerIndex = lowerIndexOut[0];
upperIndex = upperIndexOut[0];
tArr = new Array();
tEnd = (boundCount - upperIndex);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[int((upperIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (upperIndex + 2);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[int((tIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tArr = new Array();
tEnd = (upperIndex - lowerIndex);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[int((lowerIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (lowerIndex + 1);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[int((tIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
upperIndex++;
tBound1 = bounds[lowerIndex];
tBound2 = bounds[upperIndex];
tBound1.value = lowerValues[axis];
tBound1.proxyId = proxyId;
tBound2.value = upperValues[axis];
tBound2.proxyId = proxyId;
tBoundAS3 = bounds[int((lowerIndex - 1))];
tBound1.stabbingCount = ((lowerIndex == 0)) ? 0 : tBoundAS3.stabbingCount;
tBoundAS3 = bounds[int((upperIndex - 1))];
tBound2.stabbingCount = tBoundAS3.stabbingCount;
index = lowerIndex;
while (index < upperIndex) {
tBoundAS3 = bounds[index];
tBoundAS3.stabbingCount++;
index++;
};
index = lowerIndex;
while (index < (boundCount + 2)) {
tBound1 = bounds[index];
proxy2 = m_proxyPool[tBound1.proxyId];
if (tBound1.IsLower()){
proxy2.lowerBounds[axis] = index;
} else {
proxy2.upperBounds[axis] = index;
};
index++;
};
axis++;
};
m_proxyCount++;
var i:int;
while (i < m_queryResultCount) {
m_pairManager.AddBufferedPair(proxyId, m_queryResults[i]);
i++;
};
m_pairManager.Commit();
m_queryResultCount = 0;
IncrementTimeStamp();
return (proxyId);
}
public function DestroyProxy(proxyId:uint):void{
var tBound1:b2Bound;
var tBound2:b2Bound;
var bounds:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerValue:uint;
var upperValue:uint;
var tArr:Array;
var j:int;
var tEnd:int;
var tIndex:int;
var index:uint;
var index2:int;
var proxy2:b2Proxy;
var proxy:b2Proxy = m_proxyPool[proxyId];
var boundCount:int = (2 * m_proxyCount);
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndex = proxy.lowerBounds[axis];
upperIndex = proxy.upperBounds[axis];
tBound1 = bounds[lowerIndex];
lowerValue = tBound1.value;
tBound2 = bounds[upperIndex];
upperValue = tBound2.value;
tArr = new Array();
tEnd = ((upperIndex - lowerIndex) - 1);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[int(((lowerIndex + 1) + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = lowerIndex;
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[int((tIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tArr = new Array();
tEnd = ((boundCount - upperIndex) - 1);
j = 0;
while (j < tEnd) {
tArr[j] = new b2Bound();
tBound1 = tArr[j];
tBound2 = bounds[int(((upperIndex + 1) + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = tArr.length;
tIndex = (upperIndex - 1);
j = 0;
while (j < tEnd) {
tBound2 = tArr[j];
tBound1 = bounds[int((tIndex + j))];
tBound1.value = tBound2.value;
tBound1.proxyId = tBound2.proxyId;
tBound1.stabbingCount = tBound2.stabbingCount;
j++;
};
tEnd = (boundCount - 2);
index = lowerIndex;
while (index < tEnd) {
tBound1 = bounds[index];
proxy2 = m_proxyPool[tBound1.proxyId];
if (tBound1.IsLower()){
proxy2.lowerBounds[axis] = index;
} else {
proxy2.upperBounds[axis] = index;
};
index++;
};
tEnd = (upperIndex - 1);
index2 = lowerIndex;
while (index2 < tEnd) {
tBound1 = bounds[index2];
tBound1.stabbingCount--;
index2++;
};
Query([0], [0], lowerValue, upperValue, bounds, (boundCount - 2), axis);
axis++;
};
var i:int;
while (i < m_queryResultCount) {
m_pairManager.RemoveBufferedPair(proxyId, m_queryResults[i]);
i++;
};
m_pairManager.Commit();
m_queryResultCount = 0;
IncrementTimeStamp();
proxy.userData = null;
proxy.overlapCount = b2_invalid;
proxy.lowerBounds[0] = b2_invalid;
proxy.lowerBounds[1] = b2_invalid;
proxy.upperBounds[0] = b2_invalid;
proxy.upperBounds[1] = b2_invalid;
proxy.SetNext(m_freeProxy);
m_freeProxy = proxyId;
m_proxyCount--;
}
public function TestOverlap(b:b2BoundValues, p:b2Proxy):Boolean{
var bounds:Array;
var bound:b2Bound;
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
bound = bounds[p.upperBounds[axis]];
if (b.lowerValues[axis] > bound.value){
return (false);
};
bound = bounds[p.lowerBounds[axis]];
if (b.upperValues[axis] < bound.value){
return (false);
};
axis++;
};
return (true);
}
public function Validate():void{
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
var overlap:Boolean;
var bounds:b2Bound;
var boundCount:uint;
var stabbingCount:uint;
var i:uint;
var bound:b2Bound;
var axis:int;
while (axis < 2) {
bounds = m_bounds[axis];
boundCount = (2 * m_proxyCount);
stabbingCount = 0;
i = 0;
while (i < boundCount) {
bound = bounds[i];
if (bound.IsLower() == true){
stabbingCount++;
} else {
stabbingCount--;
};
i++;
};
axis++;
};
}
private function IncrementOverlapCount(proxyId:uint):void{
var proxy:b2Proxy = m_proxyPool[proxyId];
if (proxy.timeStamp < m_timeStamp){
proxy.timeStamp = m_timeStamp;
proxy.overlapCount = 1;
} else {
proxy.overlapCount = 2;
m_queryResults[m_queryResultCount] = proxyId;
m_queryResultCount++;
};
}
public function InRange(aabb:b2AABB):Boolean{
var dX:Number;
var dY:Number;
var d2X:Number;
var d2Y:Number;
dX = aabb.lowerBound.x;
dY = aabb.lowerBound.y;
dX = (dX - m_worldAABB.upperBound.x);
dY = (dY - m_worldAABB.upperBound.y);
d2X = m_worldAABB.lowerBound.x;
d2Y = m_worldAABB.lowerBound.y;
d2X = (d2X - aabb.upperBound.x);
d2Y = (d2Y - aabb.upperBound.y);
dX = b2Math.b2Max(dX, d2X);
dY = b2Math.b2Max(dY, d2Y);
return ((b2Math.b2Max(dX, dY) < 0));
}
public function MoveProxy(proxyId:uint, aabb:b2AABB):void{
var as3arr:Array;
var as3int:int;
var axis:uint;
var index:uint;
var bound:b2Bound;
var prevBound:b2Bound;
var nextBound:b2Bound;
var nextProxyId:uint;
var nextProxy:b2Proxy;
var bounds:Array;
var lowerIndex:uint;
var upperIndex:uint;
var lowerValue:uint;
var upperValue:uint;
var deltaLower:int;
var deltaUpper:int;
var prevProxyId:uint;
var prevProxy:b2Proxy;
if ((((proxyId == b2Pair.b2_nullProxy)) || ((b2Settings.b2_maxProxies <= proxyId)))){
return;
};
if (aabb.IsValid() == false){
return;
};
var boundCount:uint = (2 * m_proxyCount);
var proxy:b2Proxy = m_proxyPool[proxyId];
var newValues:b2BoundValues = new b2BoundValues();
ComputeBounds(newValues.lowerValues, newValues.upperValues, aabb);
var oldValues:b2BoundValues = new b2BoundValues();
axis = 0;
while (axis < 2) {
bound = m_bounds[axis][proxy.lowerBounds[axis]];
oldValues.lowerValues[axis] = bound.value;
bound = m_bounds[axis][proxy.upperBounds[axis]];
oldValues.upperValues[axis] = bound.value;
axis++;
};
axis = 0;
while (axis < 2) {
bounds = m_bounds[axis];
lowerIndex = proxy.lowerBounds[axis];
upperIndex = proxy.upperBounds[axis];
lowerValue = newValues.lowerValues[axis];
upperValue = newValues.upperValues[axis];
bound = bounds[lowerIndex];
deltaLower = (lowerValue - bound.value);
bound.value = lowerValue;
bound = bounds[upperIndex];
deltaUpper = (upperValue - bound.value);
bound.value = upperValue;
if (deltaLower < 0){
index = lowerIndex;
while ((((index > 0)) && ((lowerValue < (bounds[int((index - 1))] as b2Bound).value)))) {
bound = bounds[index];
prevBound = bounds[int((index - 1))];
prevProxyId = prevBound.proxyId;
prevProxy = m_proxyPool[prevBound.proxyId];
prevBound.stabbingCount++;
if (prevBound.IsUpper() == true){
if (TestOverlap(newValues, prevProxy)){
m_pairManager.AddBufferedPair(proxyId, prevProxyId);
};
as3arr = prevProxy.upperBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.stabbingCount++;
} else {
as3arr = prevProxy.lowerBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.stabbingCount--;
};
as3arr = proxy.lowerBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.Swap(prevBound);
index--;
};
};
if (deltaUpper > 0){
index = upperIndex;
while ((((index < (boundCount - 1))) && (((bounds[int((index + 1))] as b2Bound).value <= upperValue)))) {
bound = bounds[index];
nextBound = bounds[int((index + 1))];
nextProxyId = nextBound.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextBound.stabbingCount++;
if (nextBound.IsLower() == true){
if (TestOverlap(newValues, nextProxy)){
m_pairManager.AddBufferedPair(proxyId, nextProxyId);
};
as3arr = nextProxy.lowerBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.stabbingCount++;
} else {
as3arr = nextProxy.upperBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.stabbingCount--;
};
as3arr = proxy.upperBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.Swap(nextBound);
index++;
};
};
if (deltaLower > 0){
index = lowerIndex;
while ((((index < (boundCount - 1))) && (((bounds[int((index + 1))] as b2Bound).value <= lowerValue)))) {
bound = bounds[index];
nextBound = bounds[int((index + 1))];
nextProxyId = nextBound.proxyId;
nextProxy = m_proxyPool[nextProxyId];
nextBound.stabbingCount--;
if (nextBound.IsUpper()){
if (TestOverlap(oldValues, nextProxy)){
m_pairManager.RemoveBufferedPair(proxyId, nextProxyId);
};
as3arr = nextProxy.upperBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.stabbingCount--;
} else {
as3arr = nextProxy.lowerBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.stabbingCount++;
};
as3arr = proxy.lowerBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.Swap(nextBound);
index++;
};
};
if (deltaUpper < 0){
index = upperIndex;
while ((((index > 0)) && ((upperValue < (bounds[int((index - 1))] as b2Bound).value)))) {
bound = bounds[index];
prevBound = bounds[int((index - 1))];
prevProxyId = prevBound.proxyId;
prevProxy = m_proxyPool[prevProxyId];
prevBound.stabbingCount--;
if (prevBound.IsLower() == true){
if (TestOverlap(oldValues, prevProxy)){
m_pairManager.RemoveBufferedPair(proxyId, prevProxyId);
};
as3arr = prevProxy.lowerBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.stabbingCount--;
} else {
as3arr = prevProxy.upperBounds;
as3int = as3arr[axis];
as3int++;
as3arr[axis] = as3int;
bound.stabbingCount++;
};
as3arr = proxy.upperBounds;
as3int = as3arr[axis];
as3int--;
as3arr[axis] = as3int;
bound.Swap(prevBound);
index--;
};
};
axis++;
};
}
public static function BinarySearch(bounds:Array, count:int, value:uint):uint{
var mid:int;
var bound:b2Bound;
var low:int;
var high:int = (count - 1);
while (low <= high) {
mid = ((low + high) / 2);
bound = bounds[mid];
if (bound.value > value){
high = (mid - 1);
} else {
if (bound.value < value){
low = (mid + 1);
} else {
return (uint(mid));
};
};
};
return (uint(low));
}
}
}//package Box2D.Collision
Section 13
//b2BufferedPair (Box2D.Collision.b2BufferedPair)
package Box2D.Collision {
public class b2BufferedPair {
public var proxyId1:uint;
public var proxyId2:uint;
public function b2BufferedPair(){
super();
}
}
}//package Box2D.Collision
Section 14
//b2Collision (Box2D.Collision.b2Collision)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2Collision {
public static const b2_nullFeature:uint = 0xFF;
private static var b2CollidePolyTempVec:b2Vec2 = new b2Vec2();
public function b2Collision(){
super();
}
public static function EdgeSeparation(poly1:b2PolygonShape, xf1:b2XForm, edge1:int, poly2:b2PolygonShape, xf2:b2XForm):Number{
var tMat:b2Mat22;
var tVec:b2Vec2;
var dot:Number;
var count1:int = poly1.m_vertexCount;
var vertices1:Array = poly1.m_vertices;
var normals1:Array = poly1.m_normals;
var count2:int = poly2.m_vertexCount;
var vertices2:Array = poly2.m_vertices;
tMat = xf1.R;
tVec = normals1[edge1];
var normal1WorldX:Number = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
var normal1WorldY:Number = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = xf2.R;
var normal1X:Number = ((tMat.col1.x * normal1WorldX) + (tMat.col1.y * normal1WorldY));
var normal1Y:Number = ((tMat.col2.x * normal1WorldX) + (tMat.col2.y * normal1WorldY));
var index:int;
var minDot:Number = Number.MAX_VALUE;
var i:int;
while (i < count2) {
tVec = vertices2[i];
dot = ((tVec.x * normal1X) + (tVec.y * normal1Y));
if (dot < minDot){
minDot = dot;
index = i;
};
i++;
};
tVec = vertices1[edge1];
tMat = xf1.R;
var v1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var v1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tVec = vertices2[index];
tMat = xf2.R;
var v2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var v2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
v2X = (v2X - v1X);
v2Y = (v2Y - v1Y);
var separation:Number = ((v2X * normal1WorldX) + (v2Y * normal1WorldY));
return (separation);
}
public static function b2TestOverlap(a:b2AABB, b:b2AABB):Boolean{
var t1:b2Vec2 = b.lowerBound;
var t2:b2Vec2 = a.upperBound;
var d1X:Number = (t1.x - t2.x);
var d1Y:Number = (t1.y - t2.y);
t1 = a.lowerBound;
t2 = b.upperBound;
var d2X:Number = (t1.x - t2.x);
var d2Y:Number = (t1.y - t2.y);
if ((((d1X > 0)) || ((d1Y > 0)))){
return (false);
};
if ((((d2X > 0)) || ((d2Y > 0)))){
return (false);
};
return (true);
}
public static function FindIncidentEdge(c:Array, poly1:b2PolygonShape, xf1:b2XForm, edge1:int, poly2:b2PolygonShape, xf2:b2XForm):void{
var tMat:b2Mat22;
var tVec:b2Vec2;
var tClip:ClipVertex;
var dot:Number;
var count1:int = poly1.m_vertexCount;
var normals1:Array = poly1.m_normals;
var count2:int = poly2.m_vertexCount;
var vertices2:Array = poly2.m_vertices;
var normals2:Array = poly2.m_normals;
tMat = xf1.R;
tVec = normals1[edge1];
var normal1X:Number = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
var normal1Y:Number = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = xf2.R;
var tX:Number = ((tMat.col1.x * normal1X) + (tMat.col1.y * normal1Y));
normal1Y = ((tMat.col2.x * normal1X) + (tMat.col2.y * normal1Y));
normal1X = tX;
var index:int;
var minDot:Number = Number.MAX_VALUE;
var i:int;
while (i < count2) {
tVec = normals2[i];
dot = ((normal1X * tVec.x) + (normal1Y * tVec.y));
if (dot < minDot){
minDot = dot;
index = i;
};
i++;
};
var i1:int = index;
var i2:int = (((i1 + 1) < count2)) ? (i1 + 1) : 0;
tClip = c[0];
tVec = vertices2[i1];
tMat = xf2.R;
tClip.v.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
tClip.v.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tClip.id.features.referenceEdge = edge1;
tClip.id.features.incidentEdge = i1;
tClip.id.features.incidentVertex = 0;
tClip = c[1];
tVec = vertices2[i2];
tMat = xf2.R;
tClip.v.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
tClip.v.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tClip.id.features.referenceEdge = edge1;
tClip.id.features.incidentEdge = i2;
tClip.id.features.incidentVertex = 1;
}
public static function b2CollidePolygons(manifold:b2Manifold, polyA:b2PolygonShape, xfA:b2XForm, polyB:b2PolygonShape, xfB:b2XForm):void{
var cv:ClipVertex;
var poly1:b2PolygonShape;
var poly2:b2PolygonShape;
var edge1:int;
var flip:uint;
var np:int;
var v12:b2Vec2;
var separation:Number;
var cp:b2ManifoldPoint;
manifold.pointCount = 0;
var edgeA:int;
var edgeAO:Array = [edgeA];
var separationA:Number = FindMaxSeparation(edgeAO, polyA, xfA, polyB, xfB);
edgeA = edgeAO[0];
if (separationA > 0){
return;
};
var edgeB:int;
var edgeBO:Array = [edgeB];
var separationB:Number = FindMaxSeparation(edgeBO, polyB, xfB, polyA, xfA);
edgeB = edgeBO[0];
if (separationB > 0){
return;
};
var xf1:b2XForm = new b2XForm();
var xf2:b2XForm = new b2XForm();
var k_relativeTol:Number = 0.98;
var k_absoluteTol:Number = 0.001;
if (separationB > ((k_relativeTol * separationA) + k_absoluteTol)){
poly1 = polyB;
poly2 = polyA;
xf1.Set(xfB);
xf2.Set(xfA);
edge1 = edgeB;
flip = 1;
} else {
poly1 = polyA;
poly2 = polyB;
xf1.Set(xfA);
xf2.Set(xfB);
edge1 = edgeA;
flip = 0;
};
var incidentEdge:Array = [new ClipVertex(), new ClipVertex()];
FindIncidentEdge(incidentEdge, poly1, xf1, edge1, poly2, xf2);
var count1:int = poly1.m_vertexCount;
var vertices1:Array = poly1.m_vertices;
var tVec:b2Vec2 = vertices1[edge1];
var v11:b2Vec2 = tVec.Copy();
if ((edge1 + 1) < count1){
tVec = vertices1[int((edge1 + 1))];
v12 = tVec.Copy();
} else {
tVec = vertices1[0];
v12 = tVec.Copy();
};
var dv:b2Vec2 = b2Math.SubtractVV(v12, v11);
var sideNormal:b2Vec2 = b2Math.b2MulMV(xf1.R, b2Math.SubtractVV(v12, v11));
sideNormal.Normalize();
var frontNormal:b2Vec2 = b2Math.b2CrossVF(sideNormal, 1);
v11 = b2Math.b2MulX(xf1, v11);
v12 = b2Math.b2MulX(xf1, v12);
var frontOffset:Number = b2Math.b2Dot(frontNormal, v11);
var sideOffset1:Number = -(b2Math.b2Dot(sideNormal, v11));
var sideOffset2:Number = b2Math.b2Dot(sideNormal, v12);
var clipPoints1:Array = [new ClipVertex(), new ClipVertex()];
var clipPoints2:Array = [new ClipVertex(), new ClipVertex()];
np = ClipSegmentToLine(clipPoints1, incidentEdge, sideNormal.Negative(), sideOffset1);
if (np < 2){
return;
};
np = ClipSegmentToLine(clipPoints2, clipPoints1, sideNormal, sideOffset2);
if (np < 2){
return;
};
manifold.normal = (flip) ? frontNormal.Negative() : frontNormal.Copy();
var pointCount:int;
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
cv = clipPoints2[i];
separation = (b2Math.b2Dot(frontNormal, cv.v) - frontOffset);
if (separation <= 0){
cp = manifold.points[pointCount];
cp.separation = separation;
cp.localPoint1 = b2Math.b2MulXT(xfA, cv.v);
cp.localPoint2 = b2Math.b2MulXT(xfB, cv.v);
cp.id.key = cv.id._key;
cp.id.features.flip = flip;
pointCount++;
};
i++;
};
manifold.pointCount = pointCount;
}
public static function FindMaxSeparation(edgeIndex:Array, poly1:b2PolygonShape, xf1:b2XForm, poly2:b2PolygonShape, xf2:b2XForm):Number{
var tVec:b2Vec2;
var tMat:b2Mat22;
var bestEdge:int;
var bestSeparation:Number;
var increment:int;
var dot:Number;
var count1:int = poly1.m_vertexCount;
var normals1:Array = poly1.m_normals;
tMat = xf2.R;
tVec = poly2.m_centroid;
var dX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var dY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tMat = xf1.R;
tVec = poly1.m_centroid;
dX = (dX - (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y))));
dY = (dY - (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y))));
var dLocal1X:Number = ((dX * xf1.R.col1.x) + (dY * xf1.R.col1.y));
var dLocal1Y:Number = ((dX * xf1.R.col2.x) + (dY * xf1.R.col2.y));
var edge:int;
var maxDot:Number = -(Number.MAX_VALUE);
var i:int;
while (i < count1) {
tVec = normals1[i];
dot = ((tVec.x * dLocal1X) + (tVec.y * dLocal1Y));
if (dot > maxDot){
maxDot = dot;
edge = i;
};
i++;
};
var s:Number = EdgeSeparation(poly1, xf1, edge, poly2, xf2);
if (s > 0){
return (s);
};
var prevEdge:int = (((edge - 1) >= 0)) ? (edge - 1) : (count1 - 1);
var sPrev:Number = EdgeSeparation(poly1, xf1, prevEdge, poly2, xf2);
if (sPrev > 0){
return (sPrev);
};
var nextEdge:int = (((edge + 1) < count1)) ? (edge + 1) : 0;
var sNext:Number = EdgeSeparation(poly1, xf1, nextEdge, poly2, xf2);
if (sNext > 0){
return (sNext);
};
if ((((sPrev > s)) && ((sPrev > sNext)))){
increment = -1;
bestEdge = prevEdge;
bestSeparation = sPrev;
} else {
if (sNext > s){
increment = 1;
bestEdge = nextEdge;
bestSeparation = sNext;
} else {
edgeIndex[0] = edge;
return (s);
};
};
while (true) {
if (increment == -1){
edge = (((bestEdge - 1) >= 0)) ? (bestEdge - 1) : (count1 - 1);
} else {
edge = (((bestEdge + 1) < count1)) ? (bestEdge + 1) : 0;
};
s = EdgeSeparation(poly1, xf1, edge, poly2, xf2);
if (s > 0){
return (s);
};
if (s > bestSeparation){
bestEdge = edge;
bestSeparation = s;
} else {
break;
};
};
edgeIndex[0] = bestEdge;
return (bestSeparation);
}
public static function ClipSegmentToLine(vOut:Array, vIn:Array, normal:b2Vec2, offset:Number):int{
var cv:ClipVertex;
var numOut:int;
var vIn0:b2Vec2;
var vIn1:b2Vec2;
var distance0:Number;
var interp:Number;
var tVec:b2Vec2;
var cv2:ClipVertex;
numOut = 0;
cv = vIn[0];
vIn0 = cv.v;
cv = vIn[1];
vIn1 = cv.v;
distance0 = (b2Math.b2Dot(normal, vIn0) - offset);
var distance1:Number = (b2Math.b2Dot(normal, vIn1) - offset);
if (distance0 <= 0){
var _temp1 = numOut;
numOut = (numOut + 1);
var _local14 = _temp1;
vOut[_local14] = vIn[0];
};
if (distance1 <= 0){
var _temp2 = numOut;
numOut = (numOut + 1);
_local14 = _temp2;
vOut[_local14] = vIn[1];
};
if ((distance0 * distance1) < 0){
interp = (distance0 / (distance0 - distance1));
cv = vOut[numOut];
tVec = cv.v;
tVec.x = (vIn0.x + (interp * (vIn1.x - vIn0.x)));
tVec.y = (vIn0.y + (interp * (vIn1.y - vIn0.y)));
cv = vOut[numOut];
if (distance0 > 0){
cv2 = vIn[0];
cv.id = cv2.id;
} else {
cv2 = vIn[1];
cv.id = cv2.id;
};
numOut++;
};
return (numOut);
}
public static function b2CollideCircles(manifold:b2Manifold, circle1:b2CircleShape, xf1:b2XForm, circle2:b2CircleShape, xf2:b2XForm):void{
var tMat:b2Mat22;
var tVec:b2Vec2;
var separation:Number;
var dist:Number;
var a:Number;
manifold.pointCount = 0;
tMat = xf1.R;
tVec = circle1.m_localPosition;
var p1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var p1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tMat = xf2.R;
tVec = circle2.m_localPosition;
var p2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var p2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
var dX:Number = (p2X - p1X);
var dY:Number = (p2Y - p1Y);
var distSqr:Number = ((dX * dX) + (dY * dY));
var r1:Number = circle1.m_radius;
var r2:Number = circle2.m_radius;
var radiusSum:Number = (r1 + r2);
if (distSqr > (radiusSum * radiusSum)){
return;
};
if (distSqr < Number.MIN_VALUE){
separation = -(radiusSum);
manifold.normal.Set(0, 1);
} else {
dist = Math.sqrt(distSqr);
separation = (dist - radiusSum);
a = (1 / dist);
manifold.normal.x = (a * dX);
manifold.normal.y = (a * dY);
};
manifold.pointCount = 1;
var tPoint:b2ManifoldPoint = manifold.points[0];
tPoint.id.key = 0;
tPoint.separation = separation;
p1X = (p1X + (r1 * manifold.normal.x));
p1Y = (p1Y + (r1 * manifold.normal.y));
p2X = (p2X - (r2 * manifold.normal.x));
p2Y = (p2Y - (r2 * manifold.normal.y));
var pX:Number = (0.5 * (p1X + p2X));
var pY:Number = (0.5 * (p1Y + p2Y));
var tX:Number = (pX - xf1.position.x);
var tY:Number = (pY - xf1.position.y);
tPoint.localPoint1.x = ((tX * xf1.R.col1.x) + (tY * xf1.R.col1.y));
tPoint.localPoint1.y = ((tX * xf1.R.col2.x) + (tY * xf1.R.col2.y));
tX = (pX - xf2.position.x);
tY = (pY - xf2.position.y);
tPoint.localPoint2.x = ((tX * xf2.R.col1.x) + (tY * xf2.R.col1.y));
tPoint.localPoint2.y = ((tX * xf2.R.col2.x) + (tY * xf2.R.col2.y));
}
public static function b2CollidePolygonAndCircle(manifold:b2Manifold, polygon:b2PolygonShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):void{
var tPoint:b2ManifoldPoint;
var dX:Number;
var dY:Number;
var positionX:Number;
var positionY:Number;
var tVec:b2Vec2;
var tMat:b2Mat22;
var dist:Number;
var pX:Number;
var pY:Number;
var s:Number;
manifold.pointCount = 0;
tMat = xf2.R;
tVec = circle.m_localPosition;
var cX:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var cY:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
dX = (cX - xf1.position.x);
dY = (cY - xf1.position.y);
tMat = xf1.R;
var cLocalX:Number = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
var cLocalY:Number = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
var normalIndex:int;
var separation:Number = -(Number.MAX_VALUE);
var radius:Number = circle.m_radius;
var vertexCount:int = polygon.m_vertexCount;
var vertices:Array = polygon.m_vertices;
var normals:Array = polygon.m_normals;
var i:int;
while (i < vertexCount) {
tVec = vertices[i];
dX = (cLocalX - tVec.x);
dY = (cLocalY - tVec.y);
tVec = normals[i];
s = ((tVec.x * dX) + (tVec.y * dY));
if (s > radius){
return;
};
if (s > separation){
separation = s;
normalIndex = i;
};
i++;
};
if (separation < Number.MIN_VALUE){
manifold.pointCount = 1;
tVec = normals[normalIndex];
tMat = xf1.R;
manifold.normal.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
manifold.normal.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tPoint = manifold.points[0];
tPoint.id.features.incidentEdge = normalIndex;
tPoint.id.features.incidentVertex = b2_nullFeature;
tPoint.id.features.referenceEdge = 0;
tPoint.id.features.flip = 0;
positionX = (cX - (radius * manifold.normal.x));
positionY = (cY - (radius * manifold.normal.y));
dX = (positionX - xf1.position.x);
dY = (positionY - xf1.position.y);
tMat = xf1.R;
tPoint.localPoint1.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
tPoint.localPoint1.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
dX = (positionX - xf2.position.x);
dY = (positionY - xf2.position.y);
tMat = xf2.R;
tPoint.localPoint2.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
tPoint.localPoint2.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
tPoint.separation = (separation - radius);
return;
};
var vertIndex1:int = normalIndex;
var vertIndex2:int = (((vertIndex1 + 1) < vertexCount)) ? (vertIndex1 + 1) : 0;
tVec = vertices[vertIndex1];
var tVec2:b2Vec2 = vertices[vertIndex2];
var eX:Number = (tVec2.x - tVec.x);
var eY:Number = (tVec2.y - tVec.y);
var length:Number = Math.sqrt(((eX * eX) + (eY * eY)));
eX = (eX / length);
eY = (eY / length);
dX = (cLocalX - tVec.x);
dY = (cLocalY - tVec.y);
var u:Number = ((dX * eX) + (dY * eY));
tPoint = manifold.points[0];
if (u <= 0){
pX = tVec.x;
pY = tVec.y;
tPoint.id.features.incidentEdge = b2_nullFeature;
tPoint.id.features.incidentVertex = vertIndex1;
} else {
if (u >= length){
pX = tVec2.x;
pY = tVec2.y;
tPoint.id.features.incidentEdge = b2_nullFeature;
tPoint.id.features.incidentVertex = vertIndex2;
} else {
pX = ((eX * u) + tVec.x);
pY = ((eY * u) + tVec.y);
tPoint.id.features.incidentEdge = normalIndex;
tPoint.id.features.incidentVertex = 0;
};
};
dX = (cLocalX - pX);
dY = (cLocalY - pY);
dist = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dist);
dY = (dY / dist);
if (dist > radius){
return;
};
manifold.pointCount = 1;
tMat = xf1.R;
manifold.normal.x = ((tMat.col1.x * dX) + (tMat.col2.x * dY));
manifold.normal.y = ((tMat.col1.y * dX) + (tMat.col2.y * dY));
positionX = (cX - (radius * manifold.normal.x));
positionY = (cY - (radius * manifold.normal.y));
dX = (positionX - xf1.position.x);
dY = (positionY - xf1.position.y);
tMat = xf1.R;
tPoint.localPoint1.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
tPoint.localPoint1.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
dX = (positionX - xf2.position.x);
dY = (positionY - xf2.position.y);
tMat = xf2.R;
tPoint.localPoint2.x = ((dX * tMat.col1.x) + (dY * tMat.col1.y));
tPoint.localPoint2.y = ((dX * tMat.col2.x) + (dY * tMat.col2.y));
tPoint.separation = (dist - radius);
tPoint.id.features.referenceEdge = 0;
tPoint.id.features.flip = 0;
}
}
}//package Box2D.Collision
Section 15
//b2ContactID (Box2D.Collision.b2ContactID)
package Box2D.Collision {
public class b2ContactID {
public var _key:uint;
public var features:Features;
public function b2ContactID(){
features = new Features();
super();
features._m_id = this;
}
public function Set(id:b2ContactID):void{
key = id._key;
}
public function Copy():b2ContactID{
var id:b2ContactID = new b2ContactID();
id.key = key;
return (id);
}
public function set key(value:uint):void{
_key = value;
features._referenceEdge = (_key & 0xFF);
features._incidentEdge = (((_key & 0xFF00) >> 8) & 0xFF);
features._incidentVertex = (((_key & 0xFF0000) >> 16) & 0xFF);
features._flip = (((_key & 4278190080) >> 24) & 0xFF);
}
public function get key():uint{
return (_key);
}
}
}//package Box2D.Collision
Section 16
//b2ContactPoint (Box2D.Collision.b2ContactPoint)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
public class b2ContactPoint {
public var friction:Number;
public var separation:Number;
public var normal:b2Vec2;
public var position:b2Vec2;
public var restitution:Number;
public var shape1:b2Shape;
public var shape2:b2Shape;
public var id:b2ContactID;
public var velocity:b2Vec2;
public function b2ContactPoint(){
position = new b2Vec2();
velocity = new b2Vec2();
normal = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Box2D.Collision
Section 17
//b2Distance (Box2D.Collision.b2Distance)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2Distance {
private static var s_p2s:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()];
private static var s_p1s:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()];
private static var s_points:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2()];
private static var gPoint:b2Point = new b2Point();
public static var g_GJK_Iterations:int = 0;
public function b2Distance(){
super();
}
public static function InPoints(w:b2Vec2, points:Array, pointCount:int):Boolean{
var points_i:b2Vec2;
var dX:Number;
var dY:Number;
var mX:Number;
var mY:Number;
var k_tolerance:Number = (100 * Number.MIN_VALUE);
var i:int;
while (i < pointCount) {
points_i = points[i];
dX = Math.abs((w.x - points_i.x));
dY = Math.abs((w.y - points_i.y));
mX = Math.max(Math.abs(w.x), Math.abs(points_i.x));
mY = Math.max(Math.abs(w.y), Math.abs(points_i.y));
if ((((dX < (k_tolerance * (mX + 1)))) && ((dY < (k_tolerance * (mY + 1)))))){
return (true);
};
i++;
};
return (false);
}
public static function DistanceGeneric(x1:b2Vec2, x2:b2Vec2, shape1, xf1:b2XForm, shape2, xf2:b2XForm):Number{
var tVec:b2Vec2;
var vX:Number;
var vY:Number;
var w1:b2Vec2;
var w2:b2Vec2;
var wX:Number;
var wY:Number;
var vw:Number;
var maxSqr:Number;
var i:int;
var p1s:Array = s_p1s;
var p2s:Array = s_p2s;
var points:Array = s_points;
var pointCount:int;
x1.SetV(shape1.GetFirstVertex(xf1));
x2.SetV(shape2.GetFirstVertex(xf2));
var vSqr:Number = 0;
var maxIterations = 20;
var iter:int;
while (iter < maxIterations) {
vX = (x2.x - x1.x);
vY = (x2.y - x1.y);
w1 = shape1.Support(xf1, vX, vY);
w2 = shape2.Support(xf2, -(vX), -(vY));
vSqr = ((vX * vX) + (vY * vY));
wX = (w2.x - w1.x);
wY = (w2.y - w1.y);
vw = ((vX * wX) + (vY * wY));
if ((vSqr - ((vX * wX) + (vY * wY))) <= (0.01 * vSqr)){
if (pointCount == 0){
x1.SetV(w1);
x2.SetV(w2);
};
g_GJK_Iterations = iter;
return (Math.sqrt(vSqr));
};
switch (pointCount){
case 0:
tVec = p1s[0];
tVec.SetV(w1);
tVec = p2s[0];
tVec.SetV(w2);
tVec = points[0];
tVec.x = wX;
tVec.y = wY;
x1.SetV(p1s[0]);
x2.SetV(p2s[0]);
pointCount++;
break;
case 1:
tVec = p1s[1];
tVec.SetV(w1);
tVec = p2s[1];
tVec.SetV(w2);
tVec = points[1];
tVec.x = wX;
tVec.y = wY;
pointCount = ProcessTwo(x1, x2, p1s, p2s, points);
break;
case 2:
tVec = p1s[2];
tVec.SetV(w1);
tVec = p2s[2];
tVec.SetV(w2);
tVec = points[2];
tVec.x = wX;
tVec.y = wY;
pointCount = ProcessThree(x1, x2, p1s, p2s, points);
break;
};
if (pointCount == 3){
g_GJK_Iterations = iter;
return (0);
};
maxSqr = -(Number.MAX_VALUE);
i = 0;
while (i < pointCount) {
tVec = points[i];
maxSqr = b2Math.b2Max(maxSqr, ((tVec.x * tVec.x) + (tVec.y * tVec.y)));
i++;
};
if ((((pointCount == 3)) || ((vSqr <= ((100 * Number.MIN_VALUE) * maxSqr))))){
g_GJK_Iterations = iter;
vX = (x2.x - x1.x);
vY = (x2.y - x1.y);
vSqr = ((vX * vX) + (vY * vY));
return (Math.sqrt(vSqr));
};
iter++;
};
g_GJK_Iterations = maxIterations;
return (Math.sqrt(vSqr));
}
public static function DistanceCC(x1:b2Vec2, x2:b2Vec2, circle1:b2CircleShape, xf1:b2XForm, circle2:b2CircleShape, xf2:b2XForm):Number{
var tMat:b2Mat22;
var tVec:b2Vec2;
var dLen:Number;
var distance:Number;
tMat = xf1.R;
tVec = circle1.m_localPosition;
var p1X:Number = (xf1.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var p1Y:Number = (xf1.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
tMat = xf2.R;
tVec = circle2.m_localPosition;
var p2X:Number = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
var p2Y:Number = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
var dX:Number = (p2X - p1X);
var dY:Number = (p2Y - p1Y);
var dSqr:Number = ((dX * dX) + (dY * dY));
var r1:Number = (circle1.m_radius - b2Settings.b2_toiSlop);
var r2:Number = (circle2.m_radius - b2Settings.b2_toiSlop);
var r:Number = (r1 + r2);
if (dSqr > (r * r)){
dLen = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dLen);
dY = (dY / dLen);
distance = (dLen - r);
x1.x = (p1X + (r1 * dX));
x1.y = (p1Y + (r1 * dY));
x2.x = (p2X - (r2 * dX));
x2.y = (p2Y - (r2 * dY));
return (distance);
};
if (dSqr > (Number.MIN_VALUE * Number.MIN_VALUE)){
dLen = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dLen);
dY = (dY / dLen);
x1.x = (p1X + (r1 * dX));
x1.y = (p1Y + (r1 * dY));
x2.x = x1.x;
x2.y = x1.y;
return (0);
};
x1.x = p1X;
x1.y = p1Y;
x2.x = x1.x;
x2.y = x1.y;
return (0);
}
public static function ProcessThree(x1:b2Vec2, x2:b2Vec2, p1s:Array, p2s:Array, points:Array):int{
var points_0:b2Vec2;
var points_1:b2Vec2;
var points_2:b2Vec2;
var p1s_0:b2Vec2;
var p1s_1:b2Vec2;
var p1s_2:b2Vec2;
var p2s_0:b2Vec2;
var p2s_1:b2Vec2;
var lambda:Number;
points_0 = points[0];
points_1 = points[1];
points_2 = points[2];
p1s_0 = p1s[0];
p1s_1 = p1s[1];
p1s_2 = p1s[2];
p2s_0 = p2s[0];
p2s_1 = p2s[1];
var p2s_2:b2Vec2 = p2s[2];
var aX:Number = points_0.x;
var aY:Number = points_0.y;
var bX:Number = points_1.x;
var bY:Number = points_1.y;
var cX:Number = points_2.x;
var cY:Number = points_2.y;
var abX:Number = (bX - aX);
var abY:Number = (bY - aY);
var acX:Number = (cX - aX);
var acY:Number = (cY - aY);
var bcX:Number = (cX - bX);
var bcY:Number = (cY - bY);
var sn:Number = -(((aX * abX) + (aY * abY)));
var sd:Number = ((bX * abX) + (bY * abY));
var tn:Number = -(((aX * acX) + (aY * acY)));
var td:Number = ((cX * acX) + (cY * acY));
var un:Number = -(((bX * bcX) + (bY * bcY)));
var ud:Number = ((cX * bcX) + (cY * bcY));
if ((((td <= 0)) && ((ud <= 0)))){
x1.SetV(p1s_2);
x2.SetV(p2s_2);
p1s_0.SetV(p1s_2);
p2s_0.SetV(p2s_2);
points_0.SetV(points_2);
return (1);
};
var n:Number = ((abX * acY) - (abY * acX));
var vc:Number = (n * ((aX * bY) - (aY * bX)));
var va:Number = (n * ((bX * cY) - (bY * cX)));
if ((((((((va <= 0)) && ((un >= 0)))) && ((ud >= 0)))) && (((un + ud) > 0)))){
lambda = (un / (un + ud));
x1.x = (p1s_1.x + (lambda * (p1s_2.x - p1s_1.x)));
x1.y = (p1s_1.y + (lambda * (p1s_2.y - p1s_1.y)));
x2.x = (p2s_1.x + (lambda * (p2s_2.x - p2s_1.x)));
x2.y = (p2s_1.y + (lambda * (p2s_2.y - p2s_1.y)));
p1s_0.SetV(p1s_2);
p2s_0.SetV(p2s_2);
points_0.SetV(points_2);
return (2);
};
var vb:Number = (n * ((cX * aY) - (cY * aX)));
if ((((((((vb <= 0)) && ((tn >= 0)))) && ((td >= 0)))) && (((tn + td) > 0)))){
lambda = (tn / (tn + td));
x1.x = (p1s_0.x + (lambda * (p1s_2.x - p1s_0.x)));
x1.y = (p1s_0.y + (lambda * (p1s_2.y - p1s_0.y)));
x2.x = (p2s_0.x + (lambda * (p2s_2.x - p2s_0.x)));
x2.y = (p2s_0.y + (lambda * (p2s_2.y - p2s_0.y)));
p1s_1.SetV(p1s_2);
p2s_1.SetV(p2s_2);
points_1.SetV(points_2);
return (2);
};
var denom:Number = ((va + vb) + vc);
denom = (1 / denom);
var u:Number = (va * denom);
var v:Number = (vb * denom);
var w:Number = ((1 - u) - v);
x1.x = (((u * p1s_0.x) + (v * p1s_1.x)) + (w * p1s_2.x));
x1.y = (((u * p1s_0.y) + (v * p1s_1.y)) + (w * p1s_2.y));
x2.x = (((u * p2s_0.x) + (v * p2s_1.x)) + (w * p2s_2.x));
x2.y = (((u * p2s_0.y) + (v * p2s_1.y)) + (w * p2s_2.y));
return (3);
}
public static function DistancePC(x1:b2Vec2, x2:b2Vec2, polygon:b2PolygonShape, xf1:b2XForm, circle:b2CircleShape, xf2:b2XForm):Number{
var tMat:b2Mat22;
var tVec:b2Vec2;
var dX:Number;
var dY:Number;
var dLen:Number;
var point:b2Point = gPoint;
tVec = circle.m_localPosition;
tMat = xf2.R;
point.p.x = (xf2.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
point.p.y = (xf2.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
var distance:Number = DistanceGeneric(x1, x2, polygon, xf1, point, b2Math.b2XForm_identity);
var r:Number = (circle.m_radius - b2Settings.b2_toiSlop);
if (distance > r){
distance = (distance - r);
dX = (x2.x - x1.x);
dY = (x2.y - x1.y);
dLen = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / dLen);
dY = (dY / dLen);
x2.x = (x2.x - (r * dX));
x2.y = (x2.y - (r * dY));
} else {
distance = 0;
x2.x = x1.x;
x2.y = x1.y;
};
return (distance);
}
public static function Distance(x1:b2Vec2, x2:b2Vec2, shape1:b2Shape, xf1:b2XForm, shape2:b2Shape, xf2:b2XForm):Number{
var type1:int = shape1.m_type;
var type2:int = shape2.m_type;
if ((((type1 == b2Shape.e_circleShape)) && ((type2 == b2Shape.e_circleShape)))){
return (DistanceCC(x1, x2, (shape1 as b2CircleShape), xf1, (shape2 as b2CircleShape), xf2));
};
if ((((type1 == b2Shape.e_polygonShape)) && ((type2 == b2Shape.e_circleShape)))){
return (DistancePC(x1, x2, (shape1 as b2PolygonShape), xf1, (shape2 as b2CircleShape), xf2));
};
if ((((type1 == b2Shape.e_circleShape)) && ((type2 == b2Shape.e_polygonShape)))){
return (DistancePC(x2, x1, (shape2 as b2PolygonShape), xf2, (shape1 as b2CircleShape), xf1));
};
if ((((type1 == b2Shape.e_polygonShape)) && ((type2 == b2Shape.e_polygonShape)))){
return (DistanceGeneric(x1, x2, (shape1 as b2PolygonShape), xf1, (shape2 as b2PolygonShape), xf2));
};
return (0);
}
public static function ProcessTwo(x1:b2Vec2, x2:b2Vec2, p1s:Array, p2s:Array, points:Array):int{
var p1s_1:b2Vec2;
var p2s_0:b2Vec2;
var p2s_1:b2Vec2;
var lambda:Number;
var points_0:b2Vec2 = points[0];
var points_1:b2Vec2 = points[1];
var p1s_0:b2Vec2 = p1s[0];
p1s_1 = p1s[1];
p2s_0 = p2s[0];
p2s_1 = p2s[1];
var rX:Number = -(points_1.x);
var rY:Number = -(points_1.y);
var dX:Number = (points_0.x - points_1.x);
var dY:Number = (points_0.y - points_1.y);
var length:Number = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / length);
dY = (dY / length);
lambda = ((rX * dX) + (rY * dY));
if ((((lambda <= 0)) || ((length < Number.MIN_VALUE)))){
x1.SetV(p1s_1);
x2.SetV(p2s_1);
p1s_0.SetV(p1s_1);
p2s_0.SetV(p2s_1);
points_0.SetV(points_1);
return (1);
};
lambda = (lambda / length);
x1.x = (p1s_1.x + (lambda * (p1s_0.x - p1s_1.x)));
x1.y = (p1s_1.y + (lambda * (p1s_0.y - p1s_1.y)));
x2.x = (p2s_1.x + (lambda * (p2s_0.x - p2s_1.x)));
x2.y = (p2s_1.y + (lambda * (p2s_0.y - p2s_1.y)));
return (2);
}
}
}//package Box2D.Collision
Section 18
//b2Manifold (Box2D.Collision.b2Manifold)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2Manifold {
public var pointCount:int;// = 0
public var normal:b2Vec2;
public var points:Array;
public function b2Manifold(){
super();
points = new Array(b2Settings.b2_maxManifoldPoints);
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
points[i] = new b2ManifoldPoint();
i++;
};
normal = new b2Vec2();
}
public function Set(m:b2Manifold):void{
pointCount = m.pointCount;
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
(points[i] as b2ManifoldPoint).Set(m.points[i]);
i++;
};
normal.SetV(m.normal);
}
public function Reset():void{
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
(points[i] as b2ManifoldPoint).Reset();
i++;
};
normal.SetZero();
pointCount = 0;
}
}
}//package Box2D.Collision
Section 19
//b2ManifoldPoint (Box2D.Collision.b2ManifoldPoint)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class b2ManifoldPoint {
public var separation:Number;
public var localPoint2:b2Vec2;
public var normalImpulse:Number;
public var tangentImpulse:Number;
public var localPoint1:b2Vec2;
public var id:b2ContactID;
public function b2ManifoldPoint(){
localPoint1 = new b2Vec2();
localPoint2 = new b2Vec2();
id = new b2ContactID();
super();
}
public function Set(m:b2ManifoldPoint):void{
localPoint1.SetV(m.localPoint1);
localPoint2.SetV(m.localPoint2);
separation = m.separation;
normalImpulse = m.normalImpulse;
tangentImpulse = m.tangentImpulse;
id.key = m.id.key;
}
public function Reset():void{
localPoint1.SetZero();
localPoint2.SetZero();
separation = 0;
normalImpulse = 0;
tangentImpulse = 0;
id.key = 0;
}
}
}//package Box2D.Collision
Section 20
//b2OBB (Box2D.Collision.b2OBB)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class b2OBB {
public var R:b2Mat22;
public var center:b2Vec2;
public var extents:b2Vec2;
public function b2OBB(){
R = new b2Mat22();
center = new b2Vec2();
extents = new b2Vec2();
super();
}
}
}//package Box2D.Collision
Section 21
//b2Pair (Box2D.Collision.b2Pair)
package Box2D.Collision {
import Box2D.Common.*;
public class b2Pair {
public var proxyId1:uint;
public var userData;// = null
public var proxyId2:uint;
public var status:uint;
public var next:uint;
public static var e_pairFinal:uint = 4;
public static var b2_tableMask:int = (b2_tableCapacity - 1);
public static var e_pairRemoved:uint = 2;
public static var b2_nullPair:uint = b2Settings.USHRT_MAX;
public static var e_pairBuffered:uint = 1;
public static var b2_nullProxy:uint = b2Settings.USHRT_MAX;
public static var b2_tableCapacity:int = b2Settings.b2_maxPairs;
public function b2Pair(){
super();
}
public function SetBuffered():void{
status = (status | e_pairBuffered);
}
public function IsBuffered():Boolean{
return (((status & e_pairBuffered) == e_pairBuffered));
}
public function IsFinal():Boolean{
return (((status & e_pairFinal) == e_pairFinal));
}
public function ClearRemoved():void{
status = (status & ~(e_pairRemoved));
}
public function SetFinal():void{
status = (status | e_pairFinal);
}
public function IsRemoved():Boolean{
return (((status & e_pairRemoved) == e_pairRemoved));
}
public function ClearBuffered():void{
status = (status & ~(e_pairBuffered));
}
public function SetRemoved():void{
status = (status | e_pairRemoved);
}
}
}//package Box2D.Collision
Section 22
//b2PairCallback (Box2D.Collision.b2PairCallback)
package Box2D.Collision {
public class b2PairCallback {
public function b2PairCallback(){
super();
}
public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{
}
public function PairAdded(proxyUserData1, proxyUserData2){
return (null);
}
}
}//package Box2D.Collision
Section 23
//b2PairManager (Box2D.Collision.b2PairManager)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PairManager {
public var m_pairCount:int;
public var m_pairBuffer:Array;
public var m_hashTable:Array;
public var m_callback:b2PairCallback;
public var m_pairs:Array;
public var m_pairBufferCount:int;
public var m_broadPhase:b2BroadPhase;
public var m_freePair:uint;
public function b2PairManager(){
var i:uint;
super();
m_hashTable = new Array(b2Pair.b2_tableCapacity);
i = 0;
while (i < b2Pair.b2_tableCapacity) {
m_hashTable[i] = b2Pair.b2_nullPair;
i++;
};
m_pairs = new Array(b2Settings.b2_maxPairs);
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairs[i] = new b2Pair();
i++;
};
m_pairBuffer = new Array(b2Settings.b2_maxPairs);
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairBuffer[i] = new b2BufferedPair();
i++;
};
i = 0;
while (i < b2Settings.b2_maxPairs) {
m_pairs[i].proxyId1 = b2Pair.b2_nullProxy;
m_pairs[i].proxyId2 = b2Pair.b2_nullProxy;
m_pairs[i].userData = null;
m_pairs[i].status = 0;
m_pairs[i].next = (i + 1);
i++;
};
m_pairs[int((b2Settings.b2_maxPairs - 1))].next = b2Pair.b2_nullPair;
m_pairCount = 0;
m_pairBufferCount = 0;
}
private function FindHash(proxyId1:uint, proxyId2:uint, hash:uint):b2Pair{
var pair:b2Pair;
var index:uint = m_hashTable[hash];
pair = m_pairs[index];
while (((!((index == b2Pair.b2_nullPair))) && ((Equals(pair, proxyId1, proxyId2) == false)))) {
index = pair.next;
pair = m_pairs[index];
};
if (index == b2Pair.b2_nullPair){
return (null);
};
return (pair);
}
private function Find(proxyId1:uint, proxyId2:uint):b2Pair{
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
return (FindHash(proxyId1, proxyId2, hash));
}
private function ValidateBuffer():void{
}
public function Commit():void{
var bufferedPair:b2BufferedPair;
var i:int;
var pair:b2Pair;
var proxy1:b2Proxy;
var proxy2:b2Proxy;
var removeCount:int;
var proxies:Array = m_broadPhase.m_proxyPool;
i = 0;
while (i < m_pairBufferCount) {
bufferedPair = m_pairBuffer[i];
pair = Find(bufferedPair.proxyId1, bufferedPair.proxyId2);
pair.ClearBuffered();
proxy1 = proxies[pair.proxyId1];
proxy2 = proxies[pair.proxyId2];
if (pair.IsRemoved()){
if (pair.IsFinal() == true){
m_callback.PairRemoved(proxy1.userData, proxy2.userData, pair.userData);
};
bufferedPair = m_pairBuffer[removeCount];
bufferedPair.proxyId1 = pair.proxyId1;
bufferedPair.proxyId2 = pair.proxyId2;
removeCount++;
} else {
if (pair.IsFinal() == false){
pair.userData = m_callback.PairAdded(proxy1.userData, proxy2.userData);
pair.SetFinal();
};
};
i++;
};
i = 0;
while (i < removeCount) {
bufferedPair = m_pairBuffer[i];
RemovePair(bufferedPair.proxyId1, bufferedPair.proxyId2);
i++;
};
m_pairBufferCount = 0;
if (b2BroadPhase.s_validate){
ValidateTable();
};
}
public function RemoveBufferedPair(proxyId1:int, proxyId2:int):void{
var bufferedPair:b2BufferedPair;
var pair:b2Pair = Find(proxyId1, proxyId2);
if (pair == null){
return;
};
if (pair.IsBuffered() == false){
pair.SetBuffered();
bufferedPair = m_pairBuffer[m_pairBufferCount];
bufferedPair.proxyId1 = pair.proxyId1;
bufferedPair.proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
pair.SetRemoved();
if (b2BroadPhase.s_validate){
ValidateBuffer();
};
}
private function RemovePair(proxyId1:uint, proxyId2:uint){
var pair:b2Pair;
var temp:uint;
var index:uint;
var userData:*;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
var node:uint = m_hashTable[hash];
var pNode:b2Pair;
while (node != b2Pair.b2_nullPair) {
if (Equals(m_pairs[node], proxyId1, proxyId2)){
index = node;
pair = m_pairs[node];
if (pNode){
pNode.next = pair.next;
} else {
m_hashTable[hash] = pair.next;
};
pair = m_pairs[index];
userData = pair.userData;
pair.next = m_freePair;
pair.proxyId1 = b2Pair.b2_nullProxy;
pair.proxyId2 = b2Pair.b2_nullProxy;
pair.userData = null;
pair.status = 0;
m_freePair = index;
m_pairCount--;
return (userData);
} else {
pNode = m_pairs[node];
node = pNode.next;
};
};
return (null);
}
public function Initialize(broadPhase:b2BroadPhase, callback:b2PairCallback):void{
m_broadPhase = broadPhase;
m_callback = callback;
}
public function AddBufferedPair(proxyId1:int, proxyId2:int):void{
var bufferedPair:b2BufferedPair;
var pair:b2Pair = AddPair(proxyId1, proxyId2);
if (pair.IsBuffered() == false){
pair.SetBuffered();
bufferedPair = m_pairBuffer[m_pairBufferCount];
bufferedPair.proxyId1 = pair.proxyId1;
bufferedPair.proxyId2 = pair.proxyId2;
m_pairBufferCount++;
};
pair.ClearRemoved();
if (b2BroadPhase.s_validate){
ValidateBuffer();
};
}
private function AddPair(proxyId1:uint, proxyId2:uint):b2Pair{
var temp:uint;
if (proxyId1 > proxyId2){
temp = proxyId1;
proxyId1 = proxyId2;
proxyId2 = temp;
};
var hash:uint = (Hash(proxyId1, proxyId2) & b2Pair.b2_tableMask);
var pair = FindHash(proxyId1, proxyId2, hash);
if (pair != null){
return (pair);
};
var pIndex:uint = m_freePair;
pair = m_pairs[pIndex];
m_freePair = pair.next;
pair.proxyId1 = proxyId1;
pair.proxyId2 = proxyId2;
pair.status = 0;
pair.userData = null;
pair.next = m_hashTable[hash];
m_hashTable[hash] = pIndex;
m_pairCount++;
return (pair);
}
private function ValidateTable():void{
}
public static function EqualsPair(pair1:b2BufferedPair, pair2:b2BufferedPair):Boolean{
return ((((pair1.proxyId1 == pair2.proxyId1)) && ((pair1.proxyId2 == pair2.proxyId2))));
}
public static function Hash(proxyId1:uint, proxyId2:uint):uint{
var key:uint = (((proxyId2 << 16) & 4294901760) | proxyId1);
key = (~(key) + ((key << 15) & 4294934528));
key = (key ^ ((key >> 12) & 1048575));
key = (key + ((key << 2) & 4294967292));
key = (key ^ ((key >> 4) & 268435455));
key = (key * 2057);
key = (key ^ ((key >> 16) & 0xFFFF));
return (key);
}
public static function Equals(pair:b2Pair, proxyId1:uint, proxyId2:uint):Boolean{
return ((((pair.proxyId1 == proxyId1)) && ((pair.proxyId2 == proxyId2))));
}
}
}//package Box2D.Collision
Section 24
//b2Point (Box2D.Collision.b2Point)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class b2Point {
public var p:b2Vec2;
public function b2Point(){
p = new b2Vec2();
super();
}
public function GetFirstVertex(xf:b2XForm):b2Vec2{
return (p);
}
public function Support(xf:b2XForm, vX:Number, vY:Number):b2Vec2{
return (p);
}
}
}//package Box2D.Collision
Section 25
//b2Proxy (Box2D.Collision.b2Proxy)
package Box2D.Collision {
public class b2Proxy {
public var overlapCount:uint;
public var userData;// = null
public var lowerBounds:Array;
public var upperBounds:Array;
public var timeStamp:uint;
public function b2Proxy(){
lowerBounds = [uint(0), uint(0)];
upperBounds = [uint(0), uint(0)];
super();
}
public function GetNext():uint{
return (lowerBounds[0]);
}
public function IsValid():Boolean{
return (!((overlapCount == b2BroadPhase.b2_invalid)));
}
public function SetNext(next:uint):void{
lowerBounds[0] = (next & 0xFFFF);
}
}
}//package Box2D.Collision
Section 26
//b2Segment (Box2D.Collision.b2Segment)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2Segment {
public var p1:b2Vec2;
public var p2:b2Vec2;
public function b2Segment(){
p1 = new b2Vec2();
p2 = new b2Vec2();
super();
}
public function TestSegment(lambda:Array, normal:b2Vec2, segment:b2Segment, maxLambda:Number):Boolean{
var bX:Number;
var bY:Number;
var a:Number;
var mu2:Number;
var nLen:Number;
var s:b2Vec2 = segment.p1;
var rX:Number = (segment.p2.x - s.x);
var rY:Number = (segment.p2.y - s.y);
var dX:Number = (p2.x - p1.x);
var dY:Number = (p2.y - p1.y);
var nX:Number = dY;
var nY:Number = -(dX);
var k_slop:Number = (100 * Number.MIN_VALUE);
var denom:Number = -(((rX * nX) + (rY * nY)));
if (denom > k_slop){
bX = (s.x - p1.x);
bY = (s.y - p1.y);
a = ((bX * nX) + (bY * nY));
if ((((0 <= a)) && ((a <= (maxLambda * denom))))){
mu2 = ((-(rY) * bY) + (rY * bX));
if (((((-(k_slop) * denom) <= mu2)) && ((mu2 <= (denom * (1 + k_slop)))))){
a = (a / denom);
nLen = Math.sqrt(((nX * nX) + (nY * nY)));
nX = (nX / nLen);
nY = (nY / nLen);
lambda[0] = a;
normal.Set(nX, nY);
return (true);
};
};
};
return (false);
}
}
}//package Box2D.Collision
Section 27
//b2TimeOfImpact (Box2D.Collision.b2TimeOfImpact)
package Box2D.Collision {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Common.*;
public class b2TimeOfImpact {
public static var s_xf1:b2XForm = new b2XForm();
public static var s_xf2:b2XForm = new b2XForm();
public static var s_p1:b2Vec2 = new b2Vec2();
public static var s_p2:b2Vec2 = new b2Vec2();
public function b2TimeOfImpact(){
super();
}
public static function TimeOfImpact(shape1:b2Shape, sweep1:b2Sweep, shape2:b2Shape, sweep2:b2Sweep):Number{
var math1:Number;
var math2:Number;
var t:Number;
var xf1:b2XForm;
var xf2:b2XForm;
var nLen:Number;
var approachVelocityBound:Number;
var dAlpha:Number;
var newAlpha:Number;
var r1:Number = shape1.m_sweepRadius;
var r2:Number = shape2.m_sweepRadius;
var t0:Number = sweep1.t0;
var v1X:Number = (sweep1.c.x - sweep1.c0.x);
var v1Y:Number = (sweep1.c.y - sweep1.c0.y);
var v2X:Number = (sweep2.c.x - sweep2.c0.x);
var v2Y:Number = (sweep2.c.y - sweep2.c0.y);
var omega1:Number = (sweep1.a - sweep1.a0);
var omega2:Number = (sweep2.a - sweep2.a0);
var alpha:Number = 0;
var p1:b2Vec2 = s_p1;
var p2:b2Vec2 = s_p2;
var k_maxIterations = 20;
var iter:int;
var normalX:Number = 0;
var normalY:Number = 0;
var distance:Number = 0;
var targetDistance:Number = 0;
while (true) {
t = (((1 - alpha) * t0) + alpha);
xf1 = s_xf1;
xf2 = s_xf2;
sweep1.GetXForm(xf1, t);
sweep2.GetXForm(xf2, t);
distance = b2Distance.Distance(p1, p2, shape1, xf1, shape2, xf2);
if (iter == 0){
if (distance > (2 * b2Settings.b2_toiSlop)){
targetDistance = (1.5 * b2Settings.b2_toiSlop);
} else {
math1 = (0.05 * b2Settings.b2_toiSlop);
math2 = (distance - (0.5 * b2Settings.b2_toiSlop));
targetDistance = ((math1 > math2)) ? math1 : math2;
};
};
if (((((distance - targetDistance) < (0.05 * b2Settings.b2_toiSlop))) || ((iter == k_maxIterations)))){
break;
};
normalX = (p2.x - p1.x);
normalY = (p2.y - p1.y);
nLen = Math.sqrt(((normalX * normalX) + (normalY * normalY)));
normalX = (normalX / nLen);
normalY = (normalY / nLen);
approachVelocityBound = ((((normalX * (v1X - v2X)) + (normalY * (v1Y - v2Y))) + (((omega1 < 0)) ? -(omega1) : omega1 * r1)) + (((omega2 < 0)) ? -(omega2) : omega2 * r2));
if (approachVelocityBound == 0){
alpha = 1;
break;
};
dAlpha = ((distance - targetDistance) / approachVelocityBound);
newAlpha = (alpha + dAlpha);
if ((((newAlpha < 0)) || ((1 < newAlpha)))){
alpha = 1;
break;
};
if (newAlpha < ((1 + (100 * Number.MIN_VALUE)) * alpha)){
break;
};
alpha = newAlpha;
iter++;
};
return (alpha);
}
}
}//package Box2D.Collision
Section 28
//ClipVertex (Box2D.Collision.ClipVertex)
package Box2D.Collision {
import Box2D.Common.Math.*;
public class ClipVertex {
public var id:b2ContactID;
public var v:b2Vec2;
public function ClipVertex(){
v = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Box2D.Collision
Section 29
//Features (Box2D.Collision.Features)
package Box2D.Collision {
public class Features {
public var _referenceEdge:int;
public var _incidentEdge:int;
public var _flip:int;
public var _incidentVertex:int;
public var _m_id:b2ContactID;
public function Features(){
super();
}
public function get referenceEdge():int{
return (_referenceEdge);
}
public function set incidentVertex(value:int):void{
_incidentVertex = value;
_m_id._key = ((_m_id._key & 4278255615) | ((_incidentVertex << 16) & 0xFF0000));
}
public function get flip():int{
return (_flip);
}
public function get incidentEdge():int{
return (_incidentEdge);
}
public function set referenceEdge(value:int):void{
_referenceEdge = value;
_m_id._key = ((_m_id._key & 4294967040) | (_referenceEdge & 0xFF));
}
public function get incidentVertex():int{
return (_incidentVertex);
}
public function set flip(value:int):void{
_flip = value;
_m_id._key = ((_m_id._key & 0xFFFFFF) | ((_flip << 24) & 4278190080));
}
public function set incidentEdge(value:int):void{
_incidentEdge = value;
_m_id._key = ((_m_id._key & 4294902015) | ((_incidentEdge << 8) & 0xFF00));
}
}
}//package Box2D.Collision
Section 30
//b2Mat22 (Box2D.Common.Math.b2Mat22)
package Box2D.Common.Math {
public class b2Mat22 {
public var col1:b2Vec2;
public var col2:b2Vec2;
public function b2Mat22(angle:Number=0, c1:b2Vec2=null, c2:b2Vec2=null){
var c:Number;
var s:Number;
col1 = new b2Vec2();
col2 = new b2Vec2();
super();
if (((!((c1 == null))) && (!((c2 == null))))){
col1.SetV(c1);
col2.SetV(c2);
} else {
c = Math.cos(angle);
s = Math.sin(angle);
col1.x = c;
col2.x = -(s);
col1.y = s;
col2.y = c;
};
}
public function SetIdentity():void{
col1.x = 1;
col2.x = 0;
col1.y = 0;
col2.y = 1;
}
public function SetVV(c1:b2Vec2, c2:b2Vec2):void{
col1.SetV(c1);
col2.SetV(c2);
}
public function Set(angle:Number):void{
var c:Number;
c = Math.cos(angle);
var s:Number = Math.sin(angle);
col1.x = c;
col2.x = -(s);
col1.y = s;
col2.y = c;
}
public function SetZero():void{
col1.x = 0;
col2.x = 0;
col1.y = 0;
col2.y = 0;
}
public function SetM(m:b2Mat22):void{
col1.SetV(m.col1);
col2.SetV(m.col2);
}
public function AddM(m:b2Mat22):void{
col1.x = (col1.x + m.col1.x);
col1.y = (col1.y + m.col1.y);
col2.x = (col2.x + m.col2.x);
col2.y = (col2.y + m.col2.y);
}
public function Abs():void{
col1.Abs();
col2.Abs();
}
public function Copy():b2Mat22{
return (new b2Mat22(0, col1, col2));
}
public function Invert(out:b2Mat22):b2Mat22{
var a:Number;
var c:Number;
var det:Number;
a = col1.x;
var b:Number = col2.x;
c = col1.y;
var d:Number = col2.y;
det = ((a * d) - (b * c));
det = (1 / det);
out.col1.x = (det * d);
out.col2.x = (-(det) * b);
out.col1.y = (-(det) * c);
out.col2.y = (det * a);
return (out);
}
public function GetAngle():Number{
return (Math.atan2(col1.y, col1.x));
}
public function Solve(out:b2Vec2, bX:Number, bY:Number):b2Vec2{
var a11:Number = col1.x;
var a12:Number = col2.x;
var a21:Number = col1.y;
var a22:Number = col2.y;
var det:Number = ((a11 * a22) - (a12 * a21));
det = (1 / det);
out.x = (det * ((a22 * bX) - (a12 * bY)));
out.y = (det * ((a11 * bY) - (a21 * bX)));
return (out);
}
}
}//package Box2D.Common.Math
Section 31
//b2Math (Box2D.Common.Math.b2Math)
package Box2D.Common.Math {
public class b2Math {
public static const b2Mat22_identity:b2Mat22 = new b2Mat22(0, new b2Vec2(1, 0), new b2Vec2(0, 1));
public static const b2XForm_identity:b2XForm = new b2XForm(b2Vec2_zero, b2Mat22_identity);
public static const b2Vec2_zero:b2Vec2 = new b2Vec2(0, 0);
public function b2Math(){
super();
}
public static function b2CrossVF(a:b2Vec2, s:Number):b2Vec2{
var v:b2Vec2 = new b2Vec2((s * a.y), (-(s) * a.x));
return (v);
}
public static function AddVV(a:b2Vec2, b:b2Vec2):b2Vec2{
var v:b2Vec2 = new b2Vec2((a.x + b.x), (a.y + b.y));
return (v);
}
public static function b2IsValid(x:Number):Boolean{
return (isFinite(x));
}
public static function b2MinV(a:b2Vec2, b:b2Vec2):b2Vec2{
var c:b2Vec2 = new b2Vec2(b2Min(a.x, b.x), b2Min(a.y, b.y));
return (c);
}
public static function b2MulX(T:b2XForm, v:b2Vec2):b2Vec2{
var a:b2Vec2;
a = b2MulMV(T.R, v);
a.x = (a.x + T.position.x);
a.y = (a.y + T.position.y);
return (a);
}
public static function b2DistanceSquared(a:b2Vec2, b:b2Vec2):Number{
var cX:Number = (a.x - b.x);
var cY:Number = (a.y - b.y);
return (((cX * cX) + (cY * cY)));
}
public static function b2Swap(a:Array, b:Array):void{
var tmp:* = a[0];
a[0] = b[0];
b[0] = tmp;
}
public static function b2AbsM(A:b2Mat22):b2Mat22{
var B:b2Mat22 = new b2Mat22(0, b2AbsV(A.col1), b2AbsV(A.col2));
return (B);
}
public static function SubtractVV(a:b2Vec2, b:b2Vec2):b2Vec2{
var v:b2Vec2 = new b2Vec2((a.x - b.x), (a.y - b.y));
return (v);
}
public static function b2MulXT(T:b2XForm, v:b2Vec2):b2Vec2{
var a:b2Vec2;
var tX:Number;
a = SubtractVV(v, T.position);
tX = ((a.x * T.R.col1.x) + (a.y * T.R.col1.y));
a.y = ((a.x * T.R.col2.x) + (a.y * T.R.col2.y));
a.x = tX;
return (a);
}
public static function b2Abs(a:Number):Number{
return (((a > 0)) ? a : -(a));
}
public static function b2Clamp(a:Number, low:Number, high:Number):Number{
return (b2Max(low, b2Min(a, high)));
}
public static function b2AbsV(a:b2Vec2):b2Vec2{
var b:b2Vec2 = new b2Vec2(b2Abs(a.x), b2Abs(a.y));
return (b);
}
public static function MulFV(s:Number, a:b2Vec2):b2Vec2{
var v:b2Vec2 = new b2Vec2((s * a.x), (s * a.y));
return (v);
}
public static function b2CrossVV(a:b2Vec2, b:b2Vec2):Number{
return (((a.x * b.y) - (a.y * b.x)));
}
public static function b2Dot(a:b2Vec2, b:b2Vec2):Number{
return (((a.x * b.x) + (a.y * b.y)));
}
public static function b2CrossFV(s:Number, a:b2Vec2):b2Vec2{
var v:b2Vec2 = new b2Vec2((-(s) * a.y), (s * a.x));
return (v);
}
public static function AddMM(A:b2Mat22, B:b2Mat22):b2Mat22{
var C:b2Mat22 = new b2Mat22(0, AddVV(A.col1, B.col1), AddVV(A.col2, B.col2));
return (C);
}
public static function b2Distance(a:b2Vec2, b:b2Vec2):Number{
var cX:Number = (a.x - b.x);
var cY:Number = (a.y - b.y);
return (Math.sqrt(((cX * cX) + (cY * cY))));
}
public static function b2MulTMM(A:b2Mat22, B:b2Mat22):b2Mat22{
var c1:b2Vec2 = new b2Vec2(b2Dot(A.col1, B.col1), b2Dot(A.col2, B.col1));
var c2:b2Vec2 = new b2Vec2(b2Dot(A.col1, B.col2), b2Dot(A.col2, B.col2));
var C:b2Mat22 = new b2Mat22(0, c1, c2);
return (C);
}
public static function b2MaxV(a:b2Vec2, b:b2Vec2):b2Vec2{
var c:b2Vec2 = new b2Vec2(b2Max(a.x, b.x), b2Max(a.y, b.y));
return (c);
}
public static function b2IsPowerOfTwo(x:uint):Boolean{
var result:Boolean = (((x > 0)) && (((x & (x - 1)) == 0)));
return (result);
}
public static function b2ClampV(a:b2Vec2, low:b2Vec2, high:b2Vec2):b2Vec2{
return (b2MaxV(low, b2MinV(a, high)));
}
public static function b2RandomRange(lo:Number, hi:Number):Number{
var r:Number = Math.random();
r = (((hi - lo) * r) + lo);
return (r);
}
public static function b2MulTMV(A:b2Mat22, v:b2Vec2):b2Vec2{
var u:b2Vec2 = new b2Vec2(b2Dot(v, A.col1), b2Dot(v, A.col2));
return (u);
}
public static function b2Min(a:Number, b:Number):Number{
return (((a < b)) ? a : b);
}
public static function b2Random():Number{
return (((Math.random() * 2) - 1));
}
public static function b2MulMM(A:b2Mat22, B:b2Mat22):b2Mat22{
var C:b2Mat22 = new b2Mat22(0, b2MulMV(A, B.col1), b2MulMV(A, B.col2));
return (C);
}
public static function b2NextPowerOfTwo(x:uint):uint{
x = (x | ((x >> 1) & 2147483647));
x = (x | ((x >> 2) & 1073741823));
x = (x | ((x >> 4) & 268435455));
x = (x | ((x >> 8) & 0xFFFFFF));
x = (x | ((x >> 16) & 0xFFFF));
return ((x + 1));
}
public static function b2Max(a:Number, b:Number):Number{
return (((a > b)) ? a : b);
}
public static function b2MulMV(A:b2Mat22, v:b2Vec2):b2Vec2{
var u:b2Vec2 = new b2Vec2(((A.col1.x * v.x) + (A.col2.x * v.y)), ((A.col1.y * v.x) + (A.col2.y * v.y)));
return (u);
}
}
}//package Box2D.Common.Math
Section 32
//b2Sweep (Box2D.Common.Math.b2Sweep)
package Box2D.Common.Math {
public class b2Sweep {
public var localCenter:b2Vec2;
public var a:Number;
public var c:b2Vec2;
public var a0:Number;
public var c0:b2Vec2;
public var t0:Number;
public function b2Sweep(){
localCenter = new b2Vec2();
c0 = new b2Vec2();
c = new b2Vec2();
super();
}
public function Advance(t:Number):void{
var alpha:Number;
if ((((t0 < t)) && (((1 - t0) > Number.MIN_VALUE)))){
alpha = ((t - t0) / (1 - t0));
c0.x = (((1 - alpha) * c0.x) + (alpha * c.x));
c0.y = (((1 - alpha) * c0.y) + (alpha * c.y));
a0 = (((1 - alpha) * a0) + (alpha * a));
t0 = t;
};
}
public function GetXForm(xf:b2XForm, t:Number):void{
var alpha:Number;
var angle:Number;
if ((1 - t0) > Number.MIN_VALUE){
alpha = ((t - t0) / (1 - t0));
xf.position.x = (((1 - alpha) * c0.x) + (alpha * c.x));
xf.position.y = (((1 - alpha) * c0.y) + (alpha * c.y));
angle = (((1 - alpha) * a0) + (alpha * a));
xf.R.Set(angle);
} else {
xf.position.SetV(c);
xf.R.Set(a);
};
var tMat:b2Mat22 = xf.R;
xf.position.x = (xf.position.x - ((tMat.col1.x * localCenter.x) + (tMat.col2.x * localCenter.y)));
xf.position.y = (xf.position.y - ((tMat.col1.y * localCenter.x) + (tMat.col2.y * localCenter.y)));
}
}
}//package Box2D.Common.Math
Section 33
//b2Vec2 (Box2D.Common.Math.b2Vec2)
package Box2D.Common.Math {
public class b2Vec2 {
public var y:Number;
public var x:Number;
public function b2Vec2(x_:Number=0, y_:Number=0):void{
super();
x = x_;
y = y_;
}
public function Add(v:b2Vec2):void{
x = (x + v.x);
y = (y + v.y);
}
public function Set(x_:Number=0, y_:Number=0):void{
x = x_;
y = y_;
}
public function Multiply(a:Number):void{
x = (x * a);
y = (y * a);
}
public function Length():Number{
return (Math.sqrt(((x * x) + (y * y))));
}
public function LengthSquared():Number{
return (((x * x) + (y * y)));
}
public function MulM(A:b2Mat22):void{
var tX:Number = x;
x = ((A.col1.x * tX) + (A.col2.x * y));
y = ((A.col1.y * tX) + (A.col2.y * y));
}
public function SetZero():void{
x = 0;
y = 0;
}
public function MinV(b:b2Vec2):void{
x = ((x < b.x)) ? x : b.x;
y = ((y < b.y)) ? y : b.y;
}
public function Normalize():Number{
var length:Number = Math.sqrt(((x * x) + (y * y)));
if (length < Number.MIN_VALUE){
return (0);
};
var invLength:Number = (1 / length);
x = (x * invLength);
y = (y * invLength);
return (length);
}
public function CrossVF(s:Number):void{
var tX:Number = x;
x = (s * y);
y = (-(s) * tX);
}
public function MaxV(b:b2Vec2):void{
x = ((x > b.x)) ? x : b.x;
y = ((y > b.y)) ? y : b.y;
}
public function SetV(v:b2Vec2):void{
x = v.x;
y = v.y;
}
public function Negative():b2Vec2{
return (new b2Vec2(-(x), -(y)));
}
public function CrossFV(s:Number):void{
var tX:Number = x;
x = (-(s) * y);
y = (s * tX);
}
public function Abs():void{
if (x < 0){
x = -(x);
};
if (y < 0){
y = -(y);
};
}
public function Subtract(v:b2Vec2):void{
x = (x - v.x);
y = (y - v.y);
}
public function Copy():b2Vec2{
return (new b2Vec2(x, y));
}
public function MulTM(A:b2Mat22):void{
var tX:Number = b2Math.b2Dot(this, A.col1);
y = b2Math.b2Dot(this, A.col2);
x = tX;
}
public function IsValid():Boolean{
return (((b2Math.b2IsValid(x)) && (b2Math.b2IsValid(y))));
}
public static function Make(x_:Number, y_:Number):b2Vec2{
return (new b2Vec2(x_, y_));
}
}
}//package Box2D.Common.Math
Section 34
//b2XForm (Box2D.Common.Math.b2XForm)
package Box2D.Common.Math {
public class b2XForm {
public var position:b2Vec2;
public var R:b2Mat22;
public function b2XForm(pos:b2Vec2=null, r:b2Mat22=null):void{
position = new b2Vec2();
R = new b2Mat22();
super();
if (pos){
position.SetV(pos);
R.SetM(r);
};
}
public function Initialize(pos:b2Vec2, r:b2Mat22):void{
position.SetV(pos);
R.SetM(r);
}
public function Set(x:b2XForm):void{
position.SetV(x.position);
R.SetM(x.R);
}
public function SetIdentity():void{
position.SetZero();
R.SetIdentity();
}
}
}//package Box2D.Common.Math
Section 35
//b2Color (Box2D.Common.b2Color)
package Box2D.Common {
import Box2D.Common.Math.*;
public class b2Color {
private var _r:uint;// = 0
private var _g:uint;// = 0
private var _b:uint;// = 0
public function b2Color(rr:Number, gg:Number, bb:Number){
super();
_r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1)));
_g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1)));
_b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1)));
}
public function Set(rr:Number, gg:Number, bb:Number):void{
_r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1)));
_g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1)));
_b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1)));
}
public function set b(bb:Number):void{
_b = uint((0xFF * b2Math.b2Clamp(bb, 0, 1)));
}
public function get color():uint{
return (((_r | (_g << 8)) | (_b << 16)));
}
public function set r(rr:Number):void{
_r = uint((0xFF * b2Math.b2Clamp(rr, 0, 1)));
}
public function set g(gg:Number):void{
_g = uint((0xFF * b2Math.b2Clamp(gg, 0, 1)));
}
}
}//package Box2D.Common
Section 36
//b2Settings (Box2D.Common.b2Settings)
package Box2D.Common {
import Box2D.Common.Math.*;
public class b2Settings {
public static const b2_angularSleepTolerance:Number = 0.0111111111111111;
public static const b2_linearSleepTolerance:Number = 0.01;
public static const b2_angularSlop:Number = 0.0349065850398866;
public static const b2_linearSlop:Number = 0.005;
public static const b2_pi:Number = 3.14159265358979;
public static const b2_maxProxies:int = 0x0200;
public static const b2_maxAngularVelocitySquared:Number = 62500;
public static const b2_maxPolygonVertices:int = 8;
public static const b2_velocityThreshold:Number = 1;
public static const b2_contactBaumgarte:Number = 0.2;
public static const b2_maxPairs:int = 4096;
public static const b2_maxTOIContactsPerIsland:int = 32;
public static const b2_timeToSleep:Number = 0.5;
public static const b2_maxManifoldPoints:int = 2;
public static const b2_maxAngularVelocity:Number = 250;
public static const b2_maxAngularCorrection:Number = 0.139626340159546;
public static const USHRT_MAX:int = 0xFFFF;
public static const b2_maxLinearVelocity:Number = 200;
public static const b2_maxLinearCorrection:Number = 0.2;
public static const b2_toiSlop:Number = 0.04;
public static const b2_maxLinearVelocitySquared:Number = 40000;
public function b2Settings(){
super();
}
public static function b2Assert(a:Boolean):void{
var nullVec:b2Vec2;
if (!a){
nullVec.x++;
};
}
}
}//package Box2D.Common
Section 37
//b2CircleContact (Box2D.Dynamics.Contacts.b2CircleContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2CircleContact extends b2Contact {
private var m_manifolds:Array;
public var m_manifold:b2Manifold;
private var m0:b2Manifold;
private static const s_evalCP:b2ContactPoint = new b2ContactPoint();
public function b2CircleContact(shape1:b2Shape, shape2:b2Shape){
m_manifolds = [new b2Manifold()];
m0 = new b2Manifold();
super(shape1, shape2);
m_manifold = m_manifolds[0];
m_manifold.pointCount = 0;
var point:b2ManifoldPoint = m_manifold.points[0];
point.normalImpulse = 0;
point.tangentImpulse = 0;
}
override public function Evaluate(listener:b2ContactListener):void{
var v1:b2Vec2;
var v2:b2Vec2;
var mp0:b2ManifoldPoint;
var mp:b2ManifoldPoint;
var b1:b2Body = m_shape1.m_body;
var b2:b2Body = m_shape2.m_body;
m0.Set(m_manifold);
b2Collision.b2CollideCircles(m_manifold, (m_shape1 as b2CircleShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf);
var cp:b2ContactPoint = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.friction = m_friction;
cp.restitution = m_restitution;
if (m_manifold.pointCount > 0){
m_manifoldCount = 1;
mp = m_manifold.points[0];
if (m0.pointCount == 0){
mp.normalImpulse = 0;
mp.tangentImpulse = 0;
if (listener){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = mp.id._key;
listener.Add(cp);
};
} else {
mp0 = m0.points[0];
mp.normalImpulse = mp0.normalImpulse;
mp.tangentImpulse = mp0.tangentImpulse;
if (listener){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = mp.id._key;
listener.Persist(cp);
};
};
} else {
m_manifoldCount = 0;
if ((((m0.pointCount > 0)) && (listener))){
mp0 = m0.points[0];
cp.position = b1.GetWorldPoint(mp0.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m0.normal);
cp.separation = mp0.separation;
cp.id.key = mp0.id._key;
listener.Remove(cp);
};
};
}
override public function GetManifolds():Array{
return (m_manifolds);
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2CircleContact(shape1, shape2));
}
}
}//package Box2D.Dynamics.Contacts
Section 38
//b2Contact (Box2D.Dynamics.Contacts.b2Contact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2Contact {
public var m_shape1:b2Shape;
public var m_shape2:b2Shape;
public var m_prev:b2Contact;
public var m_toi:Number;
public var m_next:b2Contact;
public var m_friction:Number;
public var m_manifoldCount:int;
public var m_node1:b2ContactEdge;
public var m_node2:b2ContactEdge;
public var m_restitution:Number;
public var m_flags:uint;
public static var e_toiFlag:uint = 8;
public static var e_nonSolidFlag:uint = 1;
public static var e_slowFlag:uint = 2;
public static var e_islandFlag:uint = 4;
public static var s_registers:Array;
public static var s_initialized:Boolean = false;
public function b2Contact(s1:b2Shape=null, s2:b2Shape=null){
m_node1 = new b2ContactEdge();
m_node2 = new b2ContactEdge();
super();
m_flags = 0;
if (((!(s1)) || (!(s2)))){
m_shape1 = null;
m_shape2 = null;
return;
};
if (((s1.IsSensor()) || (s2.IsSensor()))){
m_flags = (m_flags | e_nonSolidFlag);
};
m_shape1 = s1;
m_shape2 = s2;
m_manifoldCount = 0;
m_friction = Math.sqrt((m_shape1.m_friction * m_shape2.m_friction));
m_restitution = b2Math.b2Max(m_shape1.m_restitution, m_shape2.m_restitution);
m_prev = null;
m_next = null;
m_node1.contact = null;
m_node1.prev = null;
m_node1.next = null;
m_node1.other = null;
m_node2.contact = null;
m_node2.prev = null;
m_node2.next = null;
m_node2.other = null;
}
public function IsSolid():Boolean{
return (((m_flags & e_nonSolidFlag) == 0));
}
public function GetShape1():b2Shape{
return (m_shape1);
}
public function GetShape2():b2Shape{
return (m_shape2);
}
public function GetNext():b2Contact{
return (m_next);
}
public function GetManifoldCount():int{
return (m_manifoldCount);
}
public function GetManifolds():Array{
return (null);
}
public function Update(listener:b2ContactListener):void{
var oldCount:int = m_manifoldCount;
Evaluate(listener);
var newCount:int = m_manifoldCount;
var body1:b2Body = m_shape1.m_body;
var body2:b2Body = m_shape2.m_body;
if ((((newCount == 0)) && ((oldCount > 0)))){
body1.WakeUp();
body2.WakeUp();
};
if (((((((body1.IsStatic()) || (body1.IsBullet()))) || (body2.IsStatic()))) || (body2.IsBullet()))){
m_flags = (m_flags & ~(e_slowFlag));
} else {
m_flags = (m_flags | e_slowFlag);
};
}
public function Evaluate(listener:b2ContactListener):void{
}
public static function InitializeRegisters():void{
var j:int;
s_registers = new Array(b2Shape.e_shapeTypeCount);
var i:int;
while (i < b2Shape.e_shapeTypeCount) {
s_registers[i] = new Array(b2Shape.e_shapeTypeCount);
j = 0;
while (j < b2Shape.e_shapeTypeCount) {
s_registers[i][j] = new b2ContactRegister();
j++;
};
i++;
};
AddType(b2CircleContact.Create, b2CircleContact.Destroy, b2Shape.e_circleShape, b2Shape.e_circleShape);
AddType(b2PolyAndCircleContact.Create, b2PolyAndCircleContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_circleShape);
AddType(b2PolygonContact.Create, b2PolygonContact.Destroy, b2Shape.e_polygonShape, b2Shape.e_polygonShape);
}
public static function Destroy(contact:b2Contact, allocator):void{
if (contact.m_manifoldCount > 0){
contact.m_shape1.m_body.WakeUp();
contact.m_shape2.m_body.WakeUp();
};
var type1:int = contact.m_shape1.m_type;
var type2:int = contact.m_shape2.m_type;
var reg:b2ContactRegister = s_registers[type1][type2];
var destroyFcn:Function = reg.destroyFcn;
destroyFcn(contact, allocator);
}
public static function AddType(createFcn:Function, destroyFcn:Function, type1:int, type2:int):void{
s_registers[type1][type2].createFcn = createFcn;
s_registers[type1][type2].destroyFcn = destroyFcn;
s_registers[type1][type2].primary = true;
if (type1 != type2){
s_registers[type2][type1].createFcn = createFcn;
s_registers[type2][type1].destroyFcn = destroyFcn;
s_registers[type2][type1].primary = false;
};
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
var c:b2Contact;
var i:int;
var m:b2Manifold;
if (s_initialized == false){
InitializeRegisters();
s_initialized = true;
};
var type1:int = shape1.m_type;
var type2:int = shape2.m_type;
var reg:b2ContactRegister = s_registers[type1][type2];
var createFcn:Function = reg.createFcn;
if (createFcn != null){
if (reg.primary){
return (createFcn(shape1, shape2, allocator));
};
c = createFcn(shape2, shape1, allocator);
i = 0;
while (i < c.m_manifoldCount) {
m = c.GetManifolds()[i];
m.normal = m.normal.Negative();
i++;
};
return (c);
//unresolved jump
};
return (null);
}
}
}//package Box2D.Dynamics.Contacts
Section 39
//b2ContactConstraint (Box2D.Dynamics.Contacts.b2ContactConstraint)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2ContactConstraint {
public var points:Array;
public var normal:b2Vec2;
public var restitution:Number;
public var body1:b2Body;
public var manifold:b2Manifold;
public var body2:b2Body;
public var friction:Number;
public var pointCount:int;
public function b2ContactConstraint(){
normal = new b2Vec2();
super();
points = new Array(b2Settings.b2_maxManifoldPoints);
var i:int;
while (i < b2Settings.b2_maxManifoldPoints) {
points[i] = new b2ContactConstraintPoint();
i++;
};
}
}
}//package Box2D.Dynamics.Contacts
Section 40
//b2ContactConstraintPoint (Box2D.Dynamics.Contacts.b2ContactConstraintPoint)
package Box2D.Dynamics.Contacts {
import Box2D.Common.Math.*;
public class b2ContactConstraintPoint {
public var r2:b2Vec2;
public var separation:Number;
public var positionImpulse:Number;
public var normalImpulse:Number;
public var tangentMass:Number;
public var equalizedMass:Number;
public var tangentImpulse:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var normalMass:Number;
public var velocityBias:Number;
public var r1:b2Vec2;
public function b2ContactConstraintPoint(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
r1 = new b2Vec2();
r2 = new b2Vec2();
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 41
//b2ContactEdge (Box2D.Dynamics.Contacts.b2ContactEdge)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
public class b2ContactEdge {
public var other:b2Body;
public var prev:b2ContactEdge;
public var contact:b2Contact;
public var next:b2ContactEdge;
public function b2ContactEdge(){
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 42
//b2ContactRegister (Box2D.Dynamics.Contacts.b2ContactRegister)
package Box2D.Dynamics.Contacts {
public class b2ContactRegister {
public var primary:Boolean;
public var createFcn:Function;
public var destroyFcn:Function;
public function b2ContactRegister(){
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 43
//b2ContactResult (Box2D.Dynamics.Contacts.b2ContactResult)
package Box2D.Dynamics.Contacts {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
public class b2ContactResult {
public var position:b2Vec2;
public var shape1:b2Shape;
public var shape2:b2Shape;
public var normalImpulse:Number;
public var normal:b2Vec2;
public var tangentImpulse:Number;
public var id:b2ContactID;
public function b2ContactResult(){
position = new b2Vec2();
normal = new b2Vec2();
id = new b2ContactID();
super();
}
}
}//package Box2D.Dynamics.Contacts
Section 44
//b2ContactSolver (Box2D.Dynamics.Contacts.b2ContactSolver)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2ContactSolver {
public var m_constraintCount:int;
public var m_constraints:Array;
public var m_allocator;
public var m_step:b2TimeStep;
public function b2ContactSolver(step:b2TimeStep, contacts:Array, contactCount:int, allocator){
var contact:b2Contact;
var i:int;
var tVec:b2Vec2;
var tMat:b2Mat22;
var b1:b2Body;
var b2:b2Body;
var manifoldCount:int;
var manifolds:Array;
var friction:Number;
var restitution:Number;
var v1X:Number;
var v1Y:Number;
var v2X:Number;
var v2Y:Number;
var w1:Number;
var w2:Number;
var j:int;
var manifold:b2Manifold;
var normalX:Number;
var normalY:Number;
var c:b2ContactConstraint;
var k:uint;
var cp:b2ManifoldPoint;
var ccp:b2ContactConstraintPoint;
var tX:Number;
var tY:Number;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var r1Sqr:Number;
var r2Sqr:Number;
var rn1:Number;
var rn2:Number;
var kNormal:Number;
var kEqualized:Number;
var tangentX:Number;
var tangentY:Number;
var rt1:Number;
var rt2:Number;
var kTangent:Number;
var vRel:Number;
m_step = new b2TimeStep();
m_constraints = new Array();
super();
m_step.dt = step.dt;
m_step.inv_dt = step.inv_dt;
m_step.maxIterations = step.maxIterations;
m_allocator = allocator;
m_constraintCount = 0;
i = 0;
while (i < contactCount) {
contact = contacts[i];
m_constraintCount = (m_constraintCount + contact.m_manifoldCount);
i++;
};
i = 0;
while (i < m_constraintCount) {
m_constraints[i] = new b2ContactConstraint();
i++;
};
var count:int;
i = 0;
while (i < contactCount) {
contact = contacts[i];
b1 = contact.m_shape1.m_body;
b2 = contact.m_shape2.m_body;
manifoldCount = contact.m_manifoldCount;
manifolds = contact.GetManifolds();
friction = contact.m_friction;
restitution = contact.m_restitution;
v1X = b1.m_linearVelocity.x;
v1Y = b1.m_linearVelocity.y;
v2X = b2.m_linearVelocity.x;
v2Y = b2.m_linearVelocity.y;
w1 = b1.m_angularVelocity;
w2 = b2.m_angularVelocity;
j = 0;
while (j < manifoldCount) {
manifold = manifolds[j];
normalX = manifold.normal.x;
normalY = manifold.normal.y;
c = m_constraints[count];
c.body1 = b1;
c.body2 = b2;
c.manifold = manifold;
c.normal.x = normalX;
c.normal.y = normalY;
c.pointCount = manifold.pointCount;
c.friction = friction;
c.restitution = restitution;
k = 0;
while (k < c.pointCount) {
cp = manifold.points[k];
ccp = c.points[k];
ccp.normalImpulse = cp.normalImpulse;
ccp.tangentImpulse = cp.tangentImpulse;
ccp.separation = cp.separation;
ccp.positionImpulse = 0;
ccp.localAnchor1.SetV(cp.localPoint1);
ccp.localAnchor2.SetV(cp.localPoint2);
tMat = b1.m_xf.R;
r1X = (cp.localPoint1.x - b1.m_sweep.localCenter.x);
r1Y = (cp.localPoint1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
ccp.r1.Set(r1X, r1Y);
tMat = b2.m_xf.R;
r2X = (cp.localPoint2.x - b2.m_sweep.localCenter.x);
r2Y = (cp.localPoint2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
ccp.r2.Set(r2X, r2Y);
r1Sqr = ((r1X * r1X) + (r1Y * r1Y));
r2Sqr = ((r2X * r2X) + (r2Y * r2Y));
rn1 = ((r1X * normalX) + (r1Y * normalY));
rn2 = ((r2X * normalX) + (r2Y * normalY));
kNormal = (b1.m_invMass + b2.m_invMass);
kNormal = (kNormal + ((b1.m_invI * (r1Sqr - (rn1 * rn1))) + (b2.m_invI * (r2Sqr - (rn2 * rn2)))));
ccp.normalMass = (1 / kNormal);
kEqualized = ((b1.m_mass * b1.m_invMass) + (b2.m_mass * b2.m_invMass));
kEqualized = (kEqualized + (((b1.m_mass * b1.m_invI) * (r1Sqr - (rn1 * rn1))) + ((b2.m_mass * b2.m_invI) * (r2Sqr - (rn2 * rn2)))));
ccp.equalizedMass = (1 / kEqualized);
tangentX = normalY;
tangentY = -(normalX);
rt1 = ((r1X * tangentX) + (r1Y * tangentY));
rt2 = ((r2X * tangentX) + (r2Y * tangentY));
kTangent = (b1.m_invMass + b2.m_invMass);
kTangent = (kTangent + ((b1.m_invI * (r1Sqr - (rt1 * rt1))) + (b2.m_invI * (r2Sqr - (rt2 * rt2)))));
ccp.tangentMass = (1 / kTangent);
ccp.velocityBias = 0;
if (ccp.separation > 0){
ccp.velocityBias = (-60 * ccp.separation);
};
tX = (((v2X + (-(w2) * r2Y)) - v1X) - (-(w1) * r1Y));
tY = (((v2Y + (w2 * r2X)) - v1Y) - (w1 * r1X));
vRel = ((c.normal.x * tX) + (c.normal.y * tY));
if (vRel < -(b2Settings.b2_velocityThreshold)){
ccp.velocityBias = (ccp.velocityBias + (-(c.restitution) * vRel));
};
k++;
};
count++;
j++;
};
i++;
};
}
public function InitVelocityConstraints(step:b2TimeStep):void{
var tVec:b2Vec2;
var tVec2:b2Vec2;
var tMat:b2Mat22;
var c:b2ContactConstraint;
var b1:b2Body;
var b2:b2Body;
var invMass1:Number;
var invI1:Number;
var invMass2:Number;
var invI2:Number;
var normalX:Number;
var normalY:Number;
var tangentX:Number;
var tangentY:Number;
var tX:Number;
var j:int;
var tCount:int;
var ccp:b2ContactConstraintPoint;
var PX:Number;
var PY:Number;
var ccp2:b2ContactConstraintPoint;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
b1 = c.body1;
b2 = c.body2;
invMass1 = b1.m_invMass;
invI1 = b1.m_invI;
invMass2 = b2.m_invMass;
invI2 = b2.m_invI;
normalX = c.normal.x;
normalY = c.normal.y;
tangentX = normalY;
tangentY = -(normalX);
if (step.warmStarting){
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp = c.points[j];
ccp.normalImpulse = (ccp.normalImpulse * step.dtRatio);
ccp.tangentImpulse = (ccp.tangentImpulse * step.dtRatio);
PX = ((ccp.normalImpulse * normalX) + (ccp.tangentImpulse * tangentX));
PY = ((ccp.normalImpulse * normalY) + (ccp.tangentImpulse * tangentY));
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * ((ccp.r1.x * PY) - (ccp.r1.y * PX))));
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (invMass1 * PX));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (invMass1 * PY));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * ((ccp.r2.x * PY) - (ccp.r2.y * PX))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (invMass2 * PX));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (invMass2 * PY));
j++;
};
} else {
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp2 = c.points[j];
ccp2.normalImpulse = 0;
ccp2.tangentImpulse = 0;
j++;
};
};
i++;
};
}
public function SolvePositionConstraints(baumgarte:Number):Boolean{
var tMat:b2Mat22;
var tVec:b2Vec2;
var c:b2ContactConstraint;
var b1:b2Body;
var b2:b2Body;
var b1_sweep_c:b2Vec2;
var b1_sweep_a:Number;
var b2_sweep_c:b2Vec2;
var b2_sweep_a:Number;
var invMass1:Number;
var invI1:Number;
var invMass2:Number;
var invI2:Number;
var normalX:Number;
var normalY:Number;
var tCount:int;
var j:int;
var ccp:b2ContactConstraintPoint;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var tX:Number;
var p1X:Number;
var p1Y:Number;
var p2X:Number;
var p2Y:Number;
var dpX:Number;
var dpY:Number;
var separation:Number;
var C:Number;
var dImpulse:Number;
var impulse0:Number;
var impulseX:Number;
var impulseY:Number;
var minSeparation:Number = 0;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
b1 = c.body1;
b2 = c.body2;
b1_sweep_c = b1.m_sweep.c;
b1_sweep_a = b1.m_sweep.a;
b2_sweep_c = b2.m_sweep.c;
b2_sweep_a = b2.m_sweep.a;
invMass1 = (b1.m_mass * b1.m_invMass);
invI1 = (b1.m_mass * b1.m_invI);
invMass2 = (b2.m_mass * b2.m_invMass);
invI2 = (b2.m_mass * b2.m_invI);
normalX = c.normal.x;
normalY = c.normal.y;
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp = c.points[j];
tMat = b1.m_xf.R;
tVec = b1.m_sweep.localCenter;
r1X = (ccp.localAnchor1.x - tVec.x);
r1Y = (ccp.localAnchor1.y - tVec.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
tVec = b2.m_sweep.localCenter;
r2X = (ccp.localAnchor2.x - tVec.x);
r2Y = (ccp.localAnchor2.y - tVec.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
p1X = (b1_sweep_c.x + r1X);
p1Y = (b1_sweep_c.y + r1Y);
p2X = (b2_sweep_c.x + r2X);
p2Y = (b2_sweep_c.y + r2Y);
dpX = (p2X - p1X);
dpY = (p2Y - p1Y);
separation = (((dpX * normalX) + (dpY * normalY)) + ccp.separation);
minSeparation = b2Math.b2Min(minSeparation, separation);
C = (baumgarte * b2Math.b2Clamp((separation + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0));
dImpulse = (-(ccp.equalizedMass) * C);
impulse0 = ccp.positionImpulse;
ccp.positionImpulse = b2Math.b2Max((impulse0 + dImpulse), 0);
dImpulse = (ccp.positionImpulse - impulse0);
impulseX = (dImpulse * normalX);
impulseY = (dImpulse * normalY);
b1_sweep_c.x = (b1_sweep_c.x - (invMass1 * impulseX));
b1_sweep_c.y = (b1_sweep_c.y - (invMass1 * impulseY));
b1_sweep_a = (b1_sweep_a - (invI1 * ((r1X * impulseY) - (r1Y * impulseX))));
b1.m_sweep.a = b1_sweep_a;
b1.SynchronizeTransform();
b2_sweep_c.x = (b2_sweep_c.x + (invMass2 * impulseX));
b2_sweep_c.y = (b2_sweep_c.y + (invMass2 * impulseY));
b2_sweep_a = (b2_sweep_a + (invI2 * ((r2X * impulseY) - (r2Y * impulseX))));
b2.m_sweep.a = b2_sweep_a;
b2.SynchronizeTransform();
j++;
};
i++;
};
return ((minSeparation >= (-1.5 * b2Settings.b2_linearSlop)));
}
public function SolveVelocityConstraints():void{
var j:int;
var ccp:b2ContactConstraintPoint;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var dvX:Number;
var dvY:Number;
var vn:Number;
var vt:Number;
var lambda_n:Number;
var lambda_t:Number;
var newImpulse_n:Number;
var newImpulse_t:Number;
var PX:Number;
var PY:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var c:b2ContactConstraint;
var b1:b2Body;
var b2:b2Body;
var w1:Number;
var w2:Number;
var v1:b2Vec2;
var v2:b2Vec2;
var invMass1:Number;
var invI1:Number;
var invMass2:Number;
var invI2:Number;
var normalX:Number;
var normalY:Number;
var tangentX:Number;
var tangentY:Number;
var friction:Number;
var tX:Number;
var tCount:int;
var maxFriction:Number;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
b1 = c.body1;
b2 = c.body2;
w1 = b1.m_angularVelocity;
w2 = b2.m_angularVelocity;
v1 = b1.m_linearVelocity;
v2 = b2.m_linearVelocity;
invMass1 = b1.m_invMass;
invI1 = b1.m_invI;
invMass2 = b2.m_invMass;
invI2 = b2.m_invI;
normalX = c.normal.x;
normalY = c.normal.y;
tangentX = normalY;
tangentY = -(normalX);
friction = c.friction;
tCount = c.pointCount;
j = 0;
while (j < tCount) {
ccp = c.points[j];
dvX = (((v2.x + (-(w2) * ccp.r2.y)) - v1.x) - (-(w1) * ccp.r1.y));
dvY = (((v2.y + (w2 * ccp.r2.x)) - v1.y) - (w1 * ccp.r1.x));
vn = ((dvX * normalX) + (dvY * normalY));
lambda_n = (-(ccp.normalMass) * (vn - ccp.velocityBias));
vt = ((dvX * tangentX) + (dvY * tangentY));
lambda_t = (ccp.tangentMass * -(vt));
newImpulse_n = b2Math.b2Max((ccp.normalImpulse + lambda_n), 0);
lambda_n = (newImpulse_n - ccp.normalImpulse);
maxFriction = (friction * ccp.normalImpulse);
newImpulse_t = b2Math.b2Clamp((ccp.tangentImpulse + lambda_t), -(maxFriction), maxFriction);
lambda_t = (newImpulse_t - ccp.tangentImpulse);
PX = ((lambda_n * normalX) + (lambda_t * tangentX));
PY = ((lambda_n * normalY) + (lambda_t * tangentY));
v1.x = (v1.x - (invMass1 * PX));
v1.y = (v1.y - (invMass1 * PY));
w1 = (w1 - (invI1 * ((ccp.r1.x * PY) - (ccp.r1.y * PX))));
v2.x = (v2.x + (invMass2 * PX));
v2.y = (v2.y + (invMass2 * PY));
w2 = (w2 + (invI2 * ((ccp.r2.x * PY) - (ccp.r2.y * PX))));
ccp.normalImpulse = newImpulse_n;
ccp.tangentImpulse = newImpulse_t;
j++;
};
b1.m_angularVelocity = w1;
b2.m_angularVelocity = w2;
i++;
};
}
public function FinalizeVelocityConstraints():void{
var c:b2ContactConstraint;
var m:b2Manifold;
var j:int;
var point1:b2ManifoldPoint;
var point2:b2ContactConstraintPoint;
var i:int;
while (i < m_constraintCount) {
c = m_constraints[i];
m = c.manifold;
j = 0;
while (j < c.pointCount) {
point1 = m.points[j];
point2 = c.points[j];
point1.normalImpulse = point2.normalImpulse;
point1.tangentImpulse = point2.tangentImpulse;
j++;
};
i++;
};
}
}
}//package Box2D.Dynamics.Contacts
Section 45
//b2NullContact (Box2D.Dynamics.Contacts.b2NullContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
public class b2NullContact extends b2Contact {
public function b2NullContact(){
super();
}
override public function Evaluate(l:b2ContactListener):void{
}
override public function GetManifolds():Array{
return (null);
}
}
}//package Box2D.Dynamics.Contacts
Section 46
//b2PolyAndCircleContact (Box2D.Dynamics.Contacts.b2PolyAndCircleContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2PolyAndCircleContact extends b2Contact {
private var m_manifolds:Array;
public var m_manifold:b2Manifold;
private var m0:b2Manifold;
private static const s_evalCP:b2ContactPoint = new b2ContactPoint();
public function b2PolyAndCircleContact(shape1:b2Shape, shape2:b2Shape){
m_manifolds = [new b2Manifold()];
m0 = new b2Manifold();
super(shape1, shape2);
m_manifold = m_manifolds[0];
b2Settings.b2Assert((m_shape1.m_type == b2Shape.e_polygonShape));
b2Settings.b2Assert((m_shape2.m_type == b2Shape.e_circleShape));
m_manifold.pointCount = 0;
var point:b2ManifoldPoint = m_manifold.points[0];
point.normalImpulse = 0;
point.tangentImpulse = 0;
}
override public function Evaluate(listener:b2ContactListener):void{
var i:int;
var v1:b2Vec2;
var v2:b2Vec2;
var mp0:b2ManifoldPoint;
var mp:b2ManifoldPoint;
var found:Boolean;
var idKey:uint;
var j:int;
var b1:b2Body = m_shape1.m_body;
var b2:b2Body = m_shape2.m_body;
m0.Set(m_manifold);
b2Collision.b2CollidePolygonAndCircle(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2CircleShape), b2.m_xf);
var persisted:Array = [false, false];
var cp:b2ContactPoint = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.friction = m_friction;
cp.restitution = m_restitution;
if (m_manifold.pointCount > 0){
i = 0;
while (i < m_manifold.pointCount) {
mp = m_manifold.points[i];
mp.normalImpulse = 0;
mp.tangentImpulse = 0;
found = false;
idKey = mp.id._key;
j = 0;
while (j < m0.pointCount) {
if (persisted[j] == true){
} else {
mp0 = m0.points[j];
if (mp0.id._key == idKey){
persisted[j] = true;
mp.normalImpulse = mp0.normalImpulse;
mp.tangentImpulse = mp0.tangentImpulse;
found = true;
if (listener != null){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = idKey;
listener.Persist(cp);
};
break;
};
};
j++;
};
if ((((found == false)) && (!((listener == null))))){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = idKey;
listener.Add(cp);
};
i++;
};
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
if (listener == null){
return;
};
i = 0;
while (i < m0.pointCount) {
if (persisted[i]){
} else {
mp0 = m0.points[i];
cp.position = b1.GetWorldPoint(mp0.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m0.normal);
cp.separation = mp0.separation;
cp.id.key = mp0.id._key;
listener.Remove(cp);
};
i++;
};
}
override public function GetManifolds():Array{
return (m_manifolds);
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2PolyAndCircleContact(shape1, shape2));
}
}
}//package Box2D.Dynamics.Contacts
Section 47
//b2PolygonContact (Box2D.Dynamics.Contacts.b2PolygonContact)
package Box2D.Dynamics.Contacts {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Common.*;
public class b2PolygonContact extends b2Contact {
private var m_manifolds:Array;
private var m0:b2Manifold;
public var m_manifold:b2Manifold;
private static const s_evalCP:b2ContactPoint = new b2ContactPoint();
public function b2PolygonContact(shape1:b2Shape, shape2:b2Shape):void{
m0 = new b2Manifold();
m_manifolds = [new b2Manifold()];
super(shape1, shape2);
m_manifold = m_manifolds[0];
m_manifold.pointCount = 0;
}
override public function Evaluate(listener:b2ContactListener):void{
var v1:b2Vec2;
var v2:b2Vec2;
var mp0:b2ManifoldPoint;
var cp:b2ContactPoint;
var i:int;
var mp:b2ManifoldPoint;
var found:Boolean;
var idKey:uint;
var j:int;
var b1:b2Body = m_shape1.m_body;
var b2:b2Body = m_shape2.m_body;
m0.Set(m_manifold);
b2Collision.b2CollidePolygons(m_manifold, (m_shape1 as b2PolygonShape), b1.m_xf, (m_shape2 as b2PolygonShape), b2.m_xf);
var persisted:Array = [false, false];
cp = s_evalCP;
cp.shape1 = m_shape1;
cp.shape2 = m_shape2;
cp.friction = m_friction;
cp.restitution = m_restitution;
if (m_manifold.pointCount > 0){
i = 0;
while (i < m_manifold.pointCount) {
mp = m_manifold.points[i];
mp.normalImpulse = 0;
mp.tangentImpulse = 0;
found = false;
idKey = mp.id._key;
j = 0;
while (j < m0.pointCount) {
if (persisted[j] == true){
} else {
mp0 = m0.points[j];
if (mp0.id._key == idKey){
persisted[j] = true;
mp.normalImpulse = mp0.normalImpulse;
mp.tangentImpulse = mp0.tangentImpulse;
found = true;
if (listener != null){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = idKey;
listener.Persist(cp);
};
break;
};
};
j++;
};
if ((((found == false)) && (!((listener == null))))){
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m_manifold.normal);
cp.separation = mp.separation;
cp.id.key = idKey;
listener.Add(cp);
};
i++;
};
m_manifoldCount = 1;
} else {
m_manifoldCount = 0;
};
if (listener == null){
return;
};
i = 0;
while (i < m0.pointCount) {
if (persisted[i]){
} else {
mp0 = m0.points[i];
cp.position = b1.GetWorldPoint(mp0.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp0.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp0.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.normal.SetV(m0.normal);
cp.separation = mp0.separation;
cp.id.key = mp0.id._key;
listener.Remove(cp);
};
i++;
};
}
override public function GetManifolds():Array{
return (m_manifolds);
}
public static function Destroy(contact:b2Contact, allocator):void{
}
public static function Create(shape1:b2Shape, shape2:b2Shape, allocator):b2Contact{
return (new b2PolygonContact(shape1, shape2));
}
}
}//package Box2D.Dynamics.Contacts
Section 48
//b2DistanceJoint (Box2D.Dynamics.Joints.b2DistanceJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2DistanceJoint extends b2Joint {
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_bias:Number;
public var m_gamma:Number;
public var m_u:b2Vec2;
public var m_mass:Number;
public var m_impulse:Number;
public var m_dampingRatio:Number;
public var m_frequencyHz:Number;
public var m_length:Number;
public function b2DistanceJoint(def:b2DistanceJointDef){
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_u = new b2Vec2();
super(def);
m_localAnchor1.SetV(def.localAnchor1);
m_localAnchor2.SetV(def.localAnchor2);
m_length = def.length;
m_frequencyHz = def.frequencyHz;
m_dampingRatio = def.dampingRatio;
m_impulse = 0;
m_gamma = 0;
m_bias = 0;
m_inv_dt = 0;
}
override public function GetAnchor1():b2Vec2{
return (m_body1.GetWorldPoint(m_localAnchor1));
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor2));
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var b1:b2Body;
var b2:b2Body;
var r1X:Number;
var r2X:Number;
var C:Number;
var omega:Number;
var d:Number;
var k:Number;
var PX:Number;
var PY:Number;
m_inv_dt = step.inv_dt;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_xf.R;
r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
m_u.x = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X);
m_u.y = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y);
var length:Number = Math.sqrt(((m_u.x * m_u.x) + (m_u.y * m_u.y)));
if (length > b2Settings.b2_linearSlop){
m_u.Multiply((1 / length));
} else {
m_u.SetZero();
};
var cr1u:Number = ((r1X * m_u.y) - (r1Y * m_u.x));
var cr2u:Number = ((r2X * m_u.y) - (r2Y * m_u.x));
var invMass:Number = (((b1.m_invMass + ((b1.m_invI * cr1u) * cr1u)) + b2.m_invMass) + ((b2.m_invI * cr2u) * cr2u));
m_mass = (1 / invMass);
if (m_frequencyHz > 0){
C = (length - m_length);
omega = ((2 * Math.PI) * m_frequencyHz);
d = (((2 * m_mass) * m_dampingRatio) * omega);
k = ((m_mass * omega) * omega);
m_gamma = (1 / (step.dt * (d + (step.dt * k))));
m_bias = (((C * step.dt) * k) * m_gamma);
m_mass = (1 / (invMass + m_gamma));
};
if (step.warmStarting){
m_impulse = (m_impulse * step.dtRatio);
PX = (m_impulse * m_u.x);
PY = (m_impulse * m_u.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * PX));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * PY));
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * PY) - (r1Y * PX))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * PX));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * PY));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * PY) - (r2Y * PX))));
} else {
m_impulse = 0;
};
}
override public function GetReactionTorque():Number{
return (0);
}
override public function GetReactionForce():b2Vec2{
var F:b2Vec2 = new b2Vec2();
F.SetV(m_u);
F.Multiply((m_inv_dt * m_impulse));
return (F);
}
override public function SolvePositionConstraints():Boolean{
var tMat:b2Mat22;
if (m_frequencyHz > 0){
return (true);
};
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var dX:Number = (((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x) - r1X);
var dY:Number = (((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y) - r1Y);
var length:Number = Math.sqrt(((dX * dX) + (dY * dY)));
dX = (dX / length);
dY = (dY / length);
var C:Number = (length - m_length);
C = b2Math.b2Clamp(C, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
var impulse:Number = (-(m_mass) * C);
m_u.Set(dX, dY);
var PX:Number = (impulse * m_u.x);
var PY:Number = (impulse * m_u.y);
b1.m_sweep.c.x = (b1.m_sweep.c.x - (b1.m_invMass * PX));
b1.m_sweep.c.y = (b1.m_sweep.c.y - (b1.m_invMass * PY));
b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * ((r1X * PY) - (r1Y * PX))));
b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * PX));
b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * PY));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * PY) - (r2Y * PX))));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
return ((b2Math.b2Abs(C) < b2Settings.b2_linearSlop));
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var v1X:Number = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y));
var v1Y:Number = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X));
var v2X:Number = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y));
var v2Y:Number = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X));
var Cdot:Number = ((m_u.x * (v2X - v1X)) + (m_u.y * (v2Y - v1Y)));
var impulse:Number = (-(m_mass) * ((Cdot + m_bias) + (m_gamma * m_impulse)));
m_impulse = (m_impulse + impulse);
var PX:Number = (impulse * m_u.x);
var PY:Number = (impulse * m_u.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * PX));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * PY));
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * PY) - (r1Y * PX))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * PX));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * PY));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * PY) - (r2Y * PX))));
}
}
}//package Box2D.Dynamics.Joints
Section 49
//b2DistanceJointDef (Box2D.Dynamics.Joints.b2DistanceJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2DistanceJointDef extends b2JointDef {
public var localAnchor1:b2Vec2;
public var length:Number;
public var dampingRatio:Number;
public var localAnchor2:b2Vec2;
public var frequencyHz:Number;
public function b2DistanceJointDef(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
type = b2Joint.e_distanceJoint;
length = 1;
frequencyHz = 0;
dampingRatio = 0;
}
public function Initialize(b1:b2Body, b2:b2Body, anchor1:b2Vec2, anchor2:b2Vec2):void{
body1 = b1;
body2 = b2;
localAnchor1.SetV(body1.GetLocalPoint(anchor1));
localAnchor2.SetV(body2.GetLocalPoint(anchor2));
var dX:Number = (anchor2.x - anchor1.x);
var dY:Number = (anchor2.y - anchor1.y);
length = Math.sqrt(((dX * dX) + (dY * dY)));
frequencyHz = 0;
dampingRatio = 0;
}
}
}//package Box2D.Dynamics.Joints
Section 50
//b2GearJoint (Box2D.Dynamics.Joints.b2GearJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2GearJoint extends b2Joint {
public var m_ground2:b2Body;
public var m_groundAnchor1:b2Vec2;
public var m_groundAnchor2:b2Vec2;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_ratio:Number;
public var m_revolute2:b2RevoluteJoint;
public var m_force:Number;
public var m_mass:Number;
public var m_prismatic2:b2PrismaticJoint;
public var m_ground1:b2Body;
public var m_revolute1:b2RevoluteJoint;
public var m_prismatic1:b2PrismaticJoint;
public var m_constant:Number;
public var m_J:b2Jacobian;
public function b2GearJoint(def:b2GearJointDef){
var coordinate1:Number;
var coordinate2:Number;
m_groundAnchor1 = new b2Vec2();
m_groundAnchor2 = new b2Vec2();
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_J = new b2Jacobian();
super(def);
var type1:int = def.joint1.m_type;
var type2:int = def.joint2.m_type;
m_revolute1 = null;
m_prismatic1 = null;
m_revolute2 = null;
m_prismatic2 = null;
m_ground1 = def.joint1.m_body1;
m_body1 = def.joint1.m_body2;
if (type1 == b2Joint.e_revoluteJoint){
m_revolute1 = (def.joint1 as b2RevoluteJoint);
m_groundAnchor1.SetV(m_revolute1.m_localAnchor1);
m_localAnchor1.SetV(m_revolute1.m_localAnchor2);
coordinate1 = m_revolute1.GetJointAngle();
} else {
m_prismatic1 = (def.joint1 as b2PrismaticJoint);
m_groundAnchor1.SetV(m_prismatic1.m_localAnchor1);
m_localAnchor1.SetV(m_prismatic1.m_localAnchor2);
coordinate1 = m_prismatic1.GetJointTranslation();
};
m_ground2 = def.joint2.m_body1;
m_body2 = def.joint2.m_body2;
if (type2 == b2Joint.e_revoluteJoint){
m_revolute2 = (def.joint2 as b2RevoluteJoint);
m_groundAnchor2.SetV(m_revolute2.m_localAnchor1);
m_localAnchor2.SetV(m_revolute2.m_localAnchor2);
coordinate2 = m_revolute2.GetJointAngle();
} else {
m_prismatic2 = (def.joint2 as b2PrismaticJoint);
m_groundAnchor2.SetV(m_prismatic2.m_localAnchor1);
m_localAnchor2.SetV(m_prismatic2.m_localAnchor2);
coordinate2 = m_prismatic2.GetJointTranslation();
};
m_ratio = def.ratio;
m_constant = (coordinate1 + (m_ratio * coordinate2));
m_force = 0;
}
override public function GetAnchor1():b2Vec2{
return (m_body1.GetWorldPoint(m_localAnchor1));
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor2));
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var ugX:Number;
var ugY:Number;
var rX:Number;
var rY:Number;
var tMat:b2Mat22;
var tVec:b2Vec2;
var crug:Number;
var tX:Number;
var P:Number;
var g1:b2Body = m_ground1;
var g2:b2Body = m_ground2;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var K:Number = 0;
m_J.SetZero();
if (m_revolute1){
m_J.angular1 = -1;
K = (K + b1.m_invI);
} else {
tMat = g1.m_xf.R;
tVec = m_prismatic1.m_localXAxis1;
ugX = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
ugY = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = b1.m_xf.R;
rX = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
rY = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
crug = ((rX * ugY) - (rY * ugX));
m_J.linear1.Set(-(ugX), -(ugY));
m_J.angular1 = -(crug);
K = (K + (b1.m_invMass + ((b1.m_invI * crug) * crug)));
};
if (m_revolute2){
m_J.angular2 = -(m_ratio);
K = (K + ((m_ratio * m_ratio) * b2.m_invI));
} else {
tMat = g2.m_xf.R;
tVec = m_prismatic2.m_localXAxis1;
ugX = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
ugY = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
tMat = b2.m_xf.R;
rX = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
rY = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
crug = ((rX * ugY) - (rY * ugX));
m_J.linear2.Set((-(m_ratio) * ugX), (-(m_ratio) * ugY));
m_J.angular2 = (-(m_ratio) * crug);
K = (K + ((m_ratio * m_ratio) * (b2.m_invMass + ((b2.m_invI * crug) * crug))));
};
m_mass = (1 / K);
if (step.warmStarting){
P = (step.dt * m_force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * P) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * P) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * P) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * P) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * P) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * P) * m_J.angular2));
} else {
m_force = 0;
};
}
override public function GetReactionTorque():Number{
var tMat:b2Mat22 = m_body2.m_xf.R;
var rX:Number = (m_localAnchor1.x - m_body2.m_sweep.localCenter.x);
var rY:Number = (m_localAnchor1.y - m_body2.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
tX = ((m_force * m_J.angular2) - ((rX * (m_force * m_J.linear2.y)) - (rY * (m_force * m_J.linear2.x))));
return (tX);
}
override public function GetReactionForce():b2Vec2{
var F:b2Vec2 = new b2Vec2((m_force * m_J.linear2.x), (m_force * m_J.linear2.y));
return (F);
}
override public function SolvePositionConstraints():Boolean{
var coordinate1:Number;
var coordinate2:Number;
var linearError:Number = 0;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
if (m_revolute1){
coordinate1 = m_revolute1.GetJointAngle();
} else {
coordinate1 = m_prismatic1.GetJointTranslation();
};
if (m_revolute2){
coordinate2 = m_revolute2.GetJointAngle();
} else {
coordinate2 = m_prismatic2.GetJointTranslation();
};
var C:Number = (m_constant - (coordinate1 + (m_ratio * coordinate2)));
var impulse:Number = (-(m_mass) * C);
b1.m_sweep.c.x = (b1.m_sweep.c.x + ((b1.m_invMass * impulse) * m_J.linear1.x));
b1.m_sweep.c.y = (b1.m_sweep.c.y + ((b1.m_invMass * impulse) * m_J.linear1.y));
b1.m_sweep.a = (b1.m_sweep.a + ((b1.m_invI * impulse) * m_J.angular1));
b2.m_sweep.c.x = (b2.m_sweep.c.x + ((b2.m_invMass * impulse) * m_J.linear2.x));
b2.m_sweep.c.y = (b2.m_sweep.c.y + ((b2.m_invMass * impulse) * m_J.linear2.y));
b2.m_sweep.a = (b2.m_sweep.a + ((b2.m_invI * impulse) * m_J.angular2));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
return ((linearError < b2Settings.b2_linearSlop));
}
public function GetRatio():Number{
return (m_ratio);
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var Cdot:Number = m_J.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
var force:Number = ((-(step.inv_dt) * m_mass) * Cdot);
m_force = (m_force + force);
var P:Number = (step.dt * force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((b1.m_invMass * P) * m_J.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((b1.m_invMass * P) * m_J.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((b1.m_invI * P) * m_J.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((b2.m_invMass * P) * m_J.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((b2.m_invMass * P) * m_J.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * P) * m_J.angular2));
}
}
}//package Box2D.Dynamics.Joints
Section 51
//b2GearJointDef (Box2D.Dynamics.Joints.b2GearJointDef)
package Box2D.Dynamics.Joints {
public class b2GearJointDef extends b2JointDef {
public var joint1:b2Joint;
public var joint2:b2Joint;
public var ratio:Number;
public function b2GearJointDef(){
super();
type = b2Joint.e_gearJoint;
joint1 = null;
joint2 = null;
ratio = 1;
}
}
}//package Box2D.Dynamics.Joints
Section 52
//b2Jacobian (Box2D.Dynamics.Joints.b2Jacobian)
package Box2D.Dynamics.Joints {
import Box2D.Common.Math.*;
public class b2Jacobian {
public var linear1:b2Vec2;
public var linear2:b2Vec2;
public var angular1:Number;
public var angular2:Number;
public function b2Jacobian(){
linear1 = new b2Vec2();
linear2 = new b2Vec2();
super();
}
public function Set(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number):void{
linear1.SetV(x1);
angular1 = a1;
linear2.SetV(x2);
angular2 = a2;
}
public function SetZero():void{
linear1.SetZero();
angular1 = 0;
linear2.SetZero();
angular2 = 0;
}
public function Compute(x1:b2Vec2, a1:Number, x2:b2Vec2, a2:Number):Number{
return ((((((linear1.x * x1.x) + (linear1.y * x1.y)) + (angular1 * a1)) + ((linear2.x * x2.x) + (linear2.y * x2.y))) + (angular2 * a2)));
}
}
}//package Box2D.Dynamics.Joints
Section 53
//b2Joint (Box2D.Dynamics.Joints.b2Joint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2Joint {
public var m_islandFlag:Boolean;
public var m_body1:b2Body;
public var m_prev:b2Joint;
public var m_next:b2Joint;
public var m_type:int;
public var m_collideConnected:Boolean;
public var m_node1:b2JointEdge;
public var m_node2:b2JointEdge;
public var m_inv_dt:Number;
public var m_userData;
public var m_body2:b2Body;
public static const e_unknownJoint:int = 0;
public static const e_inactiveLimit:int = 0;
public static const e_atUpperLimit:int = 2;
public static const e_atLowerLimit:int = 1;
public static const e_gearJoint:int = 6;
public static const e_revoluteJoint:int = 1;
public static const e_equalLimits:int = 3;
public static const e_distanceJoint:int = 3;
public static const e_pulleyJoint:int = 4;
public static const e_prismaticJoint:int = 2;
public static const e_mouseJoint:int = 5;
public function b2Joint(def:b2JointDef){
m_node1 = new b2JointEdge();
m_node2 = new b2JointEdge();
super();
m_type = def.type;
m_prev = null;
m_next = null;
m_body1 = def.body1;
m_body2 = def.body2;
m_collideConnected = def.collideConnected;
m_islandFlag = false;
m_userData = def.userData;
}
public function GetBody2():b2Body{
return (m_body2);
}
public function GetAnchor1():b2Vec2{
return (null);
}
public function GetAnchor2():b2Vec2{
return (null);
}
public function GetNext():b2Joint{
return (m_next);
}
public function GetType():int{
return (m_type);
}
public function InitVelocityConstraints(step:b2TimeStep):void{
}
public function GetReactionTorque():Number{
return (0);
}
public function GetUserData(){
return (m_userData);
}
public function GetReactionForce():b2Vec2{
return (null);
}
public function SolvePositionConstraints():Boolean{
return (false);
}
public function SetUserData(data):void{
m_userData = data;
}
public function GetBody1():b2Body{
return (m_body1);
}
public function SolveVelocityConstraints(step:b2TimeStep):void{
}
public function InitPositionConstraints():void{
}
public static function Destroy(joint:b2Joint, allocator):void{
}
public static function Create(def:b2JointDef, allocator):b2Joint{
var joint:b2Joint;
switch (def.type){
case e_distanceJoint:
joint = new b2DistanceJoint((def as b2DistanceJointDef));
break;
case e_mouseJoint:
joint = new b2MouseJoint((def as b2MouseJointDef));
break;
case e_prismaticJoint:
joint = new b2PrismaticJoint((def as b2PrismaticJointDef));
break;
case e_revoluteJoint:
joint = new b2RevoluteJoint((def as b2RevoluteJointDef));
break;
case e_pulleyJoint:
joint = new b2PulleyJoint((def as b2PulleyJointDef));
break;
case e_gearJoint:
joint = new b2GearJoint((def as b2GearJointDef));
break;
default:
break;
};
return (joint);
}
}
}//package Box2D.Dynamics.Joints
Section 54
//b2JointDef (Box2D.Dynamics.Joints.b2JointDef)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
public class b2JointDef {
public var body2:b2Body;
public var type:int;
public var userData;
public var collideConnected:Boolean;
public var body1:b2Body;
public function b2JointDef(){
super();
type = b2Joint.e_unknownJoint;
userData = null;
body1 = null;
body2 = null;
collideConnected = false;
}
}
}//package Box2D.Dynamics.Joints
Section 55
//b2JointEdge (Box2D.Dynamics.Joints.b2JointEdge)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
public class b2JointEdge {
public var other:b2Body;
public var next:b2JointEdge;
public var prev:b2JointEdge;
public var joint:b2Joint;
public function b2JointEdge(){
super();
}
}
}//package Box2D.Dynamics.Joints
Section 56
//b2MouseJoint (Box2D.Dynamics.Joints.b2MouseJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2MouseJoint extends b2Joint {
private var K1:b2Mat22;
private var K:b2Mat22;
public var m_beta:Number;
public var m_mass:b2Mat22;
private var K2:b2Mat22;
public var m_target:b2Vec2;
public var m_gamma:Number;
public var m_impulse:b2Vec2;
public var m_C:b2Vec2;
public var m_localAnchor:b2Vec2;
public var m_maxForce:Number;
public function b2MouseJoint(def:b2MouseJointDef){
var tY:Number;
K = new b2Mat22();
K1 = new b2Mat22();
K2 = new b2Mat22();
m_localAnchor = new b2Vec2();
m_target = new b2Vec2();
m_impulse = new b2Vec2();
m_mass = new b2Mat22();
m_C = new b2Vec2();
super(def);
m_target.SetV(def.target);
var tX:Number = (m_target.x - m_body2.m_xf.position.x);
tY = (m_target.y - m_body2.m_xf.position.y);
var tMat:b2Mat22 = m_body2.m_xf.R;
m_localAnchor.x = ((tX * tMat.col1.x) + (tY * tMat.col1.y));
m_localAnchor.y = ((tX * tMat.col2.x) + (tY * tMat.col2.y));
m_maxForce = def.maxForce;
m_impulse.SetZero();
var mass:Number = m_body2.m_mass;
var omega:Number = ((2 * b2Settings.b2_pi) * def.frequencyHz);
var d:Number = (((2 * mass) * def.dampingRatio) * omega);
var k:Number = ((def.timeStep * mass) * (omega * omega));
m_gamma = (1 / (d + k));
m_beta = (k / (d + k));
}
public function SetTarget(target:b2Vec2):void{
if (m_body2.IsSleeping()){
m_body2.WakeUp();
};
m_target = target;
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor));
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var b:b2Body;
var tMat:b2Mat22;
var rX:Number;
var rY:Number;
var invMass:Number;
var invI:Number;
b = m_body2;
tMat = b.m_xf.R;
rX = (m_localAnchor.x - b.m_sweep.localCenter.x);
rY = (m_localAnchor.y - b.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
invMass = b.m_invMass;
invI = b.m_invI;
K1.col1.x = invMass;
K1.col2.x = 0;
K1.col1.y = 0;
K1.col2.y = invMass;
K2.col1.x = ((invI * rY) * rY);
K2.col2.x = ((-(invI) * rX) * rY);
K2.col1.y = ((-(invI) * rX) * rY);
K2.col2.y = ((invI * rX) * rX);
K.SetM(K1);
K.AddM(K2);
K.col1.x = (K.col1.x + m_gamma);
K.col2.y = (K.col2.y + m_gamma);
K.Invert(m_mass);
m_C.x = ((b.m_sweep.c.x + rX) - m_target.x);
m_C.y = ((b.m_sweep.c.y + rY) - m_target.y);
b.m_angularVelocity = (b.m_angularVelocity * 0.98);
var PX:Number = (step.dt * m_impulse.x);
var PY:Number = (step.dt * m_impulse.y);
b.m_linearVelocity.x = (b.m_linearVelocity.x + (invMass * PX));
b.m_linearVelocity.y = (b.m_linearVelocity.y + (invMass * PY));
b.m_angularVelocity = (b.m_angularVelocity + (invI * ((rX * PY) - (rY * PX))));
}
override public function GetAnchor1():b2Vec2{
return (m_target);
}
override public function GetReactionTorque():Number{
return (0);
}
override public function GetReactionForce():b2Vec2{
return (m_impulse);
}
override public function SolvePositionConstraints():Boolean{
return (true);
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
var b:b2Body = m_body2;
tMat = b.m_xf.R;
var rX:Number = (m_localAnchor.x - b.m_sweep.localCenter.x);
var rY:Number = (m_localAnchor.y - b.m_sweep.localCenter.y);
tX = ((tMat.col1.x * rX) + (tMat.col2.x * rY));
rY = ((tMat.col1.y * rX) + (tMat.col2.y * rY));
rX = tX;
var CdotX:Number = (b.m_linearVelocity.x + (-(b.m_angularVelocity) * rY));
var CdotY:Number = (b.m_linearVelocity.y + (b.m_angularVelocity * rX));
tMat = m_mass;
tX = ((CdotX + ((m_beta * step.inv_dt) * m_C.x)) + ((m_gamma * step.dt) * m_impulse.x));
tY = ((CdotY + ((m_beta * step.inv_dt) * m_C.y)) + ((m_gamma * step.dt) * m_impulse.y));
var forceX:Number = (-(step.inv_dt) * ((tMat.col1.x * tX) + (tMat.col2.x * tY)));
var forceY:Number = (-(step.inv_dt) * ((tMat.col1.y * tX) + (tMat.col2.y * tY)));
var oldForceX:Number = m_impulse.x;
var oldForceY:Number = m_impulse.y;
m_impulse.x = (m_impulse.x + forceX);
m_impulse.y = (m_impulse.y + forceY);
var forceMagnitude:Number = m_impulse.Length();
if (forceMagnitude > m_maxForce){
m_impulse.Multiply((m_maxForce / forceMagnitude));
};
forceX = (m_impulse.x - oldForceX);
forceY = (m_impulse.y - oldForceY);
var PX:Number = (step.dt * forceX);
var PY:Number = (step.dt * forceY);
b.m_linearVelocity.x = (b.m_linearVelocity.x + (b.m_invMass * PX));
b.m_linearVelocity.y = (b.m_linearVelocity.y + (b.m_invMass * PY));
b.m_angularVelocity = (b.m_angularVelocity + (b.m_invI * ((rX * PY) - (rY * PX))));
}
}
}//package Box2D.Dynamics.Joints
Section 57
//b2MouseJointDef (Box2D.Dynamics.Joints.b2MouseJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Common.Math.*;
public class b2MouseJointDef extends b2JointDef {
public var timeStep:Number;
public var target:b2Vec2;
public var maxForce:Number;
public var dampingRatio:Number;
public var frequencyHz:Number;
public function b2MouseJointDef(){
target = new b2Vec2();
super();
type = b2Joint.e_mouseJoint;
maxForce = 0;
frequencyHz = 5;
dampingRatio = 0.7;
timeStep = (1 / 60);
}
}
}//package Box2D.Dynamics.Joints
Section 58
//b2PrismaticJoint (Box2D.Dynamics.Joints.b2PrismaticJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PrismaticJoint extends b2Joint {
public var m_limitForce:Number;
public var m_lowerTranslation:Number;
public var m_localXAxis1:b2Vec2;
public var m_refAngle:Number;
public var m_torque:Number;
public var m_motorForce:Number;
public var m_enableLimit:Boolean;
public var m_angularMass:Number;
public var m_maxMotorForce:Number;
public var m_localYAxis1:b2Vec2;
public var m_force:Number;
public var m_motorMass:Number;
public var m_upperTranslation:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_limitState:int;
public var m_linearMass:Number;
public var m_motorJacobian:b2Jacobian;
public var m_limitPositionImpulse:Number;
public var m_motorSpeed:Number;
public var m_enableMotor:Boolean;
public var m_linearJacobian:b2Jacobian;
public function b2PrismaticJoint(def:b2PrismaticJointDef){
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_localXAxis1 = new b2Vec2();
m_localYAxis1 = new b2Vec2();
m_linearJacobian = new b2Jacobian();
m_motorJacobian = new b2Jacobian();
super(def);
m_localAnchor1.SetV(def.localAnchor1);
m_localAnchor2.SetV(def.localAnchor2);
m_localXAxis1.SetV(def.localAxis1);
m_localYAxis1.x = -(m_localXAxis1.y);
m_localYAxis1.y = m_localXAxis1.x;
m_refAngle = def.referenceAngle;
m_linearJacobian.SetZero();
m_linearMass = 0;
m_force = 0;
m_angularMass = 0;
m_torque = 0;
m_motorJacobian.SetZero();
m_motorMass = 0;
m_motorForce = 0;
m_limitForce = 0;
m_limitPositionImpulse = 0;
m_lowerTranslation = def.lowerTranslation;
m_upperTranslation = def.upperTranslation;
m_maxMotorForce = def.maxMotorForce;
m_motorSpeed = def.motorSpeed;
m_enableLimit = def.enableLimit;
m_enableMotor = def.enableMotor;
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var oldLimitForce:Number;
var P:Number;
var motorCdot:Number;
var motorForce:Number;
var oldMotorForce:Number;
var limitCdot:Number;
var limitForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
var linearCdot:Number = m_linearJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
var force:Number = ((-(step.inv_dt) * m_linearMass) * linearCdot);
m_force = (m_force + force);
P = (step.dt * force);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_linearJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_linearJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_linearJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_linearJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_linearJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_linearJacobian.angular2));
var angularCdot:Number = (b2.m_angularVelocity - b1.m_angularVelocity);
var torque:Number = ((-(step.inv_dt) * m_angularMass) * angularCdot);
m_torque = (m_torque + torque);
var L:Number = (step.dt * torque);
b1.m_angularVelocity = (b1.m_angularVelocity - (invI1 * L));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * L));
if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){
motorCdot = (m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity) - m_motorSpeed);
motorForce = ((-(step.inv_dt) * m_motorMass) * motorCdot);
oldMotorForce = m_motorForce;
m_motorForce = b2Math.b2Clamp((m_motorForce + motorForce), -(m_maxMotorForce), m_maxMotorForce);
motorForce = (m_motorForce - oldMotorForce);
P = (step.dt * motorForce);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_motorJacobian.angular2));
};
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
limitCdot = m_motorJacobian.Compute(b1.m_linearVelocity, b1.m_angularVelocity, b2.m_linearVelocity, b2.m_angularVelocity);
limitForce = ((-(step.inv_dt) * m_motorMass) * limitCdot);
if (m_limitState == e_equalLimits){
m_limitForce = (m_limitForce + limitForce);
} else {
if (m_limitState == e_atLowerLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Max((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
} else {
if (m_limitState == e_atUpperLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Min((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
};
};
};
P = (step.dt * limitForce);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + ((invMass1 * P) * m_motorJacobian.linear1.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + ((invMass1 * P) * m_motorJacobian.linear1.y));
b1.m_angularVelocity = (b1.m_angularVelocity + ((invI1 * P) * m_motorJacobian.angular1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((invMass2 * P) * m_motorJacobian.linear2.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((invMass2 * P) * m_motorJacobian.linear2.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((invI2 * P) * m_motorJacobian.angular2));
};
}
override public function GetAnchor1():b2Vec2{
return (m_body1.GetWorldPoint(m_localAnchor1));
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor2));
}
public function GetUpperLimit():Number{
return (m_upperTranslation);
}
public function GetLowerLimit():Number{
return (m_lowerTranslation);
}
public function EnableMotor(flag:Boolean):void{
m_enableMotor = flag;
}
public function GetJointTranslation():Number{
var tMat:b2Mat22;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var p1:b2Vec2 = b1.GetWorldPoint(m_localAnchor1);
var p2:b2Vec2 = b2.GetWorldPoint(m_localAnchor2);
var dX:Number = (p2.x - p1.x);
var dY:Number = (p2.y - p1.y);
var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1);
var translation:Number = ((axis.x * dX) + (axis.y * dY));
return (translation);
}
public function GetMotorSpeed():Number{
return (m_motorSpeed);
}
override public function GetReactionForce():b2Vec2{
var tMat:b2Mat22 = m_body1.m_xf.R;
var ax1X:Number = (m_limitForce * ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y)));
var ax1Y:Number = (m_limitForce * ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y)));
var ay1X:Number = (m_force * ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y)));
var ay1Y:Number = (m_force * ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y)));
return (new b2Vec2(((m_limitForce * ax1X) + (m_force * ay1X)), ((m_limitForce * ax1Y) + (m_force * ay1Y))));
}
override public function SolvePositionConstraints():Boolean{
var limitC:Number;
var oldLimitImpulse:Number;
var tMat:b2Mat22;
var tX:Number;
var ax1X:Number;
var ax1Y:Number;
var translation:Number;
var limitImpulse:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var p1X:Number = (b1.m_sweep.c.x + r1X);
var p1Y:Number = (b1.m_sweep.c.y + r1Y);
var p2X:Number = (b2.m_sweep.c.x + r2X);
var p2Y:Number = (b2.m_sweep.c.y + r2Y);
var dX:Number = (p2X - p1X);
var dY:Number = (p2Y - p1Y);
tMat = b1.m_xf.R;
var ay1X:Number = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
var ay1Y:Number = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
var linearC:Number = ((ay1X * dX) + (ay1Y * dY));
linearC = b2Math.b2Clamp(linearC, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
var linearImpulse:Number = (-(m_linearMass) * linearC);
b1.m_sweep.c.x = (b1.m_sweep.c.x + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.x));
b1.m_sweep.c.y = (b1.m_sweep.c.y + ((invMass1 * linearImpulse) * m_linearJacobian.linear1.y));
b1.m_sweep.a = (b1.m_sweep.a + ((invI1 * linearImpulse) * m_linearJacobian.angular1));
b2.m_sweep.c.x = (b2.m_sweep.c.x + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.x));
b2.m_sweep.c.y = (b2.m_sweep.c.y + ((invMass2 * linearImpulse) * m_linearJacobian.linear2.y));
b2.m_sweep.a = (b2.m_sweep.a + ((invI2 * linearImpulse) * m_linearJacobian.angular2));
var positionError:Number = b2Math.b2Abs(linearC);
var angularC:Number = ((b2.m_sweep.a - b1.m_sweep.a) - m_refAngle);
angularC = b2Math.b2Clamp(angularC, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);
var angularImpulse:Number = (-(m_angularMass) * angularC);
b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * angularImpulse));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * angularImpulse));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
var angularError:Number = b2Math.b2Abs(angularC);
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
tMat = b1.m_xf.R;
r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
p1X = (b1.m_sweep.c.x + r1X);
p1Y = (b1.m_sweep.c.y + r1Y);
p2X = (b2.m_sweep.c.x + r2X);
p2Y = (b2.m_sweep.c.y + r2Y);
dX = (p2X - p1X);
dY = (p2Y - p1Y);
tMat = b1.m_xf.R;
ax1X = ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y));
ax1Y = ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y));
translation = ((ax1X * dX) + (ax1Y * dY));
limitImpulse = 0;
if (m_limitState == e_equalLimits){
limitC = b2Math.b2Clamp(translation, -(b2Settings.b2_maxLinearCorrection), b2Settings.b2_maxLinearCorrection);
limitImpulse = (-(m_motorMass) * limitC);
positionError = b2Math.b2Max(positionError, b2Math.b2Abs(angularC));
} else {
if (m_limitState == e_atLowerLimit){
limitC = (translation - m_lowerTranslation);
positionError = b2Math.b2Max(positionError, -(limitC));
limitC = b2Math.b2Clamp((limitC + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Max((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
} else {
if (m_limitState == e_atUpperLimit){
limitC = (translation - m_upperTranslation);
positionError = b2Math.b2Max(positionError, limitC);
limitC = b2Math.b2Clamp((limitC - b2Settings.b2_linearSlop), 0, b2Settings.b2_maxLinearCorrection);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Min((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
};
};
};
b1.m_sweep.c.x = (b1.m_sweep.c.x + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.x));
b1.m_sweep.c.y = (b1.m_sweep.c.y + ((invMass1 * limitImpulse) * m_motorJacobian.linear1.y));
b1.m_sweep.a = (b1.m_sweep.a + ((invI1 * limitImpulse) * m_motorJacobian.angular1));
b2.m_sweep.c.x = (b2.m_sweep.c.x + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.x));
b2.m_sweep.c.y = (b2.m_sweep.c.y + ((invMass2 * limitImpulse) * m_motorJacobian.linear2.y));
b2.m_sweep.a = (b2.m_sweep.a + ((invI2 * limitImpulse) * m_motorJacobian.angular2));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function SetMotorSpeed(speed:Number):void{
m_motorSpeed = speed;
}
public function GetJointSpeed():Number{
var tMat:b2Mat22;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var p1X:Number = (b1.m_sweep.c.x + r1X);
var p1Y:Number = (b1.m_sweep.c.y + r1Y);
var p2X:Number = (b2.m_sweep.c.x + r2X);
var p2Y:Number = (b2.m_sweep.c.y + r2Y);
var dX:Number = (p2X - p1X);
var dY:Number = (p2Y - p1Y);
var axis:b2Vec2 = b1.GetWorldVector(m_localXAxis1);
var v1:b2Vec2 = b1.m_linearVelocity;
var v2:b2Vec2 = b2.m_linearVelocity;
var w1:Number = b1.m_angularVelocity;
var w2:Number = b2.m_angularVelocity;
var speed:Number = (((dX * (-(w1) * axis.y)) + (dY * (w1 * axis.x))) + ((axis.x * (((v2.x + (-(w2) * r2Y)) - v1.x) - (-(w1) * r1Y))) + (axis.y * (((v2.y + (w2 * r2X)) - v1.y) - (w1 * r1X)))));
return (speed);
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var ax1X:Number;
var ax1Y:Number;
var dX:Number;
var dY:Number;
var jointTranslation:Number;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var L1:Number;
var L2:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
tMat = b1.m_xf.R;
var ay1X:Number = ((tMat.col1.x * m_localYAxis1.x) + (tMat.col2.x * m_localYAxis1.y));
var ay1Y:Number = ((tMat.col1.y * m_localYAxis1.x) + (tMat.col2.y * m_localYAxis1.y));
var eX:Number = ((b2.m_sweep.c.x + r2X) - b1.m_sweep.c.x);
var eY:Number = ((b2.m_sweep.c.y + r2Y) - b1.m_sweep.c.y);
m_linearJacobian.linear1.x = -(ay1X);
m_linearJacobian.linear1.y = -(ay1Y);
m_linearJacobian.linear2.x = ay1X;
m_linearJacobian.linear2.y = ay1Y;
m_linearJacobian.angular1 = -(((eX * ay1Y) - (eY * ay1X)));
m_linearJacobian.angular2 = ((r2X * ay1Y) - (r2Y * ay1X));
m_linearMass = (((invMass1 + ((invI1 * m_linearJacobian.angular1) * m_linearJacobian.angular1)) + invMass2) + ((invI2 * m_linearJacobian.angular2) * m_linearJacobian.angular2));
m_linearMass = (1 / m_linearMass);
m_angularMass = (invI1 + invI2);
if (m_angularMass > Number.MIN_VALUE){
m_angularMass = (1 / m_angularMass);
};
if (((m_enableLimit) || (m_enableMotor))){
tMat = b1.m_xf.R;
ax1X = ((tMat.col1.x * m_localXAxis1.x) + (tMat.col2.x * m_localXAxis1.y));
ax1Y = ((tMat.col1.y * m_localXAxis1.x) + (tMat.col2.y * m_localXAxis1.y));
m_motorJacobian.linear1.x = -(ax1X);
m_motorJacobian.linear1.y = -(ax1Y);
m_motorJacobian.linear2.x = ax1X;
m_motorJacobian.linear2.y = ax1Y;
m_motorJacobian.angular1 = -(((eX * ax1Y) - (eY * ax1X)));
m_motorJacobian.angular2 = ((r2X * ax1Y) - (r2Y * ax1X));
m_motorMass = (((invMass1 + ((invI1 * m_motorJacobian.angular1) * m_motorJacobian.angular1)) + invMass2) + ((invI2 * m_motorJacobian.angular2) * m_motorJacobian.angular2));
m_motorMass = (1 / m_motorMass);
if (m_enableLimit){
dX = (eX - r1X);
dY = (eY - r1Y);
jointTranslation = ((ax1X * dX) + (ax1Y * dY));
if (b2Math.b2Abs((m_upperTranslation - m_lowerTranslation)) < (2 * b2Settings.b2_linearSlop)){
m_limitState = e_equalLimits;
} else {
if (jointTranslation <= m_lowerTranslation){
if (m_limitState != e_atLowerLimit){
m_limitForce = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointTranslation >= m_upperTranslation){
if (m_limitState != e_atUpperLimit){
m_limitForce = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitForce = 0;
};
};
};
};
};
if (m_enableMotor == false){
m_motorForce = 0;
};
if (m_enableLimit == false){
m_limitForce = 0;
};
if (step.warmStarting){
P1X = (step.dt * ((m_force * m_linearJacobian.linear1.x) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear1.x)));
P1Y = (step.dt * ((m_force * m_linearJacobian.linear1.y) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear1.y)));
P2X = (step.dt * ((m_force * m_linearJacobian.linear2.x) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear2.x)));
P2Y = (step.dt * ((m_force * m_linearJacobian.linear2.y) + ((m_motorForce + m_limitForce) * m_motorJacobian.linear2.y)));
L1 = (step.dt * (((m_force * m_linearJacobian.angular1) - m_torque) + ((m_motorForce + m_limitForce) * m_motorJacobian.angular1)));
L2 = (step.dt * (((m_force * m_linearJacobian.angular2) + m_torque) + ((m_motorForce + m_limitForce) * m_motorJacobian.angular2)));
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (invMass1 * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (invMass1 * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (invI1 * L1));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (invMass2 * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (invMass2 * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (invI2 * L2));
} else {
m_force = 0;
m_torque = 0;
m_limitForce = 0;
m_motorForce = 0;
};
m_limitPositionImpulse = 0;
}
public function GetMotorForce():Number{
return (m_motorForce);
}
public function EnableLimit(flag:Boolean):void{
m_enableLimit = flag;
}
public function SetMaxMotorForce(force:Number):void{
m_maxMotorForce = force;
}
override public function GetReactionTorque():Number{
return (m_torque);
}
public function IsLimitEnabled():Boolean{
return (m_enableLimit);
}
public function IsMotorEnabled():Boolean{
return (m_enableMotor);
}
public function SetLimits(lower:Number, upper:Number):void{
m_lowerTranslation = lower;
m_upperTranslation = upper;
}
}
}//package Box2D.Dynamics.Joints
Section 59
//b2PrismaticJointDef (Box2D.Dynamics.Joints.b2PrismaticJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2PrismaticJointDef extends b2JointDef {
public var motorSpeed:Number;
public var localAxis1:b2Vec2;
public var referenceAngle:Number;
public var upperTranslation:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var enableLimit:Boolean;
public var enableMotor:Boolean;
public var maxMotorForce:Number;
public var lowerTranslation:Number;
public function b2PrismaticJointDef(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
localAxis1 = new b2Vec2();
super();
type = b2Joint.e_prismaticJoint;
localAxis1.Set(1, 0);
referenceAngle = 0;
enableLimit = false;
lowerTranslation = 0;
upperTranslation = 0;
enableMotor = false;
maxMotorForce = 0;
motorSpeed = 0;
}
public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2, axis:b2Vec2):void{
body1 = b1;
body2 = b2;
localAnchor1 = body1.GetLocalPoint(anchor);
localAnchor2 = body2.GetLocalPoint(anchor);
localAxis1 = body1.GetLocalVector(axis);
referenceAngle = (body2.GetAngle() - body1.GetAngle());
}
}
}//package Box2D.Dynamics.Joints
Section 60
//b2PulleyJoint (Box2D.Dynamics.Joints.b2PulleyJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2PulleyJoint extends b2Joint {
public var m_limitState1:int;
public var m_limitState2:int;
public var m_ground:b2Body;
public var m_maxLength2:Number;
public var m_maxLength1:Number;
public var m_limitPositionImpulse1:Number;
public var m_limitPositionImpulse2:Number;
public var m_force:Number;
public var m_constant:Number;
public var m_positionImpulse:Number;
public var m_state:int;
public var m_ratio:Number;
public var m_groundAnchor1:b2Vec2;
public var m_groundAnchor2:b2Vec2;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
public var m_limitMass1:Number;
public var m_limitMass2:Number;
public var m_pulleyMass:Number;
public var m_u1:b2Vec2;
public var m_limitForce1:Number;
public var m_limitForce2:Number;
public var m_u2:b2Vec2;
public static const b2_minPulleyLength:Number = 2;
public function b2PulleyJoint(def:b2PulleyJointDef){
var tMat:b2Mat22;
var tX:Number;
var tY:Number;
m_groundAnchor1 = new b2Vec2();
m_groundAnchor2 = new b2Vec2();
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_u1 = new b2Vec2();
m_u2 = new b2Vec2();
super(def);
m_ground = m_body1.m_world.m_groundBody;
m_groundAnchor1.x = (def.groundAnchor1.x - m_ground.m_xf.position.x);
m_groundAnchor1.y = (def.groundAnchor1.y - m_ground.m_xf.position.y);
m_groundAnchor2.x = (def.groundAnchor2.x - m_ground.m_xf.position.x);
m_groundAnchor2.y = (def.groundAnchor2.y - m_ground.m_xf.position.y);
m_localAnchor1.SetV(def.localAnchor1);
m_localAnchor2.SetV(def.localAnchor2);
m_ratio = def.ratio;
m_constant = (def.length1 + (m_ratio * def.length2));
m_maxLength1 = b2Math.b2Min(def.maxLength1, (m_constant - (m_ratio * b2_minPulleyLength)));
m_maxLength2 = b2Math.b2Min(def.maxLength2, ((m_constant - b2_minPulleyLength) / m_ratio));
m_force = 0;
m_limitForce1 = 0;
m_limitForce2 = 0;
}
public function GetGroundAnchor2():b2Vec2{
var a:b2Vec2 = m_ground.m_xf.position.Copy();
a.Add(m_groundAnchor2);
return (a);
}
override public function GetAnchor1():b2Vec2{
return (m_body1.GetWorldPoint(m_localAnchor1));
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor2));
}
override public function GetReactionForce():b2Vec2{
var F:b2Vec2 = m_u2.Copy();
F.Multiply(m_force);
return (F);
}
override public function SolvePositionConstraints():Boolean{
var tMat:b2Mat22;
var r1X:Number;
var r1Y:Number;
var r2X:Number;
var r2Y:Number;
var p1X:Number;
var p1Y:Number;
var p2X:Number;
var p2Y:Number;
var length1:Number;
var length2:Number;
var C:Number;
var impulse:Number;
var oldImpulse:Number;
var oldLimitPositionImpulse:Number;
var tX:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var s1X:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x);
var s1Y:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y);
var s2X:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x);
var s2Y:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y);
var linearError:Number = 0;
if (m_state == e_atUpperLimit){
tMat = b1.m_xf.R;
r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
p1X = (b1.m_sweep.c.x + r1X);
p1Y = (b1.m_sweep.c.y + r1Y);
p2X = (b2.m_sweep.c.x + r2X);
p2Y = (b2.m_sweep.c.y + r2Y);
m_u1.Set((p1X - s1X), (p1Y - s1Y));
m_u2.Set((p2X - s2X), (p2Y - s2Y));
length1 = m_u1.Length();
length2 = m_u2.Length();
if (length1 > b2Settings.b2_linearSlop){
m_u1.Multiply((1 / length1));
} else {
m_u1.SetZero();
};
if (length2 > b2Settings.b2_linearSlop){
m_u2.Multiply((1 / length2));
} else {
m_u2.SetZero();
};
C = ((m_constant - length1) - (m_ratio * length2));
linearError = b2Math.b2Max(linearError, -(C));
C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0);
impulse = (-(m_pulleyMass) * C);
oldImpulse = m_positionImpulse;
m_positionImpulse = b2Math.b2Max(0, (m_positionImpulse + impulse));
impulse = (m_positionImpulse - oldImpulse);
p1X = (-(impulse) * m_u1.x);
p1Y = (-(impulse) * m_u1.y);
p2X = ((-(m_ratio) * impulse) * m_u2.x);
p2Y = ((-(m_ratio) * impulse) * m_u2.y);
b1.m_sweep.c.x = (b1.m_sweep.c.x + (b1.m_invMass * p1X));
b1.m_sweep.c.y = (b1.m_sweep.c.y + (b1.m_invMass * p1Y));
b1.m_sweep.a = (b1.m_sweep.a + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X))));
b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * p2X));
b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * p2Y));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X))));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
};
if (m_limitState1 == e_atUpperLimit){
tMat = b1.m_xf.R;
r1X = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
p1X = (b1.m_sweep.c.x + r1X);
p1Y = (b1.m_sweep.c.y + r1Y);
m_u1.Set((p1X - s1X), (p1Y - s1Y));
length1 = m_u1.Length();
if (length1 > b2Settings.b2_linearSlop){
m_u1.x = (m_u1.x * (1 / length1));
m_u1.y = (m_u1.y * (1 / length1));
} else {
m_u1.SetZero();
};
C = (m_maxLength1 - length1);
linearError = b2Math.b2Max(linearError, -(C));
C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0);
impulse = (-(m_limitMass1) * C);
oldLimitPositionImpulse = m_limitPositionImpulse1;
m_limitPositionImpulse1 = b2Math.b2Max(0, (m_limitPositionImpulse1 + impulse));
impulse = (m_limitPositionImpulse1 - oldLimitPositionImpulse);
p1X = (-(impulse) * m_u1.x);
p1Y = (-(impulse) * m_u1.y);
b1.m_sweep.c.x = (b1.m_sweep.c.x + (b1.m_invMass * p1X));
b1.m_sweep.c.y = (b1.m_sweep.c.y + (b1.m_invMass * p1Y));
b1.m_sweep.a = (b1.m_sweep.a + (b1.m_invI * ((r1X * p1Y) - (r1Y * p1X))));
b1.SynchronizeTransform();
};
if (m_limitState2 == e_atUpperLimit){
tMat = b2.m_xf.R;
r2X = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
r2Y = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
p2X = (b2.m_sweep.c.x + r2X);
p2Y = (b2.m_sweep.c.y + r2Y);
m_u2.Set((p2X - s2X), (p2Y - s2Y));
length2 = m_u2.Length();
if (length2 > b2Settings.b2_linearSlop){
m_u2.x = (m_u2.x * (1 / length2));
m_u2.y = (m_u2.y * (1 / length2));
} else {
m_u2.SetZero();
};
C = (m_maxLength2 - length2);
linearError = b2Math.b2Max(linearError, -(C));
C = b2Math.b2Clamp((C + b2Settings.b2_linearSlop), -(b2Settings.b2_maxLinearCorrection), 0);
impulse = (-(m_limitMass2) * C);
oldLimitPositionImpulse = m_limitPositionImpulse2;
m_limitPositionImpulse2 = b2Math.b2Max(0, (m_limitPositionImpulse2 + impulse));
impulse = (m_limitPositionImpulse2 - oldLimitPositionImpulse);
p2X = (-(impulse) * m_u2.x);
p2Y = (-(impulse) * m_u2.y);
b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * p2X));
b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * p2Y));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * p2Y) - (r2Y * p2X))));
b2.SynchronizeTransform();
};
return ((linearError < b2Settings.b2_linearSlop));
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var p1X:Number = (b1.m_sweep.c.x + r1X);
var p1Y:Number = (b1.m_sweep.c.y + r1Y);
var p2X:Number = (b2.m_sweep.c.x + r2X);
var p2Y:Number = (b2.m_sweep.c.y + r2Y);
var s1X:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x);
var s1Y:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y);
var s2X:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x);
var s2Y:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y);
m_u1.Set((p1X - s1X), (p1Y - s1Y));
m_u2.Set((p2X - s2X), (p2Y - s2Y));
var length1:Number = m_u1.Length();
var length2:Number = m_u2.Length();
if (length1 > b2Settings.b2_linearSlop){
m_u1.Multiply((1 / length1));
} else {
m_u1.SetZero();
};
if (length2 > b2Settings.b2_linearSlop){
m_u2.Multiply((1 / length2));
} else {
m_u2.SetZero();
};
var C:Number = ((m_constant - length1) - (m_ratio * length2));
if (C > 0){
m_state = e_inactiveLimit;
m_force = 0;
} else {
m_state = e_atUpperLimit;
m_positionImpulse = 0;
};
if (length1 < m_maxLength1){
m_limitState1 = e_inactiveLimit;
m_limitForce1 = 0;
} else {
m_limitState1 = e_atUpperLimit;
m_limitPositionImpulse1 = 0;
};
if (length2 < m_maxLength2){
m_limitState2 = e_inactiveLimit;
m_limitForce2 = 0;
} else {
m_limitState2 = e_atUpperLimit;
m_limitPositionImpulse2 = 0;
};
var cr1u1:Number = ((r1X * m_u1.y) - (r1Y * m_u1.x));
var cr2u2:Number = ((r2X * m_u2.y) - (r2Y * m_u2.x));
m_limitMass1 = (b1.m_invMass + ((b1.m_invI * cr1u1) * cr1u1));
m_limitMass2 = (b2.m_invMass + ((b2.m_invI * cr2u2) * cr2u2));
m_pulleyMass = (m_limitMass1 + ((m_ratio * m_ratio) * m_limitMass2));
m_limitMass1 = (1 / m_limitMass1);
m_limitMass2 = (1 / m_limitMass2);
m_pulleyMass = (1 / m_pulleyMass);
if (step.warmStarting){
P1X = ((step.dt * (-(m_force) - m_limitForce1)) * m_u1.x);
P1Y = ((step.dt * (-(m_force) - m_limitForce1)) * m_u1.y);
P2X = ((step.dt * ((-(m_ratio) * m_force) - m_limitForce2)) * m_u2.x);
P2Y = ((step.dt * ((-(m_ratio) * m_force) - m_limitForce2)) * m_u2.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
} else {
m_force = 0;
m_limitForce1 = 0;
m_limitForce2 = 0;
};
}
override public function GetReactionTorque():Number{
return (0);
}
public function GetRatio():Number{
return (m_ratio);
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var v1X:Number;
var v1Y:Number;
var v2X:Number;
var v2Y:Number;
var P1X:Number;
var P1Y:Number;
var P2X:Number;
var P2Y:Number;
var Cdot:Number;
var force:Number;
var oldForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
if (m_state == e_atUpperLimit){
v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y));
v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X));
v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y));
v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X));
Cdot = (-(((m_u1.x * v1X) + (m_u1.y * v1Y))) - (m_ratio * ((m_u2.x * v2X) + (m_u2.y * v2Y))));
force = ((-(step.inv_dt) * m_pulleyMass) * Cdot);
oldForce = m_force;
m_force = b2Math.b2Max(0, (m_force + force));
force = (m_force - oldForce);
P1X = ((-(step.dt) * force) * m_u1.x);
P1Y = ((-(step.dt) * force) * m_u1.y);
P2X = (((-(step.dt) * m_ratio) * force) * m_u2.x);
P2Y = (((-(step.dt) * m_ratio) * force) * m_u2.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
};
if (m_limitState1 == e_atUpperLimit){
v1X = (b1.m_linearVelocity.x + (-(b1.m_angularVelocity) * r1Y));
v1Y = (b1.m_linearVelocity.y + (b1.m_angularVelocity * r1X));
Cdot = -(((m_u1.x * v1X) + (m_u1.y * v1Y)));
force = ((-(step.inv_dt) * m_limitMass1) * Cdot);
oldForce = m_limitForce1;
m_limitForce1 = b2Math.b2Max(0, (m_limitForce1 + force));
force = (m_limitForce1 - oldForce);
P1X = ((-(step.dt) * force) * m_u1.x);
P1Y = ((-(step.dt) * force) * m_u1.y);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x + (b1.m_invMass * P1X));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y + (b1.m_invMass * P1Y));
b1.m_angularVelocity = (b1.m_angularVelocity + (b1.m_invI * ((r1X * P1Y) - (r1Y * P1X))));
};
if (m_limitState2 == e_atUpperLimit){
v2X = (b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y));
v2Y = (b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X));
Cdot = -(((m_u2.x * v2X) + (m_u2.y * v2Y)));
force = ((-(step.inv_dt) * m_limitMass2) * Cdot);
oldForce = m_limitForce2;
m_limitForce2 = b2Math.b2Max(0, (m_limitForce2 + force));
force = (m_limitForce2 - oldForce);
P2X = ((-(step.dt) * force) * m_u2.x);
P2Y = ((-(step.dt) * force) * m_u2.y);
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * P2X));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * P2Y));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * P2Y) - (r2Y * P2X))));
};
}
public function GetLength1():Number{
var p:b2Vec2 = m_body1.GetWorldPoint(m_localAnchor1);
var sX:Number = (m_ground.m_xf.position.x + m_groundAnchor1.x);
var sY:Number = (m_ground.m_xf.position.y + m_groundAnchor1.y);
var dX:Number = (p.x - sX);
var dY:Number = (p.y - sY);
return (Math.sqrt(((dX * dX) + (dY * dY))));
}
public function GetLength2():Number{
var p:b2Vec2 = m_body2.GetWorldPoint(m_localAnchor2);
var sX:Number = (m_ground.m_xf.position.x + m_groundAnchor2.x);
var sY:Number = (m_ground.m_xf.position.y + m_groundAnchor2.y);
var dX:Number = (p.x - sX);
var dY:Number = (p.y - sY);
return (Math.sqrt(((dX * dX) + (dY * dY))));
}
public function GetGroundAnchor1():b2Vec2{
var a:b2Vec2 = m_ground.m_xf.position.Copy();
a.Add(m_groundAnchor1);
return (a);
}
}
}//package Box2D.Dynamics.Joints
Section 61
//b2PulleyJointDef (Box2D.Dynamics.Joints.b2PulleyJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2PulleyJointDef extends b2JointDef {
public var maxLength1:Number;
public var maxLength2:Number;
public var length1:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var groundAnchor1:b2Vec2;
public var groundAnchor2:b2Vec2;
public var ratio:Number;
public var length2:Number;
public function b2PulleyJointDef(){
groundAnchor1 = new b2Vec2();
groundAnchor2 = new b2Vec2();
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
type = b2Joint.e_pulleyJoint;
groundAnchor1.Set(-1, 1);
groundAnchor2.Set(1, 1);
localAnchor1.Set(-1, 0);
localAnchor2.Set(1, 0);
length1 = 0;
maxLength1 = 0;
length2 = 0;
maxLength2 = 0;
ratio = 1;
collideConnected = true;
}
public function Initialize(b1:b2Body, b2:b2Body, ga1:b2Vec2, ga2:b2Vec2, anchor1:b2Vec2, anchor2:b2Vec2, r:Number):void{
body1 = b1;
body2 = b2;
groundAnchor1.SetV(ga1);
groundAnchor2.SetV(ga2);
localAnchor1 = body1.GetLocalPoint(anchor1);
localAnchor2 = body2.GetLocalPoint(anchor2);
var d1X:Number = (anchor1.x - ga1.x);
var d1Y:Number = (anchor1.y - ga1.y);
length1 = Math.sqrt(((d1X * d1X) + (d1Y * d1Y)));
var d2X:Number = (anchor2.x - ga2.x);
var d2Y:Number = (anchor2.y - ga2.y);
length2 = Math.sqrt(((d2X * d2X) + (d2Y * d2Y)));
ratio = r;
var C:Number = (length1 + (ratio * length2));
maxLength1 = (C - (ratio * b2PulleyJoint.b2_minPulleyLength));
maxLength2 = ((C - b2PulleyJoint.b2_minPulleyLength) / ratio);
}
}
}//package Box2D.Dynamics.Joints
Section 62
//b2RevoluteJoint (Box2D.Dynamics.Joints.b2RevoluteJoint)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
import Box2D.Common.*;
public class b2RevoluteJoint extends b2Joint {
public var m_limitForce:Number;
public var m_pivotMass:b2Mat22;
public var m_motorForce:Number;
public var m_enableLimit:Boolean;
public var m_limitState:int;
public var m_motorMass:Number;
public var m_localAnchor1:b2Vec2;
public var m_localAnchor2:b2Vec2;
private var K1:b2Mat22;
private var K2:b2Mat22;
private var K3:b2Mat22;
private var K:b2Mat22;
public var m_pivotForce:b2Vec2;
public var m_enableMotor:Boolean;
public var m_referenceAngle:Number;
public var m_limitPositionImpulse:Number;
public var m_motorSpeed:Number;
public var m_upperAngle:Number;
public var m_lowerAngle:Number;
public var m_maxMotorTorque:Number;
public static var tImpulse:b2Vec2 = new b2Vec2();
public function b2RevoluteJoint(def:b2RevoluteJointDef){
K = new b2Mat22();
K1 = new b2Mat22();
K2 = new b2Mat22();
K3 = new b2Mat22();
m_localAnchor1 = new b2Vec2();
m_localAnchor2 = new b2Vec2();
m_pivotForce = new b2Vec2();
m_pivotMass = new b2Mat22();
super(def);
m_localAnchor1.SetV(def.localAnchor1);
m_localAnchor2.SetV(def.localAnchor2);
m_referenceAngle = def.referenceAngle;
m_pivotForce.Set(0, 0);
m_motorForce = 0;
m_limitForce = 0;
m_limitPositionImpulse = 0;
m_lowerAngle = def.lowerAngle;
m_upperAngle = def.upperAngle;
m_maxMotorTorque = def.maxMotorTorque;
m_motorSpeed = def.motorSpeed;
m_enableLimit = def.enableLimit;
m_enableMotor = def.enableMotor;
}
override public function SolveVelocityConstraints(step:b2TimeStep):void{
var tMat:b2Mat22;
var tX:Number;
var oldLimitForce:Number;
var motorCdot:Number;
var motorForce:Number;
var oldMotorForce:Number;
var limitCdot:Number;
var limitForce:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var pivotCdotX:Number = (((b2.m_linearVelocity.x + (-(b2.m_angularVelocity) * r2Y)) - b1.m_linearVelocity.x) - (-(b1.m_angularVelocity) * r1Y));
var pivotCdotY:Number = (((b2.m_linearVelocity.y + (b2.m_angularVelocity * r2X)) - b1.m_linearVelocity.y) - (b1.m_angularVelocity * r1X));
var pivotForceX:Number = (-(step.inv_dt) * ((m_pivotMass.col1.x * pivotCdotX) + (m_pivotMass.col2.x * pivotCdotY)));
var pivotForceY:Number = (-(step.inv_dt) * ((m_pivotMass.col1.y * pivotCdotX) + (m_pivotMass.col2.y * pivotCdotY)));
m_pivotForce.x = (m_pivotForce.x + pivotForceX);
m_pivotForce.y = (m_pivotForce.y + pivotForceY);
var PX:Number = (step.dt * pivotForceX);
var PY:Number = (step.dt * pivotForceY);
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - (b1.m_invMass * PX));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - (b1.m_invMass * PY));
b1.m_angularVelocity = (b1.m_angularVelocity - (b1.m_invI * ((r1X * PY) - (r1Y * PX))));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + (b2.m_invMass * PX));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + (b2.m_invMass * PY));
b2.m_angularVelocity = (b2.m_angularVelocity + (b2.m_invI * ((r2X * PY) - (r2Y * PX))));
if (((m_enableMotor) && (!((m_limitState == e_equalLimits))))){
motorCdot = ((b2.m_angularVelocity - b1.m_angularVelocity) - m_motorSpeed);
motorForce = ((-(step.inv_dt) * m_motorMass) * motorCdot);
oldMotorForce = m_motorForce;
m_motorForce = b2Math.b2Clamp((m_motorForce + motorForce), -(m_maxMotorTorque), m_maxMotorTorque);
motorForce = (m_motorForce - oldMotorForce);
b1.m_angularVelocity = (b1.m_angularVelocity - ((b1.m_invI * step.dt) * motorForce));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * step.dt) * motorForce));
};
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
limitCdot = (b2.m_angularVelocity - b1.m_angularVelocity);
limitForce = ((-(step.inv_dt) * m_motorMass) * limitCdot);
if (m_limitState == e_equalLimits){
m_limitForce = (m_limitForce + limitForce);
} else {
if (m_limitState == e_atLowerLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Max((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
} else {
if (m_limitState == e_atUpperLimit){
oldLimitForce = m_limitForce;
m_limitForce = b2Math.b2Min((m_limitForce + limitForce), 0);
limitForce = (m_limitForce - oldLimitForce);
};
};
};
b1.m_angularVelocity = (b1.m_angularVelocity - ((b1.m_invI * step.dt) * limitForce));
b2.m_angularVelocity = (b2.m_angularVelocity + ((b2.m_invI * step.dt) * limitForce));
};
}
override public function GetAnchor1():b2Vec2{
return (m_body1.GetWorldPoint(m_localAnchor1));
}
override public function GetAnchor2():b2Vec2{
return (m_body2.GetWorldPoint(m_localAnchor2));
}
public function GetUpperLimit():Number{
return (m_upperAngle);
}
public function GetLowerLimit():Number{
return (m_lowerAngle);
}
public function EnableMotor(flag:Boolean):void{
m_enableMotor = flag;
}
public function GetMotorSpeed():Number{
return (m_motorSpeed);
}
override public function GetReactionForce():b2Vec2{
return (m_pivotForce);
}
override public function SolvePositionConstraints():Boolean{
var oldLimitImpulse:Number;
var limitC:Number;
var tMat:b2Mat22;
var angle:Number;
var limitImpulse:Number;
var b1:b2Body = m_body1;
var b2:b2Body = m_body2;
var positionError:Number = 0;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
var r1Y:Number = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
var tX:Number = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var p1X:Number = (b1.m_sweep.c.x + r1X);
var p1Y:Number = (b1.m_sweep.c.y + r1Y);
var p2X:Number = (b2.m_sweep.c.x + r2X);
var p2Y:Number = (b2.m_sweep.c.y + r2Y);
var ptpCX:Number = (p2X - p1X);
var ptpCY:Number = (p2Y - p1Y);
positionError = Math.sqrt(((ptpCX * ptpCX) + (ptpCY * ptpCY)));
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
K1.col1.x = (invMass1 + invMass2);
K1.col2.x = 0;
K1.col1.y = 0;
K1.col2.y = (invMass1 + invMass2);
K2.col1.x = ((invI1 * r1Y) * r1Y);
K2.col2.x = ((-(invI1) * r1X) * r1Y);
K2.col1.y = ((-(invI1) * r1X) * r1Y);
K2.col2.y = ((invI1 * r1X) * r1X);
K3.col1.x = ((invI2 * r2Y) * r2Y);
K3.col2.x = ((-(invI2) * r2X) * r2Y);
K3.col1.y = ((-(invI2) * r2X) * r2Y);
K3.col2.y = ((invI2 * r2X) * r2X);
K.SetM(K1);
K.AddM(K2);
K.AddM(K3);
K.Solve(tImpulse, -(ptpCX), -(ptpCY));
var impulseX:Number = tImpulse.x;
var impulseY:Number = tImpulse.y;
b1.m_sweep.c.x = (b1.m_sweep.c.x - (b1.m_invMass * impulseX));
b1.m_sweep.c.y = (b1.m_sweep.c.y - (b1.m_invMass * impulseY));
b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * ((r1X * impulseY) - (r1Y * impulseX))));
b2.m_sweep.c.x = (b2.m_sweep.c.x + (b2.m_invMass * impulseX));
b2.m_sweep.c.y = (b2.m_sweep.c.y + (b2.m_invMass * impulseY));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * ((r2X * impulseY) - (r2Y * impulseX))));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
var angularError:Number = 0;
if (((m_enableLimit) && (!((m_limitState == e_inactiveLimit))))){
angle = ((b2.m_sweep.a - b1.m_sweep.a) - m_referenceAngle);
limitImpulse = 0;
if (m_limitState == e_equalLimits){
limitC = b2Math.b2Clamp(angle, -(b2Settings.b2_maxAngularCorrection), b2Settings.b2_maxAngularCorrection);
limitImpulse = (-(m_motorMass) * limitC);
angularError = b2Math.b2Abs(limitC);
} else {
if (m_limitState == e_atLowerLimit){
limitC = (angle - m_lowerAngle);
angularError = b2Math.b2Max(0, -(limitC));
limitC = b2Math.b2Clamp((limitC + b2Settings.b2_angularSlop), -(b2Settings.b2_maxAngularCorrection), 0);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Max((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
} else {
if (m_limitState == e_atUpperLimit){
limitC = (angle - m_upperAngle);
angularError = b2Math.b2Max(0, limitC);
limitC = b2Math.b2Clamp((limitC - b2Settings.b2_angularSlop), 0, b2Settings.b2_maxAngularCorrection);
limitImpulse = (-(m_motorMass) * limitC);
oldLimitImpulse = m_limitPositionImpulse;
m_limitPositionImpulse = b2Math.b2Min((m_limitPositionImpulse + limitImpulse), 0);
limitImpulse = (m_limitPositionImpulse - oldLimitImpulse);
};
};
};
b1.m_sweep.a = (b1.m_sweep.a - (b1.m_invI * limitImpulse));
b2.m_sweep.a = (b2.m_sweep.a + (b2.m_invI * limitImpulse));
b1.SynchronizeTransform();
b2.SynchronizeTransform();
};
return ((((positionError <= b2Settings.b2_linearSlop)) && ((angularError <= b2Settings.b2_angularSlop))));
}
public function SetMotorSpeed(speed:Number):void{
m_motorSpeed = speed;
}
public function GetJointSpeed():Number{
return ((m_body2.m_angularVelocity - m_body1.m_angularVelocity));
}
public function SetMaxMotorTorque(torque:Number):void{
m_maxMotorTorque = torque;
}
public function GetJointAngle():Number{
return (((m_body2.m_sweep.a - m_body1.m_sweep.a) - m_referenceAngle));
}
public function GetMotorTorque():Number{
return (m_motorForce);
}
override public function InitVelocityConstraints(step:b2TimeStep):void{
var b1:b2Body;
var b2:b2Body;
var tMat:b2Mat22;
var tX:Number;
var r1Y:Number;
var jointAngle:Number;
b1 = m_body1;
b2 = m_body2;
tMat = b1.m_xf.R;
var r1X:Number = (m_localAnchor1.x - b1.m_sweep.localCenter.x);
r1Y = (m_localAnchor1.y - b1.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r1X) + (tMat.col2.x * r1Y));
r1Y = ((tMat.col1.y * r1X) + (tMat.col2.y * r1Y));
r1X = tX;
tMat = b2.m_xf.R;
var r2X:Number = (m_localAnchor2.x - b2.m_sweep.localCenter.x);
var r2Y:Number = (m_localAnchor2.y - b2.m_sweep.localCenter.y);
tX = ((tMat.col1.x * r2X) + (tMat.col2.x * r2Y));
r2Y = ((tMat.col1.y * r2X) + (tMat.col2.y * r2Y));
r2X = tX;
var invMass1:Number = b1.m_invMass;
var invMass2:Number = b2.m_invMass;
var invI1:Number = b1.m_invI;
var invI2:Number = b2.m_invI;
K1.col1.x = (invMass1 + invMass2);
K1.col2.x = 0;
K1.col1.y = 0;
K1.col2.y = (invMass1 + invMass2);
K2.col1.x = ((invI1 * r1Y) * r1Y);
K2.col2.x = ((-(invI1) * r1X) * r1Y);
K2.col1.y = ((-(invI1) * r1X) * r1Y);
K2.col2.y = ((invI1 * r1X) * r1X);
K3.col1.x = ((invI2 * r2Y) * r2Y);
K3.col2.x = ((-(invI2) * r2X) * r2Y);
K3.col1.y = ((-(invI2) * r2X) * r2Y);
K3.col2.y = ((invI2 * r2X) * r2X);
K.SetM(K1);
K.AddM(K2);
K.AddM(K3);
K.Invert(m_pivotMass);
m_motorMass = (1 / (invI1 + invI2));
if (m_enableMotor == false){
m_motorForce = 0;
};
if (m_enableLimit){
jointAngle = ((b2.m_sweep.a - b1.m_sweep.a) - m_referenceAngle);
if (b2Math.b2Abs((m_upperAngle - m_lowerAngle)) < (2 * b2Settings.b2_angularSlop)){
m_limitState = e_equalLimits;
} else {
if (jointAngle <= m_lowerAngle){
if (m_limitState != e_atLowerLimit){
m_limitForce = 0;
};
m_limitState = e_atLowerLimit;
} else {
if (jointAngle >= m_upperAngle){
if (m_limitState != e_atUpperLimit){
m_limitForce = 0;
};
m_limitState = e_atUpperLimit;
} else {
m_limitState = e_inactiveLimit;
m_limitForce = 0;
};
};
};
} else {
m_limitForce = 0;
};
if (step.warmStarting){
b1.m_linearVelocity.x = (b1.m_linearVelocity.x - ((step.dt * invMass1) * m_pivotForce.x));
b1.m_linearVelocity.y = (b1.m_linearVelocity.y - ((step.dt * invMass1) * m_pivotForce.y));
b1.m_angularVelocity = (b1.m_angularVelocity - ((step.dt * invI1) * ((((r1X * m_pivotForce.y) - (r1Y * m_pivotForce.x)) + m_motorForce) + m_limitForce)));
b2.m_linearVelocity.x = (b2.m_linearVelocity.x + ((step.dt * invMass2) * m_pivotForce.x));
b2.m_linearVelocity.y = (b2.m_linearVelocity.y + ((step.dt * invMass2) * m_pivotForce.y));
b2.m_angularVelocity = (b2.m_angularVelocity + ((step.dt * invI2) * ((((r2X * m_pivotForce.y) - (r2Y * m_pivotForce.x)) + m_motorForce) + m_limitForce)));
} else {
m_pivotForce.SetZero();
m_motorForce = 0;
m_limitForce = 0;
};
m_limitPositionImpulse = 0;
}
public function EnableLimit(flag:Boolean):void{
m_enableLimit = flag;
}
override public function GetReactionTorque():Number{
return (m_limitForce);
}
public function IsLimitEnabled():Boolean{
return (m_enableLimit);
}
public function IsMotorEnabled():Boolean{
return (m_enableMotor);
}
public function SetLimits(lower:Number, upper:Number):void{
m_lowerAngle = lower;
m_upperAngle = upper;
}
}
}//package Box2D.Dynamics.Joints
Section 63
//b2RevoluteJointDef (Box2D.Dynamics.Joints.b2RevoluteJointDef)
package Box2D.Dynamics.Joints {
import Box2D.Dynamics.*;
import Box2D.Common.Math.*;
public class b2RevoluteJointDef extends b2JointDef {
public var upperAngle:Number;
public var enableMotor:Boolean;
public var referenceAngle:Number;
public var motorSpeed:Number;
public var localAnchor1:b2Vec2;
public var localAnchor2:b2Vec2;
public var enableLimit:Boolean;
public var lowerAngle:Number;
public var maxMotorTorque:Number;
public function b2RevoluteJointDef(){
localAnchor1 = new b2Vec2();
localAnchor2 = new b2Vec2();
super();
type = b2Joint.e_revoluteJoint;
localAnchor1.Set(0, 0);
localAnchor2.Set(0, 0);
referenceAngle = 0;
lowerAngle = 0;
upperAngle = 0;
maxMotorTorque = 0;
motorSpeed = 0;
enableLimit = false;
enableMotor = false;
}
public function Initialize(b1:b2Body, b2:b2Body, anchor:b2Vec2):void{
body1 = b1;
body2 = b2;
localAnchor1 = body1.GetLocalPoint(anchor);
localAnchor2 = body2.GetLocalPoint(anchor);
referenceAngle = (body2.GetAngle() - body1.GetAngle());
}
}
}//package Box2D.Dynamics.Joints
Section 64
//b2Body (Box2D.Dynamics.b2Body)
package Box2D.Dynamics {
import Box2D.Dynamics.Joints.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Dynamics.Contacts.*;
public class b2Body {
public var m_next:b2Body;
public var m_xf:b2XForm;
public var m_contactList:b2ContactEdge;
public var m_angularVelocity:Number;
public var m_shapeList:b2Shape;
public var m_force:b2Vec2;
public var m_mass:Number;
public var m_sweep:b2Sweep;
public var m_torque:Number;
public var m_userData;
public var m_flags:uint;
public var m_world:b2World;
public var m_prev:b2Body;
public var m_invMass:Number;
public var m_type:int;
public var m_linearDamping:Number;
public var m_shapeCount:int;
public var m_angularDamping:Number;
public var usedInGame:Boolean;// = false
public var m_invI:Number;
public var m_linearVelocity:b2Vec2;
public var m_sleepTime:Number;
public var m_jointList:b2JointEdge;
public var m_I:Number;
public static var e_fixedRotationFlag:uint = 64;
public static var e_frozenFlag:uint = 2;
public static var e_maxTypes:uint = 3;
public static var e_sleepFlag:uint = 8;
private static var s_massData:b2MassData = new b2MassData();
public static var e_bulletFlag:uint = 32;
public static var e_staticType:uint = 1;
public static var e_islandFlag:uint = 4;
public static var e_allowSleepFlag:uint = 16;
private static var s_xf1:b2XForm = new b2XForm();
public static var e_dynamicType:uint = 2;
public function b2Body(bd:b2BodyDef, world:b2World){
m_xf = new b2XForm();
m_sweep = new b2Sweep();
m_linearVelocity = new b2Vec2();
m_force = new b2Vec2();
super();
m_flags = 0;
if (bd.isBullet){
m_flags = (m_flags | e_bulletFlag);
};
if (bd.fixedRotation){
m_flags = (m_flags | e_fixedRotationFlag);
};
if (bd.allowSleep){
m_flags = (m_flags | e_allowSleepFlag);
};
if (bd.isSleeping){
m_flags = (m_flags | e_sleepFlag);
};
m_world = world;
m_xf.position.SetV(bd.position);
m_xf.R.Set(bd.angle);
m_sweep.localCenter.SetV(bd.massData.center);
m_sweep.t0 = 1;
m_sweep.a0 = (m_sweep.a = bd.angle);
var tMat:b2Mat22 = m_xf.R;
var tVec:b2Vec2 = m_sweep.localCenter;
m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
m_sweep.c.x = (m_sweep.c.x + m_xf.position.x);
m_sweep.c.y = (m_sweep.c.y + m_xf.position.y);
m_sweep.c0.SetV(m_sweep.c);
m_jointList = null;
m_contactList = null;
m_prev = null;
m_next = null;
m_linearDamping = bd.linearDamping;
m_angularDamping = bd.angularDamping;
m_force.Set(0, 0);
m_torque = 0;
m_linearVelocity.SetZero();
m_angularVelocity = 0;
m_sleepTime = 0;
m_invMass = 0;
m_I = 0;
m_invI = 0;
m_mass = bd.massData.mass;
if (m_mass > 0){
m_invMass = (1 / m_mass);
};
if ((m_flags & b2Body.e_fixedRotationFlag) == 0){
m_I = bd.massData.I;
};
if (m_I > 0){
m_invI = (1 / m_I);
};
if ((((m_invMass == 0)) && ((m_invI == 0)))){
m_type = e_staticType;
} else {
m_type = e_dynamicType;
};
m_userData = bd.userData;
m_shapeList = null;
m_shapeCount = 0;
}
public function GetLinearVelocityFromWorldPoint(worldPoint:b2Vec2):b2Vec2{
return (new b2Vec2((m_linearVelocity.x + (m_angularVelocity * (worldPoint.y - m_sweep.c.y))), (m_linearVelocity.x - (m_angularVelocity * (worldPoint.x - m_sweep.c.x)))));
}
public function SetLinearVelocity(v:b2Vec2):void{
m_linearVelocity.SetV(v);
}
public function WakeUp():void{
m_flags = (m_flags & ~(e_sleepFlag));
m_sleepTime = 0;
usedInGame = true;
}
public function GetLocalCenter():b2Vec2{
return (m_sweep.localCenter);
}
public function ApplyTorque(torque:Number):void{
if (IsSleeping()){
WakeUp();
};
m_torque = (m_torque + torque);
}
public function IsFrozen():Boolean{
return (((m_flags & e_frozenFlag) == e_frozenFlag));
}
public function IsDynamic():Boolean{
return ((m_type == e_dynamicType));
}
public function GetLinearVelocity():b2Vec2{
return (m_linearVelocity);
}
public function SynchronizeTransform():void{
m_xf.R.Set(m_sweep.a);
var tMat:b2Mat22 = m_xf.R;
var tVec:b2Vec2 = m_sweep.localCenter;
m_xf.position.x = (m_sweep.c.x - ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
m_xf.position.y = (m_sweep.c.y - ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
}
public function GetInertia():Number{
return (m_I);
}
public function IsSleeping():Boolean{
return (((m_flags & e_sleepFlag) == e_sleepFlag));
}
public function SetMassFromShapes():void{
var s:b2Shape;
if (m_world.m_lock == true){
return;
};
m_mass = 0;
m_invMass = 0;
m_I = 0;
m_invI = 0;
var centerX:Number = 0;
var centerY:Number = 0;
var massData:b2MassData = s_massData;
s = m_shapeList;
while (s) {
s.ComputeMass(massData);
m_mass = (m_mass + massData.mass);
centerX = (centerX + (massData.mass * massData.center.x));
centerY = (centerY + (massData.mass * massData.center.y));
m_I = (m_I + massData.I);
s = s.m_next;
};
if (m_mass > 0){
m_invMass = (1 / m_mass);
centerX = (centerX * m_invMass);
centerY = (centerY * m_invMass);
};
if ((((m_I > 0)) && (((m_flags & e_fixedRotationFlag) == 0)))){
m_I = (m_I - (m_mass * ((centerX * centerX) + (centerY * centerY))));
m_invI = (1 / m_I);
} else {
m_I = 0;
m_invI = 0;
};
m_sweep.localCenter.Set(centerX, centerY);
var tMat:b2Mat22 = m_xf.R;
var tVec:b2Vec2 = m_sweep.localCenter;
m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
m_sweep.c.x = (m_sweep.c.x + m_xf.position.x);
m_sweep.c.y = (m_sweep.c.y + m_xf.position.y);
m_sweep.c0.SetV(m_sweep.c);
s = m_shapeList;
while (s) {
s.UpdateSweepRadius(m_sweep.localCenter);
s = s.m_next;
};
var oldType:int = m_type;
if ((((m_invMass == 0)) && ((m_invI == 0)))){
m_type = e_staticType;
} else {
m_type = e_dynamicType;
};
if (oldType != m_type){
s = m_shapeList;
while (s) {
s.RefilterProxy(m_world.m_broadPhase, m_xf);
s = s.m_next;
};
};
}
public function PutToSleep():void{
m_flags = (m_flags | e_sleepFlag);
m_sleepTime = 0;
m_linearVelocity.SetZero();
m_angularVelocity = 0;
m_force.SetZero();
m_torque = 0;
}
public function GetJointList():b2JointEdge{
return (m_jointList);
}
public function SetXForm(position:b2Vec2, angle:Number):Boolean{
var s:b2Shape;
var inRange:Boolean;
if (m_world.m_lock == true){
return (true);
};
if (IsFrozen()){
return (false);
};
m_xf.R.Set(angle);
m_xf.position.SetV(position);
var tMat:b2Mat22 = m_xf.R;
var tVec:b2Vec2 = m_sweep.localCenter;
m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
m_sweep.c.x = (m_sweep.c.x + m_xf.position.x);
m_sweep.c.y = (m_sweep.c.y + m_xf.position.y);
m_sweep.c0.SetV(m_sweep.c);
m_sweep.a0 = (m_sweep.a = angle);
var freeze:Boolean;
s = m_shapeList;
while (s) {
inRange = s.Synchronize(m_world.m_broadPhase, m_xf, m_xf);
if (inRange == false){
freeze = true;
break;
};
s = s.m_next;
};
if (freeze == true){
m_flags = (m_flags | e_frozenFlag);
m_linearVelocity.SetZero();
m_angularVelocity = 0;
s = m_shapeList;
while (s) {
s.DestroyProxy(m_world.m_broadPhase);
s = s.m_next;
};
return (false);
};
m_world.m_broadPhase.Commit();
return (true);
}
public function GetLocalPoint(worldPoint:b2Vec2):b2Vec2{
return (b2Math.b2MulXT(m_xf, worldPoint));
}
public function ApplyForce(force:b2Vec2, point:b2Vec2):void{
if (IsSleeping()){
WakeUp();
};
m_force.x = (m_force.x + force.x);
m_force.y = (m_force.y + force.y);
m_torque = (m_torque + (((point.x - m_sweep.c.x) * force.y) - ((point.y - m_sweep.c.y) * force.x)));
}
public function SynchronizeShapes():Boolean{
var s:b2Shape;
var xf1:b2XForm = s_xf1;
xf1.R.Set(m_sweep.a0);
var tMat:b2Mat22 = xf1.R;
var tVec:b2Vec2 = m_sweep.localCenter;
xf1.position.x = (m_sweep.c0.x - ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
xf1.position.y = (m_sweep.c0.y - ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
var inRange:Boolean;
s = m_shapeList;
while (s) {
inRange = s.Synchronize(m_world.m_broadPhase, xf1, m_xf);
if (inRange == false){
break;
};
s = s.m_next;
};
if (inRange == false){
m_flags = (m_flags | e_frozenFlag);
m_linearVelocity.SetZero();
m_angularVelocity = 0;
s = m_shapeList;
while (s) {
s.DestroyProxy(m_world.m_broadPhase);
s = s.m_next;
};
return (false);
};
return (true);
}
public function GetAngle():Number{
return (m_sweep.a);
}
public function GetXForm():b2XForm{
return (m_xf);
}
public function GetLinearVelocityFromLocalPoint(localPoint:b2Vec2):b2Vec2{
var A:b2Mat22 = m_xf.R;
var worldPoint:b2Vec2 = new b2Vec2(((A.col1.x * localPoint.x) + (A.col2.x * localPoint.y)), ((A.col1.y * localPoint.x) + (A.col2.y * localPoint.y)));
worldPoint.x = (worldPoint.x + m_xf.position.x);
worldPoint.y = (worldPoint.y + m_xf.position.y);
return (new b2Vec2((m_linearVelocity.x + (m_angularVelocity * (worldPoint.y - m_sweep.c.y))), (m_linearVelocity.x - (m_angularVelocity * (worldPoint.x - m_sweep.c.x)))));
}
public function GetNext():b2Body{
return (m_next);
}
public function GetMass():Number{
return (m_mass);
}
public function ApplyImpulse(impulse:b2Vec2, point:b2Vec2):void{
if (IsSleeping()){
WakeUp();
};
m_linearVelocity.x = (m_linearVelocity.x + (m_invMass * impulse.x));
m_linearVelocity.y = (m_linearVelocity.y + (m_invMass * impulse.y));
m_angularVelocity = (m_angularVelocity + (m_invI * (((point.x - m_sweep.c.x) * impulse.y) - ((point.y - m_sweep.c.y) * impulse.x))));
}
public function GetAngularVelocity():Number{
return (m_angularVelocity);
}
public function SetAngularVelocity(omega:Number):void{
m_angularVelocity = omega;
}
public function SetMass(massData:b2MassData):void{
var s:b2Shape;
if (m_world.m_lock == true){
return;
};
m_invMass = 0;
m_I = 0;
m_invI = 0;
m_mass = massData.mass;
if (m_mass > 0){
m_invMass = (1 / m_mass);
};
if ((m_flags & b2Body.e_fixedRotationFlag) == 0){
m_I = massData.I;
};
if (m_I > 0){
m_invI = (1 / m_I);
};
m_sweep.localCenter.SetV(massData.center);
var tMat:b2Mat22 = m_xf.R;
var tVec:b2Vec2 = m_sweep.localCenter;
m_sweep.c.x = ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y));
m_sweep.c.y = ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y));
m_sweep.c.x = (m_sweep.c.x + m_xf.position.x);
m_sweep.c.y = (m_sweep.c.y + m_xf.position.y);
m_sweep.c0.SetV(m_sweep.c);
s = m_shapeList;
while (s) {
s.UpdateSweepRadius(m_sweep.localCenter);
s = s.m_next;
};
var oldType:int = m_type;
if ((((m_invMass == 0)) && ((m_invI == 0)))){
m_type = e_staticType;
} else {
m_type = e_dynamicType;
};
if (oldType != m_type){
s = m_shapeList;
while (s) {
s.RefilterProxy(m_world.m_broadPhase, m_xf);
s = s.m_next;
};
};
}
public function IsStatic():Boolean{
return ((m_type == e_staticType));
}
public function GetWorldVector(localVector:b2Vec2):b2Vec2{
return (b2Math.b2MulMV(m_xf.R, localVector));
}
public function GetShapeList():b2Shape{
return (m_shapeList);
}
public function Advance(t:Number):void{
m_sweep.Advance(t);
m_sweep.c.SetV(m_sweep.c0);
m_sweep.a = m_sweep.a0;
SynchronizeTransform();
}
public function SetBullet(flag:Boolean):void{
if (flag){
m_flags = (m_flags | e_bulletFlag);
} else {
m_flags = (m_flags & ~(e_bulletFlag));
};
}
public function CreateShape(def:b2ShapeDef):b2Shape{
if (m_world.m_lock == true){
return (null);
};
var s:b2Shape = b2Shape.Create(def, m_world.m_blockAllocator);
s.m_next = m_shapeList;
m_shapeList = s;
m_shapeCount++;
s.m_body = this;
s.CreateProxy(m_world.m_broadPhase, m_xf);
s.UpdateSweepRadius(m_sweep.localCenter);
return (s);
}
public function IsConnected(other:b2Body):Boolean{
var jn:b2JointEdge = m_jointList;
while (jn) {
if (jn.other == other){
return ((jn.joint.m_collideConnected == false));
};
jn = jn.next;
};
return (false);
}
public function DestroyShape(s:b2Shape):void{
if (m_world.m_lock == true){
return;
};
s.DestroyProxy(m_world.m_broadPhase);
var node:b2Shape = m_shapeList;
var ppS:b2Shape;
var found:Boolean;
while (node != null) {
if (node == s){
if (ppS){
ppS.m_next = s.m_next;
} else {
m_shapeList = s.m_next;
};
found = true;
break;
};
ppS = node;
node = node.m_next;
};
s.m_body = null;
s.m_next = null;
m_shapeCount--;
b2Shape.Destroy(s, m_world.m_blockAllocator);
}
public function GetUserData(){
return (m_userData);
}
public function IsBullet():Boolean{
return (((m_flags & e_bulletFlag) == e_bulletFlag));
}
public function GetWorldCenter():b2Vec2{
return (m_sweep.c);
}
public function AllowSleeping(flag:Boolean):void{
if (flag){
m_flags = (m_flags | e_allowSleepFlag);
} else {
m_flags = (m_flags & ~(e_allowSleepFlag));
WakeUp();
};
}
public function SetUserData(data):void{
m_userData = data;
}
public function GetLocalVector(worldVector:b2Vec2):b2Vec2{
return (b2Math.b2MulTMV(m_xf.R, worldVector));
}
public function GetWorldPoint(localPoint:b2Vec2):b2Vec2{
var A:b2Mat22 = m_xf.R;
var u:b2Vec2 = new b2Vec2(((A.col1.x * localPoint.x) + (A.col2.x * localPoint.y)), ((A.col1.y * localPoint.x) + (A.col2.y * localPoint.y)));
u.x = (u.x + m_xf.position.x);
u.y = (u.y + m_xf.position.y);
return (u);
}
public function GetWorld():b2World{
return (m_world);
}
public function GetPosition():b2Vec2{
return (m_xf.position);
}
}
}//package Box2D.Dynamics
Section 65
//b2BodyDef (Box2D.Dynamics.b2BodyDef)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
public class b2BodyDef {
public var angularDamping:Number;
public var angle:Number;
public var isSleeping:Boolean;
public var position:b2Vec2;
public var isBullet:Boolean;
public var allowSleep:Boolean;
public var userData;
public var fixedRotation:Boolean;
public var linearDamping:Number;
public var massData:b2MassData;
public function b2BodyDef(){
massData = new b2MassData();
position = new b2Vec2();
super();
massData.center.SetZero();
massData.mass = 0;
massData.I = 0;
userData = null;
position.Set(0, 0);
angle = 0;
linearDamping = 0;
angularDamping = 0;
allowSleep = true;
isSleeping = false;
fixedRotation = false;
isBullet = false;
}
}
}//package Box2D.Dynamics
Section 66
//b2BoundaryListener (Box2D.Dynamics.b2BoundaryListener)
package Box2D.Dynamics {
public class b2BoundaryListener {
public function b2BoundaryListener(){
super();
}
public function Violation(body:b2Body):void{
}
}
}//package Box2D.Dynamics
Section 67
//b2ContactFilter (Box2D.Dynamics.b2ContactFilter)
package Box2D.Dynamics {
import Box2D.Collision.Shapes.*;
public class b2ContactFilter {
public static var b2_defaultFilter:b2ContactFilter = new (b2ContactFilter);
;
public function b2ContactFilter(){
super();
}
public function ShouldCollide(shape1:b2Shape, shape2:b2Shape):Boolean{
var filter1:b2FilterData = shape1.GetFilterData();
var filter2:b2FilterData = shape2.GetFilterData();
if ((((filter1.groupIndex == filter2.groupIndex)) && (!((filter1.groupIndex == 0))))){
return ((filter1.groupIndex > 0));
};
var collide:Boolean = ((!(((filter1.maskBits & filter2.categoryBits) == 0))) && (!(((filter1.categoryBits & filter2.maskBits) == 0))));
return (collide);
}
}
}//package Box2D.Dynamics
Section 68
//b2ContactListener (Box2D.Dynamics.b2ContactListener)
package Box2D.Dynamics {
import Box2D.Collision.*;
import Box2D.Dynamics.Contacts.*;
public class b2ContactListener {
public function b2ContactListener(){
super();
}
public function Add(point:b2ContactPoint):void{
}
public function Remove(point:b2ContactPoint):void{
}
public function Persist(point:b2ContactPoint):void{
}
public function Result(point:b2ContactResult):void{
if (point.normalImpulse > 20){
Main.hitSound();
};
}
}
}//package Box2D.Dynamics
Section 69
//b2ContactManager (Box2D.Dynamics.b2ContactManager)
package Box2D.Dynamics {
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
public class b2ContactManager extends b2PairCallback {
public var m_world:b2World;
public var m_destroyImmediate:Boolean;
public var m_nullContact:b2NullContact;
private static const s_evalCP:b2ContactPoint = new b2ContactPoint();
public function b2ContactManager(){
m_nullContact = new b2NullContact();
super();
m_world = null;
m_destroyImmediate = false;
}
override public function PairRemoved(proxyUserData1, proxyUserData2, pairUserData):void{
if (pairUserData == null){
return;
};
var c:b2Contact = (pairUserData as b2Contact);
if (c == m_nullContact){
return;
};
Destroy(c);
}
public function Destroy(c:b2Contact):void{
var b1:b2Body;
var b2:b2Body;
var manifolds:Array;
var cp:b2ContactPoint;
var i:int;
var manifold:b2Manifold;
var j:int;
var mp:b2ManifoldPoint;
var v1:b2Vec2;
var v2:b2Vec2;
var shape1:b2Shape = c.m_shape1;
var shape2:b2Shape = c.m_shape2;
var manifoldCount:int = c.m_manifoldCount;
if ((((manifoldCount > 0)) && (m_world.m_contactListener))){
b1 = shape1.m_body;
b2 = shape2.m_body;
manifolds = c.GetManifolds();
cp = s_evalCP;
cp.shape1 = c.m_shape1;
cp.shape2 = c.m_shape1;
cp.friction = c.m_friction;
cp.restitution = c.m_restitution;
i = 0;
while (i < manifoldCount) {
manifold = manifolds[i];
cp.normal.SetV(manifold.normal);
j = 0;
while (j < manifold.pointCount) {
mp = manifold.points[j];
cp.position = b1.GetWorldPoint(mp.localPoint1);
v1 = b1.GetLinearVelocityFromLocalPoint(mp.localPoint1);
v2 = b2.GetLinearVelocityFromLocalPoint(mp.localPoint2);
cp.velocity.Set((v2.x - v1.x), (v2.y - v1.y));
cp.separation = mp.separation;
cp.id.key = mp.id._key;
m_world.m_contactListener.Remove(cp);
j++;
};
i++;
};
};
if (c.m_prev){
c.m_prev.m_next = c.m_next;
};
if (c.m_next){
c.m_next.m_prev = c.m_prev;
};
if (c == m_world.m_contactList){
m_world.m_contactList = c.m_next;
};
var body1:b2Body = shape1.m_body;
var body2:b2Body = shape2.m_body;
if (c.m_node1.prev){
c.m_node1.prev.next = c.m_node1.next;
};
if (c.m_node1.next){
c.m_node1.next.prev = c.m_node1.prev;
};
if (c.m_node1 == body1.m_contactList){
body1.m_contactList = c.m_node1.next;
};
if (c.m_node2.prev){
c.m_node2.prev.next = c.m_node2.next;
};
if (c.m_node2.next){
c.m_node2.next.prev = c.m_node2.prev;
};
if (c.m_node2 == body2.m_contactList){
body2.m_contactList = c.m_node2.next;
};
b2Contact.Destroy(c, m_world.m_blockAllocator);
m_world.m_contactCount--;
}
override public function PairAdded(proxyUserData1, proxyUserData2){
var shape1:b2Shape = (proxyUserData1 as b2Shape);
var shape2:b2Shape = (proxyUserData2 as b2Shape);
var body1:b2Body = shape1.m_body;
var body2:b2Body = shape2.m_body;
if (((body1.IsStatic()) && (body2.IsStatic()))){
return (m_nullContact);
};
if (shape1.m_body == shape2.m_body){
return (m_nullContact);
};
if (body2.IsConnected(body1)){
return (m_nullContact);
};
if (((!((m_world.m_contactFilter == null))) && ((m_world.m_contactFilter.ShouldCollide(shape1, shape2) == false)))){
return (m_nullContact);
};
var c:b2Contact = b2Contact.Create(shape1, shape2, m_world.m_blockAllocator);
if (c == null){
return (m_nullContact);
};
shape1 = c.m_shape1;
shape2 = c.m_shape2;
body1 = shape1.m_body;
body2 = shape2.m_body;
c.m_prev = null;
c.m_next = m_world.m_contactList;
if (m_world.m_contactList != null){
m_world.m_contactList.m_prev = c;
};
m_world.m_contactList = c;
c.m_node1.contact = c;
c.m_node1.other = body2;
c.m_node1.prev = null;
c.m_node1.next = body1.m_contactList;
if (body1.m_contactList != null){
body1.m_contactList.prev = c.m_node1;
};
body1.m_contactList = c.m_node1;
c.m_node2.contact = c;
c.m_node2.other = body1;
c.m_node2.prev = null;
c.m_node2.next = body2.m_contactList;
if (body2.m_contactList != null){
body2.m_contactList.prev = c.m_node2;
};
body2.m_contactList = c.m_node2;
m_world.m_contactCount++;
return (c);
}
public function Collide():void{
var body1:b2Body;
var body2:b2Body;
var c:b2Contact = m_world.m_contactList;
while (c) {
body1 = c.m_shape1.m_body;
body2 = c.m_shape2.m_body;
if (((body1.IsSleeping()) && (body2.IsSleeping()))){
} else {
c.Update(m_world.m_contactListener);
};
c = c.m_next;
};
}
}
}//package Box2D.Dynamics
Section 70
//b2DebugDraw (Box2D.Dynamics.b2DebugDraw)
package Box2D.Dynamics {
import flash.display.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
public class b2DebugDraw {
public var m_xformScale:Number;// = 1
public var m_fillAlpha:Number;// = 1
public var m_alpha:Number;// = 1
public var m_drawFlags:uint;
public var m_lineThickness:Number;// = 1
public var m_drawScale:Number;// = 1
public var m_sprite:Sprite;
public static var e_coreShapeBit:uint = 4;
public static var e_shapeBit:uint = 1;
public static var e_centerOfMassBit:uint = 64;
public static var e_aabbBit:uint = 8;
public static var e_obbBit:uint = 16;
public static var e_pairBit:uint = 32;
public static var e_jointBit:uint = 2;
public function b2DebugDraw(){
super();
m_drawFlags = 0;
}
public function ClearFlags(flags:uint):void{
m_drawFlags = (m_drawFlags & ~(flags));
}
public function SetFlags(flags:uint):void{
m_drawFlags = flags;
}
public function AppendFlags(flags:uint):void{
m_drawFlags = (m_drawFlags | flags);
}
public function DrawSegment(p1:b2Vec2, p2:b2Vec2, color:b2Color):void{
m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha);
m_sprite.graphics.moveTo((p1.x * m_drawScale), (p1.y * m_drawScale));
m_sprite.graphics.lineTo((p2.x * m_drawScale), (p2.y * m_drawScale));
}
public function DrawSolidPolygon(vertices:Array, vertexCount:int, color:b2Color):void{
m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha);
m_sprite.graphics.moveTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale));
m_sprite.graphics.beginFill(color.color, m_fillAlpha);
var i = 1;
while (i < vertexCount) {
m_sprite.graphics.lineTo((vertices[i].x * m_drawScale), (vertices[i].y * m_drawScale));
i++;
};
m_sprite.graphics.lineTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale));
m_sprite.graphics.endFill();
}
public function DrawCircle(center:b2Vec2, radius:Number, color:b2Color):void{
m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha);
m_sprite.graphics.drawCircle((center.x * m_drawScale), (center.y * m_drawScale), (radius * m_drawScale));
}
public function DrawPolygon(vertices:Array, vertexCount:int, color:b2Color):void{
m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha);
m_sprite.graphics.moveTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale));
var i = 1;
while (i < vertexCount) {
m_sprite.graphics.lineTo((vertices[i].x * m_drawScale), (vertices[i].y * m_drawScale));
i++;
};
m_sprite.graphics.lineTo((vertices[0].x * m_drawScale), (vertices[0].y * m_drawScale));
}
public function DrawSolidCircle(center:b2Vec2, radius:Number, axis:b2Vec2, color:b2Color):void{
m_sprite.graphics.lineStyle(m_lineThickness, color.color, m_alpha);
m_sprite.graphics.moveTo(0, 0);
m_sprite.graphics.beginFill(color.color, m_fillAlpha);
m_sprite.graphics.drawCircle((center.x * m_drawScale), (center.y * m_drawScale), (radius * m_drawScale));
m_sprite.graphics.endFill();
m_sprite.graphics.moveTo((center.x * m_drawScale), (center.y * m_drawScale));
m_sprite.graphics.lineTo(((center.x + (axis.x * radius)) * m_drawScale), ((center.y + (axis.y * radius)) * m_drawScale));
}
public function GetFlags():uint{
return (m_drawFlags);
}
public function DrawXForm(xf:b2XForm):void{
m_sprite.graphics.lineStyle(m_lineThickness, 0xFF0000, m_alpha);
m_sprite.graphics.moveTo((xf.position.x * m_drawScale), (xf.position.y * m_drawScale));
m_sprite.graphics.lineTo(((xf.position.x + (m_xformScale * xf.R.col1.x)) * m_drawScale), ((xf.position.y + (m_xformScale * xf.R.col1.y)) * m_drawScale));
m_sprite.graphics.lineStyle(m_lineThickness, 0xFF00, m_alpha);
m_sprite.graphics.moveTo((xf.position.x * m_drawScale), (xf.position.y * m_drawScale));
m_sprite.graphics.lineTo(((xf.position.x + (m_xformScale * xf.R.col2.x)) * m_drawScale), ((xf.position.y + (m_xformScale * xf.R.col2.y)) * m_drawScale));
}
}
}//package Box2D.Dynamics
Section 71
//b2DestructionListener (Box2D.Dynamics.b2DestructionListener)
package Box2D.Dynamics {
import Box2D.Dynamics.Joints.*;
import Box2D.Collision.Shapes.*;
public class b2DestructionListener {
public function b2DestructionListener(){
super();
}
public function SayGoodbyeShape(shape:b2Shape):void{
}
public function SayGoodbyeJoint(joint:b2Joint):void{
}
}
}//package Box2D.Dynamics
Section 72
//b2Island (Box2D.Dynamics.b2Island)
package Box2D.Dynamics {
import Box2D.Dynamics.Joints.*;
import Box2D.Common.Math.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
public class b2Island {
public var m_listener:b2ContactListener;
public var m_positionIterationCount:int;
public var m_bodyCapacity:int;
public var m_bodies:Array;
public var m_joints:Array;
public var m_jointCapacity:int;
public var m_contactCount:int;
public var m_contacts:Array;
public var m_contactCapacity:int;
public var m_jointCount:int;
public var m_allocator;
public var m_bodyCount:int;
private static var s_reportCR:b2ContactResult = new b2ContactResult();
public function b2Island(bodyCapacity:int, contactCapacity:int, jointCapacity:int, allocator, listener:b2ContactListener){
var i:int;
super();
m_bodyCapacity = bodyCapacity;
m_contactCapacity = contactCapacity;
m_jointCapacity = jointCapacity;
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
m_allocator = allocator;
m_listener = listener;
m_bodies = new Array(bodyCapacity);
i = 0;
while (i < bodyCapacity) {
m_bodies[i] = null;
i++;
};
m_contacts = new Array(contactCapacity);
i = 0;
while (i < contactCapacity) {
m_contacts[i] = null;
i++;
};
m_joints = new Array(jointCapacity);
i = 0;
while (i < jointCapacity) {
m_joints[i] = null;
i++;
};
m_positionIterationCount = 0;
}
public function AddBody(body:b2Body):void{
var _local2 = m_bodyCount++;
m_bodies[_local2] = body;
}
public function AddJoint(joint:b2Joint):void{
var _local2 = m_jointCount++;
m_joints[_local2] = joint;
}
public function Report(constraints:Array):void{
var tMat:b2Mat22;
var tVec:b2Vec2;
var c:b2Contact;
var cc:b2ContactConstraint;
var cr:b2ContactResult;
var b1:b2Body;
var manifoldCount:int;
var manifolds:Array;
var j:int;
var manifold:b2Manifold;
var k:int;
var point:b2ManifoldPoint;
var ccp:b2ContactConstraintPoint;
if (m_listener == null){
return;
};
var i:int;
while (i < m_contactCount) {
c = m_contacts[i];
cc = constraints[i];
cr = s_reportCR;
cr.shape1 = c.m_shape1;
cr.shape2 = c.m_shape2;
b1 = cr.shape1.m_body;
manifoldCount = c.m_manifoldCount;
manifolds = c.GetManifolds();
j = 0;
while (j < manifoldCount) {
manifold = manifolds[j];
cr.normal.SetV(manifold.normal);
k = 0;
while (k < manifold.pointCount) {
point = manifold.points[k];
ccp = cc.points[k];
cr.position = b1.GetWorldPoint(point.localPoint1);
cr.normalImpulse = ccp.normalImpulse;
cr.tangentImpulse = ccp.tangentImpulse;
cr.id.key = point.id.key;
m_listener.Result(cr);
k++;
};
j++;
};
i++;
};
}
public function AddContact(contact:b2Contact):void{
var _local2 = m_contactCount++;
m_contacts[_local2] = contact;
}
public function Solve(step:b2TimeStep, gravity:b2Vec2, correctPositions:Boolean, allowSleep:Boolean):void{
var i:int;
var b:b2Body;
var joint:b2Joint;
var j:int;
var contactsOkay:Boolean;
var jointsOkay:Boolean;
var jointOkay:Boolean;
var minSleepTime:Number;
var linTolSqr:Number;
var angTolSqr:Number;
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.IsStatic()){
} else {
b.m_linearVelocity.x = (b.m_linearVelocity.x + (step.dt * (gravity.x + (b.m_invMass * b.m_force.x))));
b.m_linearVelocity.y = (b.m_linearVelocity.y + (step.dt * (gravity.y + (b.m_invMass * b.m_force.y))));
b.m_angularVelocity = (b.m_angularVelocity + ((step.dt * b.m_invI) * b.m_torque));
b.m_force.SetZero();
b.m_torque = 0;
b.m_linearVelocity.Multiply(b2Math.b2Clamp((1 - (step.dt * b.m_linearDamping)), 0, 1));
b.m_angularVelocity = (b.m_angularVelocity * b2Math.b2Clamp((1 - (step.dt * b.m_angularDamping)), 0, 1));
if (b.m_linearVelocity.LengthSquared() > b2Settings.b2_maxLinearVelocitySquared){
b.m_linearVelocity.Normalize();
b.m_linearVelocity.x = (b.m_linearVelocity.x * b2Settings.b2_maxLinearVelocity);
b.m_linearVelocity.y = (b.m_linearVelocity.y * b2Settings.b2_maxLinearVelocity);
};
if ((b.m_angularVelocity * b.m_angularVelocity) > b2Settings.b2_maxAngularVelocitySquared){
if (b.m_angularVelocity < 0){
b.m_angularVelocity = -(b2Settings.b2_maxAngularVelocity);
} else {
b.m_angularVelocity = b2Settings.b2_maxAngularVelocity;
};
};
};
i++;
};
var contactSolver:b2ContactSolver = new b2ContactSolver(step, m_contacts, m_contactCount, m_allocator);
contactSolver.InitVelocityConstraints(step);
i = 0;
while (i < m_jointCount) {
joint = m_joints[i];
joint.InitVelocityConstraints(step);
i++;
};
i = 0;
while (i < step.maxIterations) {
contactSolver.SolveVelocityConstraints();
j = 0;
while (j < m_jointCount) {
joint = m_joints[j];
joint.SolveVelocityConstraints(step);
j++;
};
i++;
};
contactSolver.FinalizeVelocityConstraints();
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.IsStatic()){
} else {
b.m_sweep.c0.SetV(b.m_sweep.c);
b.m_sweep.a0 = b.m_sweep.a;
b.m_sweep.c.x = (b.m_sweep.c.x + (step.dt * b.m_linearVelocity.x));
b.m_sweep.c.y = (b.m_sweep.c.y + (step.dt * b.m_linearVelocity.y));
b.m_sweep.a = (b.m_sweep.a + (step.dt * b.m_angularVelocity));
b.SynchronizeTransform();
};
i++;
};
if (correctPositions){
i = 0;
while (i < m_jointCount) {
joint = m_joints[i];
joint.InitPositionConstraints();
i++;
};
m_positionIterationCount = 0;
while (m_positionIterationCount < step.maxIterations) {
contactsOkay = contactSolver.SolvePositionConstraints(b2Settings.b2_contactBaumgarte);
jointsOkay = true;
i = 0;
while (i < m_jointCount) {
joint = m_joints[i];
jointOkay = joint.SolvePositionConstraints();
jointsOkay = ((jointsOkay) && (jointOkay));
i++;
};
if (((contactsOkay) && (jointsOkay))){
break;
};
m_positionIterationCount++;
};
};
Report(contactSolver.m_constraints);
if (allowSleep){
minSleepTime = Number.MAX_VALUE;
linTolSqr = (b2Settings.b2_linearSleepTolerance * b2Settings.b2_linearSleepTolerance);
angTolSqr = (b2Settings.b2_angularSleepTolerance * b2Settings.b2_angularSleepTolerance);
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.m_invMass == 0){
} else {
if ((b.m_flags & b2Body.e_allowSleepFlag) == 0){
b.m_sleepTime = 0;
minSleepTime = 0;
};
if (((((((b.m_flags & b2Body.e_allowSleepFlag) == 0)) || (((b.m_angularVelocity * b.m_angularVelocity) > angTolSqr)))) || ((b2Math.b2Dot(b.m_linearVelocity, b.m_linearVelocity) > linTolSqr)))){
b.m_sleepTime = 0;
minSleepTime = 0;
} else {
b.m_sleepTime = (b.m_sleepTime + step.dt);
minSleepTime = b2Math.b2Min(minSleepTime, b.m_sleepTime);
};
};
i++;
};
if (minSleepTime >= b2Settings.b2_timeToSleep){
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
b.m_flags = (b.m_flags | b2Body.e_sleepFlag);
b.m_linearVelocity.SetZero();
b.m_angularVelocity = 0;
i++;
};
};
};
}
public function Clear():void{
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
}
public function SolveTOI(subStep:b2TimeStep):void{
var i:int;
var b:b2Body;
var contactsOkay:Boolean;
var contactSolver:b2ContactSolver = new b2ContactSolver(subStep, m_contacts, m_contactCount, m_allocator);
i = 0;
while (i < subStep.maxIterations) {
contactSolver.SolveVelocityConstraints();
i++;
};
i = 0;
while (i < m_bodyCount) {
b = m_bodies[i];
if (b.IsStatic()){
} else {
b.m_sweep.c0.SetV(b.m_sweep.c);
b.m_sweep.a0 = b.m_sweep.a;
b.m_sweep.c.x = (b.m_sweep.c.x + (subStep.dt * b.m_linearVelocity.x));
b.m_sweep.c.y = (b.m_sweep.c.y + (subStep.dt * b.m_linearVelocity.y));
b.m_sweep.a = (b.m_sweep.a + (subStep.dt * b.m_angularVelocity));
b.SynchronizeTransform();
};
i++;
};
var k_toiBaumgarte:Number = 0.75;
i = 0;
while (i < subStep.maxIterations) {
contactsOkay = contactSolver.SolvePositionConstraints(k_toiBaumgarte);
if (contactsOkay){
break;
};
i++;
};
Report(contactSolver.m_constraints);
}
}
}//package Box2D.Dynamics
Section 73
//b2TimeStep (Box2D.Dynamics.b2TimeStep)
package Box2D.Dynamics {
public class b2TimeStep {
public var warmStarting:Boolean;
public var positionCorrection:Boolean;
public var dt:Number;
public var maxIterations:int;
public var dtRatio:Number;
public var inv_dt:Number;
public function b2TimeStep(){
super();
}
}
}//package Box2D.Dynamics
Section 74
//b2World (Box2D.Dynamics.b2World)
package Box2D.Dynamics {
import Box2D.Dynamics.Joints.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import Box2D.Dynamics.Contacts.*;
import Box2D.Common.*;
public class b2World {
public var m_inv_dt0:Number;
public var m_boundaryListener:b2BoundaryListener;
public var m_contactList:b2Contact;
public var m_blockAllocator;
public var m_contactListener:b2ContactListener;
public var m_allowSleep:Boolean;
public var m_broadPhase:b2BroadPhase;
public var m_destructionListener:b2DestructionListener;
public var m_jointCount:int;
public var m_bodyCount:int;
public var m_lock:Boolean;
public var m_positionIterationCount:int;
public var m_groundBody:b2Body;
public var m_contactCount:int;
public var m_debugDraw:b2DebugDraw;
public var m_contactFilter:b2ContactFilter;
public var m_bodyList:b2Body;
public var m_stackAllocator;
public var m_jointList:b2Joint;
public var m_gravity:b2Vec2;
public var m_contactManager:b2ContactManager;
private static var s_jointColor:b2Color = new b2Color(0.5, 0.8, 0.8);
public static var m_continuousPhysics:Boolean;
public static var m_warmStarting:Boolean;
private static var s_coreColor:b2Color = new b2Color(0.9, 0.6, 0.6);
public static var m_positionCorrection:Boolean;
private static var s_xf:b2XForm = new b2XForm();
public function b2World(worldAABB:b2AABB, gravity:b2Vec2, doSleep:Boolean){
m_contactManager = new b2ContactManager();
super();
m_destructionListener = null;
m_boundaryListener = null;
m_contactFilter = b2ContactFilter.b2_defaultFilter;
m_contactListener = null;
m_debugDraw = null;
m_bodyList = null;
m_contactList = null;
m_jointList = null;
m_bodyCount = 0;
m_contactCount = 0;
m_jointCount = 0;
m_positionCorrection = true;
m_warmStarting = true;
m_continuousPhysics = true;
m_allowSleep = doSleep;
m_gravity = gravity;
m_lock = false;
m_inv_dt0 = 0;
m_contactManager.m_world = this;
m_broadPhase = new b2BroadPhase(worldAABB, m_contactManager);
var bd:b2BodyDef = new b2BodyDef();
m_groundBody = CreateBody(bd);
}
public function DrawJoint(joint:b2Joint):void{
var pulley:b2PulleyJoint;
var s1:b2Vec2;
var s2:b2Vec2;
var b1:b2Body = joint.m_body1;
var b2:b2Body = joint.m_body2;
var xf1:b2XForm = b1.m_xf;
var xf2:b2XForm = b2.m_xf;
var x1:b2Vec2 = xf1.position;
var x2:b2Vec2 = xf2.position;
var p1:b2Vec2 = joint.GetAnchor1();
var p2:b2Vec2 = joint.GetAnchor2();
var color:b2Color = s_jointColor;
switch (joint.m_type){
case b2Joint.e_distanceJoint:
m_debugDraw.DrawSegment(p1, p2, color);
break;
case b2Joint.e_pulleyJoint:
pulley = (joint as b2PulleyJoint);
s1 = pulley.GetGroundAnchor1();
s2 = pulley.GetGroundAnchor2();
m_debugDraw.DrawSegment(s1, p1, color);
m_debugDraw.DrawSegment(s2, p2, color);
m_debugDraw.DrawSegment(s1, s2, color);
break;
case b2Joint.e_mouseJoint:
m_debugDraw.DrawSegment(p1, p2, color);
break;
default:
if (b1 != m_groundBody){
m_debugDraw.DrawSegment(x1, p1, color);
};
m_debugDraw.DrawSegment(p1, p2, color);
if (b2 != m_groundBody){
m_debugDraw.DrawSegment(x2, p2, color);
};
};
}
public function Refilter(shape:b2Shape):void{
shape.RefilterProxy(m_broadPhase, shape.m_body.m_xf);
}
public function SetDebugDraw(debugDraw:b2DebugDraw):void{
m_debugDraw = debugDraw;
}
public function SetContinuousPhysics(flag:Boolean):void{
m_continuousPhysics = flag;
}
public function GetProxyCount():int{
return (m_broadPhase.m_proxyCount);
}
public function DrawDebugData():void{
var i:int;
var b:b2Body;
var s:b2Shape;
var j:b2Joint;
var bp:b2BroadPhase;
var xf:b2XForm;
var core:Boolean;
var index:uint;
var pair:b2Pair;
var p1:b2Proxy;
var p2:b2Proxy;
var worldLower:b2Vec2;
var worldUpper:b2Vec2;
var p:b2Proxy;
var poly:b2PolygonShape;
var obb:b2OBB;
var h:b2Vec2;
var tMat:b2Mat22;
var tVec:b2Vec2;
var tX:Number;
if (m_debugDraw == null){
return;
};
m_debugDraw.m_sprite.graphics.clear();
var flags:uint = m_debugDraw.GetFlags();
var invQ:b2Vec2 = new b2Vec2();
var x1:b2Vec2 = new b2Vec2();
var x2:b2Vec2 = new b2Vec2();
var color:b2Color = new b2Color(0, 0, 0);
var b1:b2AABB = new b2AABB();
var b2:b2AABB = new b2AABB();
var vs:Array = [new b2Vec2(), new b2Vec2(), new b2Vec2(), new b2Vec2()];
if ((flags & b2DebugDraw.e_shapeBit)){
core = ((flags & b2DebugDraw.e_coreShapeBit) == b2DebugDraw.e_coreShapeBit);
b = m_bodyList;
while (b) {
xf = b.m_xf;
s = b.GetShapeList();
while (s) {
if (b.IsStatic()){
DrawShape(s, xf, new b2Color(0.5, 0.9, 0.5), core);
} else {
if (b.IsSleeping()){
DrawShape(s, xf, new b2Color(0.5, 0.5, 0.9), core);
} else {
DrawShape(s, xf, new b2Color(0.9, 0.9, 0.9), core);
};
};
s = s.m_next;
};
b = b.m_next;
};
};
if ((flags & b2DebugDraw.e_jointBit)){
j = m_jointList;
while (j) {
DrawJoint(j);
j = j.m_next;
};
};
if ((flags & b2DebugDraw.e_pairBit)){
bp = m_broadPhase;
invQ.Set((1 / bp.m_quantizationFactor.x), (1 / bp.m_quantizationFactor.y));
color.Set(0.9, 0.9, 0.3);
i = 0;
while (i < b2Pair.b2_tableCapacity) {
index = bp.m_pairManager.m_hashTable[i];
while (index != b2Pair.b2_nullPair) {
pair = bp.m_pairManager.m_pairs[index];
p1 = bp.m_proxyPool[pair.proxyId1];
p2 = bp.m_proxyPool[pair.proxyId2];
b1.lowerBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p1.lowerBounds[0]].value));
b1.lowerBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p1.lowerBounds[1]].value));
b1.upperBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p1.upperBounds[0]].value));
b1.upperBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p1.upperBounds[1]].value));
b2.lowerBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p2.lowerBounds[0]].value));
b2.lowerBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p2.lowerBounds[1]].value));
b2.upperBound.x = (bp.m_worldAABB.lowerBound.x + (invQ.x * bp.m_bounds[0][p2.upperBounds[0]].value));
b2.upperBound.y = (bp.m_worldAABB.lowerBound.y + (invQ.y * bp.m_bounds[1][p2.upperBounds[1]].value));
x1.x = (0.5 * (b1.lowerBound.x + b1.upperBound.x));
x1.y = (0.5 * (b1.lowerBound.y + b1.upperBound.y));
x2.x = (0.5 * (b2.lowerBound.x + b2.upperBound.x));
x2.y = (0.5 * (b2.lowerBound.y + b2.upperBound.y));
m_debugDraw.DrawSegment(x1, x2, color);
index = pair.next;
};
i++;
};
};
if ((flags & b2DebugDraw.e_aabbBit)){
bp = m_broadPhase;
worldLower = bp.m_worldAABB.lowerBound;
worldUpper = bp.m_worldAABB.upperBound;
invQ.Set((1 / bp.m_quantizationFactor.x), (1 / bp.m_quantizationFactor.y));
color.Set(0.9, 0.3, 0.9);
i = 0;
while (i < b2Settings.b2_maxProxies) {
p = bp.m_proxyPool[i];
if (p.IsValid() == false){
} else {
b1.lowerBound.x = (worldLower.x + (invQ.x * bp.m_bounds[0][p.lowerBounds[0]].value));
b1.lowerBound.y = (worldLower.y + (invQ.y * bp.m_bounds[1][p.lowerBounds[1]].value));
b1.upperBound.x = (worldLower.x + (invQ.x * bp.m_bounds[0][p.upperBounds[0]].value));
b1.upperBound.y = (worldLower.y + (invQ.y * bp.m_bounds[1][p.upperBounds[1]].value));
vs[0].Set(b1.lowerBound.x, b1.lowerBound.y);
vs[1].Set(b1.upperBound.x, b1.lowerBound.y);
vs[2].Set(b1.upperBound.x, b1.upperBound.y);
vs[3].Set(b1.lowerBound.x, b1.upperBound.y);
m_debugDraw.DrawPolygon(vs, 4, color);
};
i++;
};
vs[0].Set(worldLower.x, worldLower.y);
vs[1].Set(worldUpper.x, worldLower.y);
vs[2].Set(worldUpper.x, worldUpper.y);
vs[3].Set(worldLower.x, worldUpper.y);
m_debugDraw.DrawPolygon(vs, 4, new b2Color(0.3, 0.9, 0.9));
};
if ((flags & b2DebugDraw.e_obbBit)){
color.Set(0.5, 0.3, 0.5);
b = m_bodyList;
while (b) {
xf = b.m_xf;
s = b.GetShapeList();
while (s) {
if (s.m_type != b2Shape.e_polygonShape){
} else {
poly = (s as b2PolygonShape);
obb = poly.GetOBB();
h = obb.extents;
vs[0].Set(-(h.x), -(h.y));
vs[1].Set(h.x, -(h.y));
vs[2].Set(h.x, h.y);
vs[3].Set(-(h.x), h.y);
i = 0;
while (i < 4) {
tMat = obb.R;
tVec = vs[i];
tX = (obb.center.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
vs[i].y = (obb.center.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
vs[i].x = tX;
tMat = xf.R;
tX = (xf.position.x + ((tMat.col1.x * tVec.x) + (tMat.col2.x * tVec.y)));
vs[i].y = (xf.position.y + ((tMat.col1.y * tVec.x) + (tMat.col2.y * tVec.y)));
vs[i].x = tX;
i++;
};
m_debugDraw.DrawPolygon(vs, 4, color);
};
s = s.m_next;
};
b = b.m_next;
};
};
if ((flags & b2DebugDraw.e_centerOfMassBit)){
b = m_bodyList;
while (b) {
xf = s_xf;
xf.R = b.m_xf.R;
xf.position = b.GetWorldCenter();
m_debugDraw.DrawXForm(xf);
b = b.m_next;
};
};
}
public function DestroyBody(b:b2Body):void{
var jn0:b2JointEdge;
var s0:b2Shape;
if (m_lock == true){
return;
};
var jn:b2JointEdge = b.m_jointList;
while (jn) {
jn0 = jn;
jn = jn.next;
if (m_destructionListener){
m_destructionListener.SayGoodbyeJoint(jn0.joint);
};
DestroyJoint(jn0.joint);
};
var s:b2Shape = b.m_shapeList;
while (s) {
s0 = s;
s = s.m_next;
if (m_destructionListener){
m_destructionListener.SayGoodbyeShape(s0);
};
s0.DestroyProxy(m_broadPhase);
b2Shape.Destroy(s0, m_blockAllocator);
};
if (b.m_prev){
b.m_prev.m_next = b.m_next;
};
if (b.m_next){
b.m_next.m_prev = b.m_prev;
};
if (b == m_bodyList){
m_bodyList = b.m_next;
};
m_bodyCount--;
}
public function SetContactFilter(filter:b2ContactFilter):void{
m_contactFilter = filter;
}
public function GetGroundBody():b2Body{
return (m_groundBody);
}
public function DrawShape(shape:b2Shape, xf:b2XForm, color:b2Color, core:Boolean):void{
var circle:b2CircleShape;
var center:b2Vec2;
var radius:Number;
var axis:b2Vec2;
var i:int;
var poly:b2PolygonShape;
var vertexCount:int;
var localVertices:Array;
var vertices:Array;
var localCoreVertices:Array;
var coreColor:b2Color = s_coreColor;
switch (shape.m_type){
case b2Shape.e_circleShape:
circle = (shape as b2CircleShape);
center = b2Math.b2MulX(xf, circle.m_localPosition);
radius = circle.m_radius;
axis = xf.R.col1;
m_debugDraw.DrawSolidCircle(center, radius, axis, color);
if (core){
m_debugDraw.DrawCircle(center, (radius - b2Settings.b2_toiSlop), coreColor);
};
break;
case b2Shape.e_polygonShape:
poly = (shape as b2PolygonShape);
vertexCount = poly.GetVertexCount();
localVertices = poly.GetVertices();
vertices = new Array(b2Settings.b2_maxPolygonVertices);
i = 0;
while (i < vertexCount) {
vertices[i] = b2Math.b2MulX(xf, localVertices[i]);
i++;
};
m_debugDraw.DrawSolidPolygon(vertices, vertexCount, color);
if (core){
localCoreVertices = poly.GetCoreVertices();
i = 0;
while (i < vertexCount) {
vertices[i] = b2Math.b2MulX(xf, localCoreVertices[i]);
i++;
};
m_debugDraw.DrawPolygon(vertices, vertexCount, coreColor);
};
break;
};
}
public function GetContactCount():int{
return (m_contactCount);
}
public function Solve(step:b2TimeStep):void{
var b:b2Body;
var stackCount:int;
var i:int;
var other:b2Body;
var cn:b2ContactEdge;
var jn:b2JointEdge;
var inRange:Boolean;
m_positionIterationCount = 0;
var island:b2Island = new b2Island(m_bodyCount, m_contactCount, m_jointCount, m_stackAllocator, m_contactListener);
b = m_bodyList;
while (b) {
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
b = b.m_next;
};
var c:b2Contact = m_contactList;
while (c) {
c.m_flags = (c.m_flags & ~(b2Contact.e_islandFlag));
c = c.m_next;
};
var j:b2Joint = m_jointList;
while (j) {
j.m_islandFlag = false;
j = j.m_next;
};
var stackSize:int = m_bodyCount;
var stack:Array = new Array(stackSize);
var seed:b2Body = m_bodyList;
while (seed) {
if ((seed.m_flags & ((b2Body.e_islandFlag | b2Body.e_sleepFlag) | b2Body.e_frozenFlag))){
} else {
if (seed.IsStatic()){
} else {
island.Clear();
stackCount = 0;
var _temp1 = stackCount;
stackCount = (stackCount + 1);
var _local15 = _temp1;
stack[_local15] = seed;
seed.m_flags = (seed.m_flags | b2Body.e_islandFlag);
while (stackCount > 0) {
--stackCount;
b = stack[stackCount];
island.AddBody(b);
b.m_flags = (b.m_flags & ~(b2Body.e_sleepFlag));
if (b.IsStatic()){
} else {
cn = b.m_contactList;
while (cn) {
if ((cn.contact.m_flags & (b2Contact.e_islandFlag | b2Contact.e_nonSolidFlag))){
} else {
if (cn.contact.m_manifoldCount == 0){
} else {
island.AddContact(cn.contact);
cn.contact.m_flags = (cn.contact.m_flags | b2Contact.e_islandFlag);
other = cn.other;
if ((other.m_flags & b2Body.e_islandFlag)){
} else {
var _temp2 = stackCount;
stackCount = (stackCount + 1);
var _local16 = _temp2;
stack[_local16] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
};
cn = cn.next;
};
jn = b.m_jointList;
while (jn) {
if (jn.joint.m_islandFlag == true){
} else {
island.AddJoint(jn.joint);
jn.joint.m_islandFlag = true;
other = jn.other;
if ((other.m_flags & b2Body.e_islandFlag)){
} else {
var _temp3 = stackCount;
stackCount = (stackCount + 1);
_local16 = _temp3;
stack[_local16] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
jn = jn.next;
};
};
};
island.Solve(step, m_gravity, m_positionCorrection, m_allowSleep);
if (island.m_positionIterationCount > m_positionIterationCount){
m_positionIterationCount = island.m_positionIterationCount;
};
i = 0;
while (i < island.m_bodyCount) {
b = island.m_bodies[i];
if (b.IsStatic()){
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
};
i++;
};
};
};
seed = seed.m_next;
};
b = m_bodyList;
while (b) {
if ((b.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag))){
} else {
if (b.IsStatic()){
} else {
inRange = b.SynchronizeShapes();
if ((((inRange == false)) && (!((m_boundaryListener == null))))){
m_boundaryListener.Violation(b);
};
};
};
b = b.m_next;
};
m_broadPhase.Commit();
}
public function Query(aabb:b2AABB, shapes:Array, maxCount:int):int{
var results:Array = new Array(maxCount);
var count:int = m_broadPhase.QueryAABB(aabb, results, maxCount);
var i:int;
while (i < count) {
shapes[i] = results[i];
i++;
};
return (count);
}
public function SetGravity(gravity:b2Vec2):void{
m_gravity = gravity;
}
public function SolveTOI(step:b2TimeStep):void{
var b:b2Body;
var s1:b2Shape;
var s2:b2Shape;
var b1:b2Body;
var b2:b2Body;
var cn:b2ContactEdge;
var c:b2Contact;
var minContact:b2Contact;
var minTOI:Number;
var seed:b2Body;
var stackCount:int;
var subStep:b2TimeStep;
var i:int;
var toi:Number;
var t0:Number;
var other:b2Body;
var inRange:Boolean;
var island:b2Island = new b2Island(m_bodyCount, b2Settings.b2_maxTOIContactsPerIsland, 0, m_stackAllocator, m_contactListener);
var stackSize:int = m_bodyCount;
var stack:Array = new Array(stackSize);
b = m_bodyList;
while (b) {
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
b.m_sweep.t0 = 0;
b = b.m_next;
};
c = m_contactList;
while (c) {
c.m_flags = (c.m_flags & ~((b2Contact.e_toiFlag | b2Contact.e_islandFlag)));
c = c.m_next;
};
while (true) {
minContact = null;
minTOI = 1;
c = m_contactList;
for (;c;(c = c.m_next)) {
if ((c.m_flags & (b2Contact.e_slowFlag | b2Contact.e_nonSolidFlag))){
} else {
toi = 1;
if ((c.m_flags & b2Contact.e_toiFlag)){
toi = c.m_toi;
} else {
s1 = c.m_shape1;
s2 = c.m_shape2;
b1 = s1.m_body;
b2 = s2.m_body;
if (((((b1.IsStatic()) || (b1.IsSleeping()))) && (((b2.IsStatic()) || (b2.IsSleeping()))))){
continue;
};
t0 = b1.m_sweep.t0;
if (b1.m_sweep.t0 < b2.m_sweep.t0){
t0 = b2.m_sweep.t0;
b1.m_sweep.Advance(t0);
} else {
if (b2.m_sweep.t0 < b1.m_sweep.t0){
t0 = b1.m_sweep.t0;
b2.m_sweep.Advance(t0);
};
};
toi = b2TimeOfImpact.TimeOfImpact(c.m_shape1, b1.m_sweep, c.m_shape2, b2.m_sweep);
if ((((toi > 0)) && ((toi < 1)))){
toi = (((1 - toi) * t0) + toi);
if (toi > 1){
toi = 1;
};
};
c.m_toi = toi;
c.m_flags = (c.m_flags | b2Contact.e_toiFlag);
};
if ((((Number.MIN_VALUE < toi)) && ((toi < minTOI)))){
minContact = c;
minTOI = toi;
};
};
};
if ((((minContact == null)) || (((1 - (100 * Number.MIN_VALUE)) < minTOI)))){
break;
};
s1 = minContact.m_shape1;
s2 = minContact.m_shape2;
b1 = s1.m_body;
b2 = s2.m_body;
b1.Advance(minTOI);
b2.Advance(minTOI);
minContact.Update(m_contactListener);
minContact.m_flags = (minContact.m_flags & ~(b2Contact.e_toiFlag));
if (minContact.m_manifoldCount == 0){
} else {
seed = b1;
if (seed.IsStatic()){
seed = b2;
};
island.Clear();
stackCount = 0;
var _temp1 = stackCount;
stackCount = (stackCount + 1);
var _local22 = _temp1;
stack[_local22] = seed;
seed.m_flags = (seed.m_flags | b2Body.e_islandFlag);
while (stackCount > 0) {
--stackCount;
b = stack[stackCount];
island.AddBody(b);
b.m_flags = (b.m_flags & ~(b2Body.e_sleepFlag));
if (b.IsStatic()){
} else {
cn = b.m_contactList;
while (cn) {
if (island.m_contactCount == island.m_contactCapacity){
} else {
if ((cn.contact.m_flags & ((b2Contact.e_islandFlag | b2Contact.e_slowFlag) | b2Contact.e_nonSolidFlag))){
} else {
if (cn.contact.m_manifoldCount == 0){
} else {
island.AddContact(cn.contact);
cn.contact.m_flags = (cn.contact.m_flags | b2Contact.e_islandFlag);
other = cn.other;
if ((other.m_flags & b2Body.e_islandFlag)){
} else {
if (other.IsStatic() == false){
other.Advance(minTOI);
other.WakeUp();
};
var _temp2 = stackCount;
stackCount = (stackCount + 1);
var _local23 = _temp2;
stack[_local23] = other;
other.m_flags = (other.m_flags | b2Body.e_islandFlag);
};
};
};
};
cn = cn.next;
};
};
};
subStep = new b2TimeStep();
subStep.dt = ((1 - minTOI) * step.dt);
subStep.inv_dt = (1 / subStep.dt);
subStep.maxIterations = step.maxIterations;
island.SolveTOI(subStep);
i = 0;
while (i < island.m_bodyCount) {
b = island.m_bodies[i];
b.m_flags = (b.m_flags & ~(b2Body.e_islandFlag));
if ((b.m_flags & (b2Body.e_sleepFlag | b2Body.e_frozenFlag))){
} else {
if (b.IsStatic()){
} else {
inRange = b.SynchronizeShapes();
if ((((inRange == false)) && (!((m_boundaryListener == null))))){
m_boundaryListener.Violation(b);
};
cn = b.m_contactList;
while (cn) {
cn.contact.m_flags = (cn.contact.m_flags & ~(b2Contact.e_toiFlag));
cn = cn.next;
};
};
};
i++;
};
i = 0;
while (i < island.m_contactCount) {
c = island.m_contacts[i];
c.m_flags = (c.m_flags & ~((b2Contact.e_toiFlag | b2Contact.e_islandFlag)));
i++;
};
m_broadPhase.Commit();
};
};
}
public function GetJointList():b2Joint{
return (m_jointList);
}
public function GetBodyList():b2Body{
return (m_bodyList);
}
public function GetPairCount():int{
return (m_broadPhase.m_pairManager.m_pairCount);
}
public function Validate():void{
m_broadPhase.Validate();
}
public function SetWarmStarting(flag:Boolean):void{
m_warmStarting = flag;
}
public function SetPositionCorrection(flag:Boolean):void{
m_positionCorrection = flag;
}
public function CreateJoint(def:b2JointDef):b2Joint{
var b:b2Body;
var s:b2Shape;
var j:b2Joint = b2Joint.Create(def, m_blockAllocator);
j.m_prev = null;
j.m_next = m_jointList;
if (m_jointList){
m_jointList.m_prev = j;
};
m_jointList = j;
m_jointCount++;
j.m_node1.joint = j;
j.m_node1.other = j.m_body2;
j.m_node1.prev = null;
j.m_node1.next = j.m_body1.m_jointList;
if (j.m_body1.m_jointList){
j.m_body1.m_jointList.prev = j.m_node1;
};
j.m_body1.m_jointList = j.m_node1;
j.m_node2.joint = j;
j.m_node2.other = j.m_body1;
j.m_node2.prev = null;
j.m_node2.next = j.m_body2.m_jointList;
if (j.m_body2.m_jointList){
j.m_body2.m_jointList.prev = j.m_node2;
};
j.m_body2.m_jointList = j.m_node2;
if (def.collideConnected == false){
b = ((def.body1.m_shapeCount < def.body2.m_shapeCount)) ? def.body1 : def.body2;
s = b.m_shapeList;
while (s) {
s.RefilterProxy(m_broadPhase, b.m_xf);
s = s.m_next;
};
};
return (j);
}
public function DestroyJoint(j:b2Joint):void{
var b:b2Body;
var s:b2Shape;
var collideConnected:Boolean = j.m_collideConnected;
if (j.m_prev){
j.m_prev.m_next = j.m_next;
};
if (j.m_next){
j.m_next.m_prev = j.m_prev;
};
if (j == m_jointList){
m_jointList = j.m_next;
};
var body1:b2Body = j.m_body1;
var body2:b2Body = j.m_body2;
body1.WakeUp();
body2.WakeUp();
if (j.m_node1.prev){
j.m_node1.prev.next = j.m_node1.next;
};
if (j.m_node1.next){
j.m_node1.next.prev = j.m_node1.prev;
};
if (j.m_node1 == body1.m_jointList){
body1.m_jointList = j.m_node1.next;
};
j.m_node1.prev = null;
j.m_node1.next = null;
if (j.m_node2.prev){
j.m_node2.prev.next = j.m_node2.next;
};
if (j.m_node2.next){
j.m_node2.next.prev = j.m_node2.prev;
};
if (j.m_node2 == body2.m_jointList){
body2.m_jointList = j.m_node2.next;
};
j.m_node2.prev = null;
j.m_node2.next = null;
b2Joint.Destroy(j, m_blockAllocator);
m_jointCount--;
if (collideConnected == false){
b = ((body1.m_shapeCount < body2.m_shapeCount)) ? body1 : body2;
s = b.m_shapeList;
while (s) {
s.RefilterProxy(m_broadPhase, b.m_xf);
s = s.m_next;
};
};
}
public function SetContactListener(listener:b2ContactListener):void{
m_contactListener = listener;
}
public function CreateBody(def:b2BodyDef):b2Body{
if (m_lock == true){
return (null);
};
var b:b2Body = new b2Body(def, this);
b.m_prev = null;
b.m_next = m_bodyList;
if (m_bodyList){
m_bodyList.m_prev = b;
};
m_bodyList = b;
m_bodyCount++;
return (b);
}
public function SetBoundaryListener(listener:b2BoundaryListener):void{
m_boundaryListener = listener;
}
public function SetDestructionListener(listener:b2DestructionListener):void{
m_destructionListener = listener;
}
public function Step(dt:Number, iterations:int):void{
m_lock = true;
var step:b2TimeStep = new b2TimeStep();
step.dt = dt;
step.maxIterations = iterations;
if (dt > 0){
step.inv_dt = (1 / dt);
} else {
step.inv_dt = 0;
};
step.dtRatio = (m_inv_dt0 * dt);
step.positionCorrection = m_positionCorrection;
step.warmStarting = m_warmStarting;
m_contactManager.Collide();
if (step.dt > 0){
Solve(step);
};
if (((m_continuousPhysics) && ((step.dt > 0)))){
SolveTOI(step);
};
DrawDebugData();
m_inv_dt0 = step.inv_dt;
m_lock = false;
}
public function GetBodyCount():int{
return (m_bodyCount);
}
public function GetJointCount():int{
return (m_jointCount);
}
}
}//package Box2D.Dynamics
Section 75
//Channel (fmd._ModPlayer.Channel)
package fmd._ModPlayer {
import fmd.flash.*;
public class Channel {
public var note:Array;
public function Channel():void{
super();
if (!Boot.skip_constructor){
};
}
}
}//package fmd._ModPlayer
Section 76
//ChanState (fmd._ModPlayer.ChanState)
package fmd._ModPlayer {
import fmd.flash.*;
public class ChanState {
public var csp:int;
public var cslooplen:int;
public var cutsample:Boolean;
public var tremolopos:int;
public var arpeggiotick:int;
public var cutsampleticks:int;
public var slidevolume:Boolean;
public var rvolume:int;
public var retriggersample:Boolean;
public var csmp:Sample;
public var arpeggiosemi1:int;
public var tremolospeed:int;
public var arpeggiosemi2:int;
public var delaynoteticks:int;
public var vibratowave:int;
public var slideperiodval:int;
public var retriggersamplectr:int;
public var slidevolumeval:int;
public var slideperiod:Boolean;
public var vibratopos:int;
public var cvolume:int;
public var tremolowave:int;
public var retriggersampleticks:int;
public var lastnoteperiod:int;
public var tremolo:Boolean;
public var cslength:int;
public var arpeggionote:int;
public var cperiod:int;
public var cspinc:int;
public var vibratospeed:int;
public var slidetonotetarget:int;
public var vibratodepth:int;
public var delaynote:Boolean;
public var slidetonote:Boolean;
public var tremolodepth:int;
public var vibrato:Boolean;
public var arpeggio:Boolean;
public function ChanState():void{
super();
if (!Boot.skip_constructor){
};
}
}
}//package fmd._ModPlayer
Section 77
//Note (fmd._ModPlayer.Note)
package fmd._ModPlayer {
import fmd.flash.*;
public class Note {
public var peridx:int;
public var period:int;
public var sample:Sample;
public var command:int;
public var cmdarg:int;
public function Note():void{
super();
if (!Boot.skip_constructor){
};
}
}
}//package fmd._ModPlayer
Section 78
//Pattern (fmd._ModPlayer.Pattern)
package fmd._ModPlayer {
import fmd.flash.*;
public class Pattern {
public var channel:Array;
public function Pattern():void{
super();
if (!Boot.skip_constructor){
};
}
}
}//package fmd._ModPlayer
Section 79
//Sample (fmd._ModPlayer.Sample)
package fmd._ModPlayer {
import fmd.flash.*;
public class Sample {
public var fine:int;
public var length:int;
public var looplen:int;
public var wave:Array;
public var volume:int;
public var loopstart:int;
public function Sample():void{
super();
if (!Boot.skip_constructor){
};
}
}
}//package fmd._ModPlayer
Section 80
//Boot (fmd.flash.Boot)
package fmd.flash {
import flash.display.*;
import flash.utils.*;
import flash.text.*;
public dynamic class Boot extends MovieClip {
protected static var lastError:Error;
protected static var tf:TextField;
public static var skip_constructor:Boolean = false;
protected static var lines:Array;
public function Boot(mc:MovieClip=null):void{
var aproto:*;
var cca:*;
var c:MovieClip;
var mc = mc;
if (!Boot.skip_constructor){
super();
aproto = Array.prototype;
aproto.copy = function (){
return (this.slice());
};
aproto.insert = function (i, x):void{
this.splice(i, 0, x);
};
aproto.remove = function (obj):Boolean{
var i:int;
var _g1:int;
var _g:* = this.length;
while (_g1 < _g) {
var _temp1 = _g1;
_g1 = (_g1 + 1);
i = _temp1;
if (this[i] == obj){
this.splice(i, 1);
return (true);
};
};
return (false);
};
aproto.iterator = function (){
var cur:int;
var arr:Array;
cur = 0;
arr = this;
return ({hasNext:function ():Boolean{
return ((cur < arr.length));
}, next:function (){
return (arr[cur++]);
}});
};
aproto.setPropertyIsEnumerable("copy", false);
aproto.setPropertyIsEnumerable("insert", false);
aproto.setPropertyIsEnumerable("remove", false);
aproto.setPropertyIsEnumerable("iterator", false);
cca = String.prototype.charCodeAt;
String.prototype.charCodeAt = function (i){
var x:* = cca.call(this, i);
if (isNaN(x)){
return (null);
};
return (x);
};
Boot.lines = new Array();
c = ((mc == null)) ? this : mc;
Lib.current = c;
if (((!((c.stage == null))) && ((c.stage.align == "")))){
c.stage.align = "TOP_LEFT";
//unresolved jump
};
//unresolved jump
var _slot1 = e;
if (Boot.init != null){
init();
};
};
}
public static function __trace(v, pos):void{
var tf:TextField = getTrace();
var pstr:String = ((pos == null)) ? "(null)" : ((pos.fileName + ":") + pos.lineNumber);
Boot.lines = lines.concat(((pstr + ": ") + __string_rec(v, "")).split("\n"));
tf.text = lines.join("\n");
var stage:Stage = Lib.current.stage;
if (stage == null){
return;
};
while (tf.height > stage.stageHeight) {
lines.shift();
tf.text = lines.join("\n");
};
}
public static function __string_rec(v, str:String):String{
var k:Array;
var s:String;
var first:Boolean;
var _g1:int;
var _g:int;
var i:int;
var key:String;
var s2:String;
var i2:*;
var first2:Boolean;
var _g12:int;
var _g2:*;
var i1:int;
var v = v;
var str = str;
var cname:String = getQualifiedClassName(v);
switch (cname){
case "Object":
k = function ():Array{
var $r:*;
var $k:*;
$r = new Array();
for ($k in v) {
$r.push($k);
};
return ($r);
}();
s = "{";
first = true;
_g1 = 0;
_g = k.length;
while (_g1 < _g) {
_g1 = (_g1 + 1);
i = _g1;
key = k[i];
if (first){
first = false;
} else {
s = (s + ",");
};
s = (s + (((" " + key) + " : ") + __string_rec(v[key], str)));
};
if (!first){
s = (s + " ");
};
s = (s + "}");
return (s);
case "Array":
s2 = "[";
first2 = true;
_g12 = 0;
_g2 = v.length;
while (_g12 < _g2) {
_g12 = (_g12 + 1);
i1 = _g12;
if (first2){
first2 = false;
} else {
s2 = (s2 + ",");
};
s2 = (s2 + __string_rec(v[i1], str));
};
return ((s2 + "]"));
default:
switch (typeof(v)){
case "function":
return ("<function>");
};
break;
};
return (new String(v));
}
public static function __instanceof(v, t):Boolean{
var v = v;
var t = t;
if (t == Object){
return (true);
};
return ((v is t));
//unresolved jump
var _slot1 = e;
return (false);
}
public static function getTrace():TextField{
var format:TextFormat;
var mc:MovieClip = Lib.current;
if (Boot.tf == null){
Boot.tf = new TextField();
format = tf.getTextFormat();
format.font = "_sans";
tf.defaultTextFormat = format;
tf.selectable = false;
tf.width = ((mc.stage == null)) ? 800 : mc.stage.stageWidth;
tf.autoSize = TextFieldAutoSize.LEFT;
tf.mouseEnabled = false;
};
mc.addChild(tf);
return (tf);
}
private static function init():void{
Math["NaN"] = Number.NaN;
Math["NEGATIVE_INFINITY"] = Number.NEGATIVE_INFINITY;
Math["POSITIVE_INFINITY"] = Number.POSITIVE_INFINITY;
Math["isFinite"] = function (i:Number):Boolean{
return (isFinite(i));
};
Math["isNaN"] = function (i:Number):Boolean{
return (isNaN(i));
};
}
public static function __clear_trace():void{
if (Boot.tf == null){
return;
};
Lib.current.removeChild(tf);
Boot.tf = null;
Boot.lines = new Array();
}
protected static function __unprotect__(s:String):String{
return (s);
}
public static function enum_to_string(e):String{
if (e.params == null){
return (e.tag);
};
return ((((e.tag + "(") + e.params.join(",")) + ")"));
}
public static function __set_trace_color(rgb:uint):void{
getTrace().textColor = rgb;
}
}
}//package fmd.flash
Section 81
//Lib (fmd.flash.Lib)
package fmd.flash {
import flash.display.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class Lib {
public static var current:MovieClip;
public function Lib(){
super();
}
public static function trace(arg):void{
trace(arg);
}
public static function fscommand(cmd:String, param:String=null):void{
fscommand(cmd, ((param == null)) ? "" : param);
}
public static function _as(v, c:Class){
return ((v as c));
}
public static function getURL(url:URLRequest, target:String=null):void{
var f:Function = navigateToURL;
if (target == null){
f(url);
} else {
f(url, target);
};
}
public static function eval(path:String){
var p:Array;
var fields:Array;
var f:String;
var path = path;
p = path.split(".");
fields = new Array();
var o:* = null;
for (;p.length > 0;if (o != null){
break;
}) {
o = getDefinitionByName(p.join("."));
continue;
var _slot1 = e;
fields.unshift(p.pop());
};
var _g:int;
while (_g < fields.length) {
f = fields[_g];
_g = (_g + 1);
if (o == null){
return (null);
};
o = o[f];
};
return (o);
}
public static function attach(name:String):MovieClip{
var cl:* = (getDefinitionByName(name) as Class);
return (new (cl));
}
public static function _getTimer():Number{
return (getTimer());
}
}
}//package fmd.flash
Section 82
//Log (fmd.haxe.Log)
package fmd.haxe {
import fmd.flash.*;
public class Log {
public static var setColor:Function = function (rgb:int):void{
Boot.__set_trace_color(rgb);
};
public static var trace:Function = function (v, infos=null):void{
Boot.__trace(v, infos);
};
public static var clear:Function = function ():void{
Boot.__clear_trace();
};
public function Log(){
super();
}
}
}//package fmd.haxe
Section 83
//Timer (fmd.haxe.Timer)
package fmd.haxe {
import flash.utils.*;
import fmd.flash.*;
public class Timer {
protected var id;
public var run:Function;
public function Timer(time_ms:int):void{
var me:Timer;
var time_ms = time_ms;
run = function ():void{
};
super();
if (!Boot.skip_constructor){
me = this;
this.id = setInterval(function ():void{
me.run();
}, time_ms);
};
}
public function stop():void{
if (this.id == null){
return;
};
clearInterval(this.id);
this.id = null;
}
public static function delay(f:Function, time_ms:int):void{
var t:Timer;
var f = f;
var time_ms = time_ms;
t = new Timer(time_ms);
t.run = function ():void{
t.stop();
f();
};
}
public static function stamp():Number{
return ((Lib._getTimer() / 1000));
}
}
}//package fmd.haxe
Section 84
//DynSound (fmd.DynSound)
package fmd {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
public class DynSound {
public function DynSound(){
super();
}
protected static function writeTagInfo(swf:ByteArray, code:int, len:int):void{
if (len >= 63){
swf.writeShort(((code << 6) | 63));
swf.writeInt(len);
} else {
swf.writeShort(((code << 6) | len));
};
}
public static function playSound(wave:ByteArray, repeat:Boolean):Loader{
var swf:ByteArray;
var ldr:Loader;
var wave = wave;
var repeat = repeat;
swf = new ByteArray();
swf.endian = Endian.LITTLE_ENDIAN;
swf.writeByte(70);
swf.writeByte(87);
swf.writeByte(83);
swf.writeByte(7);
swf.writeUnsignedInt(0);
swf.writeByte(120);
swf.writeByte(0);
swf.writeByte(5);
swf.writeByte(95);
swf.writeByte(0);
swf.writeByte(0);
swf.writeByte(15);
swf.writeByte(160);
swf.writeByte(0);
swf.writeByte(0);
swf.writeByte(12);
swf.writeShort(1);
writeTagInfo(swf, 14, (((2 + 1) + 4) + wave.length));
swf.writeShort(1);
swf.writeByte(60);
swf.writeUnsignedInt(wave.length);
swf.writeBytes(wave);
writeTagInfo(swf, 15, (2 + 1));
swf.writeShort(1);
if (repeat){
swf.writeByte(4);
swf.writeShort(0xFFFF);
} else {
swf.writeByte(0);
};
writeTagInfo(swf, 0, 0);
swf.position = 4;
swf.writeUnsignedInt(swf.length);
swf.position = 0;
ldr = new Loader();
ldr.loadBytes(swf);
ldr.addEventListener(Event.COMPLETE, function (d):void{
swf.length = 0;
});
return (ldr);
}
}
}//package fmd
Section 85
//ModPlayer (fmd.ModPlayer)
package fmd {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.net.*;
import fmd._ModPlayer.*;
import fmd.flash.*;
import flash.media.*;
import fmd.haxe.*;
public class ModPlayer {
protected var ldr:Loader;
protected var states:Array;
public var sinewave:Array;
public var notsupflag:Array;
protected var tickspermin:int;
protected var samplespertick:int;
protected var ticksperrow:int;
public var stopnow:Boolean;
public var chancount:int;
protected var crow:int;
protected var tmr:Timer;
public var pat:Array;
protected var delaypattern:int;
protected var rowspermin:int;
protected var checktick:Boolean;
public var showTraces:Boolean;
public var songlength:int;
protected var breakpatnextrow:int;
public var onProgress:Function;
protected var corder:int;
public var order:Array;
public var musicdata:Class;
public var periods:Array;
protected var cpattern:Pattern;
public var smp:Array;
protected var breakpatonrow:Boolean;
protected var cpat:int;
protected var checkrow:Boolean;
public var segbreak:int;
public var repeating:Boolean;
protected var ticksmpctr:int;
protected var cnt:int;
protected var onFinish:Function;
protected var rowtick:int;
public var wave:ByteArray;
public var wavelen:int;
public function ModPlayer():void{
musicdata = ModPlayer_musicdata;
super();
if (!Boot.skip_constructor){
this.showTraces = false;
this.segbreak = 500000;
this.repeating = true;
};
}
public function stop():void{
this.stopnow = true;
SoundMixer.stopAll();
}
public function test():void{
var self:ModPlayer = this;
var testdata:ByteArray = new ByteArray();
testdata = (new musicdata() as ByteArray);
self.playBytes(testdata);
}
public function setRepeating(value:Boolean):void{
this.repeating = value;
}
public function notsupport(code:int, pat:int, row:int):void{
if (!this.notsupflag[code]){
this.notsupflag[code] = true;
if (code > 15){
this.xtrace(((((("Command not supported at pat " + pat) + " row ") + row) + ": Extended ") + (code >> 4)));
} else {
this.xtrace(((((("Command not supported at pat " + pat) + " row ") + row) + ": ") + code));
};
};
}
public function playBytes(data:ByteArray):void{
var stamp:Number;
var self:ModPlayer;
var data = data;
data.endian = Endian.BIG_ENDIAN;
this.stopnow = false;
this.parseData(data);
//unresolved jump
var _slot1 = e;
this.xtrace(("pderror - " + _slot1.message));
if (this.onProgress != null){
this.onProgress(-1);
};
data.length = 0;
stamp = Timer.stamp();
self = this;
this.genWaveform(function ():void{
self.xtrace((("Waveform synthesis time: " + (Timer.stamp() - stamp)) + " seconds"));
self.wave.length = self.cnt;
self.beginPlayback();
});
//unresolved jump
var _slot1 = e2;
this.xtrace(_slot1.message);
if (this.onProgress != null){
this.onProgress(-1);
};
return;
}
public function calcSegment():Boolean{
var cs:ChanState;
var nextcheckrow:Boolean;
var mixed:int;
var _g1:int;
var _g:int;
var c:int;
var note:Note;
var amigabps:Number;
var cmd:int;
var arg:int;
var amigabps2:Number;
var amigabps3:Number;
var amigabps4:Number;
var amigabps5:Number;
var aperiod:int;
var amigabps6:Number;
var amigabps7:Number;
var amigabps8:Number;
var vibval:int;
var amigabps9:Number;
var trmval:int;
var stamp:Number = Timer.stamp();
var segsamples:int;
for (;;if (mixed < -128){
mixed = -128;
} else {
if (mixed > 127){
mixed = 127;
};
}, (mixed = (mixed + 128)), if (this.cnt >= this.wavelen){
this.wavelen = (this.wavelen + 1000000);
this.wave.length = this.wavelen;
}, (var _local2 = this.cnt++), (this.wave[_local2] = mixed), (var _local3 = this.cnt++), (this.wave[_local3] = mixed), if (this.checkrow){
this.checkrow = nextcheckrow;
}, if (this.checktick){
this.checktick = false;
}, (segsamples = (segsamples + 1)), if ((segsamples + 1) >= this.segbreak){
return (true);
}) {
nextcheckrow = false;
if (++this.ticksmpctr == this.samplespertick){
this.ticksmpctr = 0;
if (++this.rowtick == this.ticksperrow){
this.rowtick = 0;
if (this.delaypattern > 0){
this.delaypattern--;
} else {
if (((this.breakpatonrow) || ((++this.crow == 64)))){
this.crow = (this.breakpatonrow) ? this.breakpatnextrow : 0;
if (this.crow >= 64){
this.crow = 63;
};
if (++this.corder == this.songlength){
return (false);
};
this.cpat = this.order[this.corder];
this.cpattern = this.pat[this.cpat];
this.breakpatonrow = false;
this.delaypattern = 0;
};
this.checkrow = true;
};
};
this.checktick = true;
};
mixed = 0;
_g1 = 0;
_g = this.chancount;
while (_g1 < _g) {
_g1 = (_g1 + 1);
c = _g1;
cs = this.states[c];
if (this.checkrow){
note = this.cpattern.channel[c].note[this.crow];
cs.arpeggio = false;
cs.delaynote = false;
cs.retriggersample = false;
cs.slidevolume = false;
cs.slideperiod = false;
cs.slidetonote = (((note.command == 3)) || ((note.command == 5)));
cs.vibrato = (((note.command == 4)) || ((note.command == 6)));
cs.tremolo = false;
if (note.sample != null){
cs.csmp = note.sample;
cs.cvolume = (cs.rvolume = cs.csmp.volume);
cs.cslength = (cs.csmp.length << 16);
cs.cslooplen = cs.cslength;
};
if (((((!((note.period == 0))) && (!((cs.csmp == null))))) && (!(cs.slidetonote)))){
if (note.peridx != -1){
cs.cperiod = this.periods[(note.peridx + (cs.csmp.fine * 84))];
} else {
cs.cperiod = note.period;
};
cs.lastnoteperiod = cs.cperiod;
amigabps = (7159090.5 / (cs.cperiod * 2));
cs.cspinc = Std._int(((amigabps / 22050) * 65536));
cs.csp = 0;
cs.slideperiod = false;
if (cs.vibratowave < 4){
cs.vibratopos = 0;
};
if (cs.tremolowave < 4){
cs.tremolopos = 0;
};
};
if (((!((note.command == 0))) || (!((note.cmdarg == 0))))){
cmd = note.command;
arg = note.cmdarg;
switch (cmd){
case 0:
cs.arpeggio = ((!((note.peridx == -1))) || ((note.period == 0)));
if (note.period != 0){
cs.arpeggionote = note.peridx;
};
cs.arpeggiosemi1 = ((arg & 240) >> 4);
cs.arpeggiosemi2 = (arg & 15);
cs.arpeggiotick = 0;
break;
case 1:
if (arg != 0){
cs.slideperiod = true;
cs.slideperiodval = -(arg);
};
throw ("__break__");
break;
case 2:
if (arg != 0){
cs.slideperiod = true;
cs.slideperiodval = arg;
};
throw ("__break__");
break;
case 3:
if (arg != 0){
cs.slideperiodval = arg;
};
if (note.period != 0){
cs.slidetonotetarget = ((note.peridx == 1)) ? note.period : this.periods[(note.peridx + (cs.csmp.fine * 84))];
if ((((cs.cperiod > note.period)) && ((cs.slideperiodval > 0)))){
cs.slideperiodval = -(cs.slideperiodval);
} else {
if ((((cs.cperiod < note.period)) && ((cs.slideperiodval < 0)))){
cs.slideperiodval = -(cs.slideperiodval);
};
};
} else {
if (arg != 0){
if ((((cs.cperiod > cs.slidetonotetarget)) && ((cs.slideperiodval > 0)))){
cs.slideperiodval = -(cs.slideperiodval);
} else {
if ((((cs.cperiod < cs.slidetonotetarget)) && ((cs.slideperiodval < 0)))){
cs.slideperiodval = -(cs.slideperiodval);
};
};
};
};
if (cs.slidetonotetarget == 0){
cs.slidetonote = false;
};
break;
case 4:
if (arg != 0){
cs.vibratospeed = ((arg & 240) >> 4);
cs.vibratodepth = (arg & 15);
cs.vibratopos = 0;
};
break;
case 7:
cs.tremolo = true;
if (arg != 0){
cs.tremolospeed = ((arg & 240) >> 4);
cs.tremolodepth = (arg & 15);
cs.tremolopos = 0;
};
break;
case 8:
break;
case 9:
if (arg != 0){
arg = (arg << 8);
if (arg >= cs.csmp.length){
arg = cs.csmp.length;
};
cs.csp = (arg << 16);
};
break;
case 5:
case 6:
case 10:
cs.slidevolume = true;
if (arg != 0){
if ((arg & 240) != 0){
cs.slidevolumeval = (arg >> 4);
} else {
cs.slidevolumeval = -((arg & 15));
};
};
break;
case 11:
if (arg > this.corder){
this.corder = arg;
if (this.corder >= this.order.length){
this.corder = (this.order.length - 1);
this.crow = 63;
this.cpat = this.order[this.corder];
this.cpattern = this.pat[this.cpat];
} else {
this.crow = 0;
};
nextcheckrow = true;
};
break;
case 12:
if (arg > 64){
arg = 64;
};
cs.cvolume = (cs.rvolume = arg);
break;
case 13:
arg = ((((arg & 240) >> 4) * 10) + (arg & 15));
if (arg > 63){
arg = 63;
};
this.breakpatonrow = true;
this.breakpatnextrow = arg;
break;
case 14:
switch ((arg & 240)){
case 0:
break;
case 16:
cs.cperiod = (cs.cperiod - (arg & 15));
amigabps2 = (7159090.5 / (cs.cperiod * 2));
cs.cspinc = Std._int(((amigabps2 / 22050) * 65536));
break;
case 32:
cs.cperiod = (cs.cperiod + (arg & 15));
amigabps3 = (7159090.5 / (cs.cperiod * 2));
cs.cspinc = Std._int(((amigabps3 / 22050) * 65536));
break;
case 48:
this.notsupport((arg & 240), this.cpat, this.crow);
break;
case 64:
switch ((arg & 15)){
case 0:
case 1:
case 2:
case 4:
case 5:
case 6:
cs.vibratowave = (arg & 15);
break;
case 3:
case 7:
cs.vibratowave = Std._int((Math.random() * 4));
if (cs.vibratowave > 3){
cs.vibratowave = 3;
};
if ((arg & 15) == 7){
cs.vibratowave = (cs.vibratowave + 4);
};
break;
};
break;
case 80:
this.notsupport((arg & 240), this.cpat, this.crow);
break;
case 96:
this.notsupport((arg & 240), this.cpat, this.crow);
break;
case 112:
switch ((arg & 15)){
case 0:
case 1:
case 2:
case 4:
case 5:
case 6:
cs.tremolowave = (arg & 15);
break;
case 3:
case 7:
cs.tremolowave = Std._int((Math.random() * 4));
if (cs.tremolowave > 3){
cs.tremolowave = 3;
};
if ((arg & 15) == 7){
cs.tremolowave = (cs.tremolowave + 4);
};
break;
};
break;
case 128:
break;
case 144:
cs.retriggersample = ((arg & 15) > 0);
cs.retriggersamplectr = 0;
cs.retriggersampleticks = (arg & 15);
break;
case 160:
cs.cvolume = (cs.cvolume + (arg & 15));
if (cs.cvolume > 64){
cs.cvolume = 64;
};
cs.rvolume = cs.cvolume;
break;
case 176:
cs.cvolume = (cs.cvolume - (arg & 15));
if (cs.cvolume < 0){
cs.cvolume = 0;
};
cs.rvolume = cs.cvolume;
break;
case 192:
cs.cutsample = ((arg & 15) > 0);
cs.cutsampleticks = (arg & 15);
break;
case 208:
cs.delaynote = true;
cs.delaynoteticks = (arg & 15);
break;
case 224:
this.delaypattern = (arg & 15);
break;
case 240:
break;
};
break;
case 15:
if (arg <= 32){
if (arg == 0){
arg = 1;
};
this.ticksperrow = arg;
} else {
this.rowspermin = (arg * 4);
this.tickspermin = (this.rowspermin * 6);
this.samplespertick = Std._int(((22050 * 60) / this.tickspermin));
};
break;
};
};
};
if (this.checktick){
if (this.rowtick > 0){
if (((cs.cutsample) && ((cs.cutsampleticks <= this.rowtick)))){
cs.cvolume = (cs.rvolume = 0);
cs.csmp = null;
cs.cutsample = false;
};
if (((cs.delaynote) && ((cs.delaynoteticks <= this.rowtick)))){
cs.csp = 0;
cs.delaynote = false;
};
if (cs.retriggersample){
if (++cs.retriggersamplectr == cs.retriggersampleticks){
cs.csp = 0;
cs.cslength = (cs.csmp.length << 16);
cs.cslooplen = cs.cslength;
cs.retriggersamplectr = 0;
};
};
if (cs.slidevolume){
cs.cvolume = (cs.cvolume + cs.slidevolumeval);
if (cs.cvolume <= 0){
cs.cvolume = 0;
} else {
if (cs.cvolume > 64){
cs.cvolume = 64;
};
};
cs.rvolume = cs.cvolume;
};
if (cs.slideperiod){
cs.cperiod = (cs.cperiod + cs.slideperiodval);
if (cs.cperiod < 113){
cs.cperiod = 113;
} else {
if (cs.cperiod > 856){
cs.cperiod = 856;
};
};
amigabps4 = (7159090.5 / (cs.cperiod * 2));
cs.cspinc = Std._int(((amigabps4 / 22050) * 65536));
};
if (cs.slidetonote){
cs.cperiod = (cs.cperiod + cs.slideperiodval);
if ((((cs.slideperiodval < 0)) && ((cs.slidetonotetarget > cs.cperiod)))){
cs.cperiod = cs.slidetonotetarget;
} else {
if ((((cs.slideperiodval > 0)) && ((cs.slidetonotetarget < cs.cperiod)))){
cs.cperiod = cs.slidetonotetarget;
};
};
amigabps5 = (7159090.5 / (cs.cperiod * 2));
cs.cspinc = Std._int(((amigabps5 / 22050) * 65536));
};
};
if (cs.arpeggio){
if (cs.arpeggiotick == 0){
aperiod = this.periods[(cs.arpeggionote + (cs.csmp.fine * 84))];
amigabps6 = (7159090.5 / (aperiod * 2));
cs.cspinc = Std._int(((amigabps6 / 22050) * 65536));
cs.arpeggiotick++;
} else {
if (cs.arpeggiotick == 1){
aperiod = this.periods[((cs.arpeggionote + (cs.csmp.fine * 84)) + cs.arpeggiosemi1)];
amigabps7 = (7159090.5 / (aperiod * 2));
cs.cspinc = Std._int(((amigabps7 / 22050) * 65536));
cs.arpeggiotick++;
} else {
if (cs.arpeggiotick == 2){
aperiod = this.periods[((cs.arpeggionote + (cs.csmp.fine * 84)) + cs.arpeggiosemi2)];
amigabps8 = (7159090.5 / (aperiod * 2));
cs.cspinc = Std._int(((amigabps8 / 22050) * 65536));
cs.arpeggiotick = 0;
};
};
};
};
if (cs.vibrato){
vibval = ((cs.vibratodepth * this.sinewave[(cs.vibratopos & 63)]) >> 7);
amigabps9 = (7159090.5 / ((cs.cperiod + vibval) * 2));
cs.cspinc = Std._int(((amigabps9 / 22050) * 65536));
if (this.rowtick > 0){
cs.vibratopos = (cs.vibratopos + cs.vibratospeed);
};
};
if (cs.tremolo){
trmval = ((cs.tremolodepth * this.sinewave[(cs.tremolopos & 63)]) >> 6);
cs.rvolume = (cs.cvolume + trmval);
if (cs.rvolume < 0){
cs.rvolume = 0;
} else {
if (cs.rvolume > 64){
cs.rvolume = 64;
};
};
if (this.rowtick > 0){
cs.tremolopos = (cs.tremolopos + cs.tremolospeed);
};
};
};
if ((((cs.csmp == null)) || ((cs.rvolume == 0)))){
} else {
if (!cs.delaynote){
mixed = (mixed + ((cs.csmp.wave[(cs.csp >> 16)] * cs.rvolume) >> 8));
};
cs.csp = (cs.csp + cs.cspinc);
if (cs.csp >= cs.cslooplen){
if (cs.csmp.looplen < 2){
cs.csmp = null;
continue;
} else {
cs.csp = (cs.csmp.loopstart << 16);
cs.cslooplen = (cs.csp + (cs.csmp.looplen << 16));
};
};
};
};
continue;
var _slot1 = e;
if (_slot1 != "__break__"){
throw (_slot1);
};
};
return (true);
}
public function genWaveform(onFinish:Function):void{
var i:int;
var c:int;
this.corder = 0;
this.cpat = this.order[this.corder];
this.cpattern = this.pat[this.cpat];
this.states = new Array();
this.rowspermin = (125 * 4);
this.ticksperrow = 6;
this.tickspermin = (this.rowspermin * this.ticksperrow);
this.samplespertick = Std._int(((22050 * 60) / this.tickspermin));
this.ticksmpctr = -1;
this.checkrow = true;
this.checktick = true;
this.delaypattern = 0;
this.sinewave = [0, 24, 49, 74, 97, 120, 141, 161, 180, 197, 212, 224, 235, 244, 250, 253, 0xFF, 253, 250, 244, 235, 224, 212, 197, 180, 161, 141, 120, 97, 74, 49, 24, 0, -24, -49, -74, -97, -120, -141, -161, -180, -197, -212, -224, -235, -244, -250, -253, -255, -253, -250, -244, -235, -224, -212, -197, -180, -161, -141, -120, -97, -74, -49, -24];
this.notsupflag = new Array();
var _g:int;
while (_g < 0x0100) {
var _temp1 = _g;
_g = (_g + 1);
i = _temp1;
this.notsupflag[i] = false;
};
var _g1:int;
var _g2:int = this.chancount;
while (_g1 < _g2) {
var _temp2 = _g1;
_g1 = (_g1 + 1);
c = _temp2;
this.states[c] = new ChanState();
this.states[c].csmp = null;
this.states[c].cperiod = 0;
this.states[c].cvolume = 64;
this.states[c].rvolume = 64;
this.states[c].csp = 0;
this.states[c].cspinc = 0;
this.states[c].slideperiod = false;
this.states[c].vibratowave = 0;
this.states[c].tremolowave = 0;
};
this.xtrace("Generating waveform from module data");
this.wave = new ByteArray();
this.wave.length = (this.wavelen = 1000000);
this.cnt = 0;
this.stopnow = false;
this.onFinish = onFinish;
this.calcSegTask(null);
}
public function play(url:String):void{
var loader:URLLoader;
var self:ModPlayer;
var url = url;
var req:URLRequest = new URLRequest(url);
loader = new URLLoader();
self = this;
this.xtrace(("Downloading " + url));
loader.dataFormat = URLLoaderDataFormat.BINARY;
loader.load(req);
//unresolved jump
var _slot1 = e;
this.xtrace(("Flash error - " + _slot1.message));
if (this.onProgress != null){
this.onProgress(-1);
};
return;
loader.addEventListener(IOErrorEvent.IO_ERROR, function (d):void{
self.xtrace(("IO Error while loading " + url));
if (self.onProgress != null){
self.onProgress(-1);
};
});
loader.addEventListener(Event.COMPLETE, function (d):void{
var d = d;
self.xtrace((("Finished loading " + loader.bytesTotal) + " bytes"));
self.playBytes(function ():ByteArray{
var $r:*;
var tmp:* = loader.data;
$r = (Std._is(tmp, ByteArray)) ? tmp : function (){
var $r2:*;
throw ("Class cast error");
}();
return ($r);
}());
loader.data.length = 0;
});
loader.addEventListener(ProgressEvent.PROGRESS, function (d):void{
if (self.onProgress != null){
self.onProgress(Std._int(((9 * d.bytesLoaded) / d.bytesTotal)));
};
});
}
public function xtrace(msg:String):void{
if (this.showTraces){
Log.trace(msg, {fileName:"ModPlayer.hx", lineNumber:134, className:"ModPlayer", methodName:"xtrace"});
};
}
public function beginPlayback():void{
if (this.stopnow){
return;
};
this.xtrace("Beginning playback");
this.ldr = DynSound.playSound(this.wave, this.repeating);
this.wave.length = 0;
}
protected function calcSegTask(d):void{
if (!this.calcSegment()){
if (this.onProgress != null){
this.onProgress(100);
};
this.onFinish();
} else {
if (this.onProgress != null){
this.onProgress((10 + Std._int(((89 * this.corder) / this.songlength))));
};
if (this.stopnow){
this.stopnow = false;
return;
};
this.tmr = new Timer(1, 1);
this.tmr.addEventListener(TimerEvent.TIMER_COMPLETE, this.calcSegTask);
this.tmr.start();
};
}
public function parseData(data:ByteArray):void{
var samplecount:int;
var patcount:int;
var j:int;
var c:int;
var i:int;
var len:int;
var fine:int;
var vol:int;
var loopstart:int;
var looplen:int;
var i2:int;
var i3:int;
var i4:int;
var _g22:int;
var _g12:int;
var _g13:int;
var c2:int;
var _g32:int;
var r:int;
var r2:int;
var _g33:int;
var _g23:int;
var ch:int;
var a:int;
var b:int;
var c3:int;
var d:int;
var sampidx:int;
var period:int;
var effect:int;
var peridx:int;
var diff:int;
var _g42:int;
var p:int;
var i5:int;
var _g24:int;
var _g14:int;
var j2:int;
var b2:int;
var rowcount = 64;
var periods:Array = [3628, 3424, 3232, 3048, 2880, 2712, 0x0A00, 2416, 2280, 2152, 2032, 1920, 1814, 1712, 1616, 1524, 1440, 1356, 0x0500, 1208, 1140, 1076, 1016, 960, 907, 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453, 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226, 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113, 107, 101, 95, 90, 85, 80, 75, 71, 67, 63, 60, 56, 53, 50, 47, 45, 42, 40, 37, 35, 33, 31, 30, 3600, 3400, 3208, 3028, 2860, 2700, 2544, 2404, 2268, 2140, 2020, 1908, 1800, 1700, 1604, 1514, 1430, 1350, 1272, 1202, 1134, 1070, 1010, 954, 900, 850, 802, 757, 715, 675, 636, 601, 567, 535, 505, 477, 450, 425, 401, 379, 357, 337, 318, 300, 284, 268, 253, 238, 225, 212, 200, 189, 179, 169, 159, 150, 142, 134, 126, 119, 112, 106, 100, 94, 89, 84, 79, 75, 71, 67, 63, 59, 56, 53, 50, 47, 44, 42, 39, 37, 35, 33, 31, 29, 3576, 3376, 3184, 3008, 2836, 2680, 2528, 2388, 2252, 2128, 2008, 1896, 1788, 1688, 1592, 1504, 1418, 1340, 1264, 1194, 1126, 1064, 1004, 948, 894, 844, 796, 752, 709, 670, 632, 597, 563, 532, 502, 474, 447, 422, 398, 376, 355, 335, 316, 298, 282, 266, 251, 237, 223, 211, 199, 188, 177, 167, 158, 149, 141, 133, 125, 118, 111, 105, 99, 94, 88, 83, 79, 74, 70, 66, 62, 59, 55, 52, 49, 47, 44, 41, 39, 37, 35, 33, 31, 29, 3548, 3352, 3164, 2984, 0x0B00, 2660, 2512, 2368, 2236, 2112, 1992, 1880, 1774, 1676, 1582, 1492, 1408, 1330, 1256, 1184, 1118, 1056, 996, 940, 887, 838, 791, 746, 704, 665, 628, 592, 559, 528, 498, 470, 444, 419, 395, 373, 352, 332, 314, 296, 280, 264, 249, 235, 222, 209, 198, 187, 176, 166, 157, 148, 140, 132, 125, 118, 111, 104, 99, 93, 88, 83, 78, 74, 70, 66, 62, 59, 55, 52, 49, 46, 44, 41, 39, 37, 35, 33, 31, 29, 3524, 0x0D00, 3140, 2964, 2796, 2640, 2492, 2352, 2220, 2096, 1976, 1868, 1762, 1664, 1570, 1482, 1398, 1320, 1246, 1176, 1110, 1048, 988, 934, 881, 832, 785, 741, 699, 660, 623, 588, 555, 524, 494, 467, 441, 416, 392, 370, 350, 330, 312, 294, 278, 262, 247, 233, 220, 208, 196, 185, 175, 165, 156, 147, 139, 131, 123, 117, 110, 104, 98, 92, 87, 82, 78, 73, 69, 65, 61, 58, 55, 52, 49, 46, 43, 41, 39, 36, 34, 32, 30, 29, 3500, 3304, 3116, 2944, 2776, 2620, 2476, 2336, 2204, 2080, 1964, 1852, 1750, 1652, 1558, 1472, 1388, 1310, 1238, 1168, 1102, 1040, 982, 926, 875, 826, 779, 736, 694, 655, 619, 584, 551, 520, 491, 463, 437, 413, 390, 368, 347, 328, 309, 292, 276, 260, 245, 232, 219, 206, 195, 184, 174, 164, 155, 146, 138, 130, 123, 116, 109, 103, 97, 92, 87, 82, 77, 73, 69, 65, 61, 58, 54, 51, 48, 46, 43, 41, 38, 36, 34, 32, 30, 29, 3472, 3280, 3096, 2920, 2756, 2604, 2456, 2320, 2188, 2064, 1948, 1840, 1736, 1640, 1548, 1460, 1378, 1302, 1228, 1160, 1094, 1032, 974, 920, 868, 820, 774, 730, 689, 651, 614, 580, 547, 516, 487, 460, 434, 410, 387, 365, 345, 325, 307, 290, 274, 258, 244, 230, 217, 205, 193, 183, 172, 163, 154, 145, 137, 129, 122, 115, 108, 102, 96, 91, 86, 81, 77, 72, 68, 64, 61, 57, 54, 51, 48, 45, 43, 40, 38, 36, 34, 32, 30, 28, 3448, 3256, 0x0C00, 2900, 2736, 2584, 2440, 2300, 2172, 2052, 1936, 1828, 1724, 1628, 0x0600, 1450, 1368, 1292, 1220, 1150, 1086, 1026, 968, 914, 862, 814, 0x0300, 725, 684, 646, 610, 575, 543, 513, 484, 457, 431, 407, 384, 363, 342, 323, 305, 288, 272, 0x0100, 242, 228, 216, 203, 192, 181, 171, 161, 152, 144, 136, 128, 121, 114, 108, 101, 96, 90, 85, 80, 76, 72, 68, 64, 60, 57, 54, 50, 48, 45, 42, 40, 38, 36, 34, 32, 30, 28, 3424, 3232, 3048, 2880, 2712, 0x0A00, 2416, 2280, 2152, 2032, 1920, 1812, 1712, 1616, 1524, 1440, 1356, 0x0500, 1208, 1140, 1076, 1016, 960, 906, 856, 808, 762, 720, 678, 640, 604, 570, 538, 508, 480, 453, 428, 404, 381, 360, 339, 320, 302, 285, 269, 254, 240, 226, 214, 202, 190, 180, 170, 160, 151, 143, 135, 127, 120, 113, 107, 101, 95, 90, 85, 80, 75, 71, 67, 63, 60, 56, 53, 50, 47, 45, 42, 40, 37, 35, 33, 31, 30, 28, 3400, 3208, 3028, 2860, 2696, 2548, 2404, 2268, 2140, 2020, 1908, 1800, 1700, 1604, 1514, 1430, 1348, 1274, 1202, 1134, 1070, 1010, 954, 900, 850, 802, 757, 715, 674, 637, 601, 567, 535, 505, 477, 450, 425, 401, 379, 357, 337, 318, 300, 284, 268, 253, 239, 225, 213, 201, 189, 179, 169, 159, 150, 142, 134, 126, 119, 113, 106, 100, 94, 89, 84, 79, 75, 71, 67, 63, 59, 56, 53, 50, 47, 44, 42, 39, 37, 35, 33, 31, 29, 28, 3376, 3184, 3008, 2836, 2680, 2528, 2388, 2252, 2128, 2008, 1896, 1788, 1688, 1592, 1504, 1418, 1340, 1264, 1194, 1126, 1064, 1004, 948, 894, 844, 796, 752, 709, 670, 632, 597, 563, 532, 502, 474, 447, 422, 398, 376, 355, 335, 316, 298, 282, 266, 251, 237, 224, 211, 199, 188, 177, 167, 158, 149, 141, 133, 125, 118, 112, 105, 99, 94, 88, 83, 79, 74, 70, 66, 62, 59, 56, 52, 49, 47, 44, 41, 39, 37, 35, 33, 31, 29, 28, 3352, 3164, 2984, 0x0B00, 2660, 2512, 2368, 2236, 2112, 1992, 1880, 1776, 1676, 1582, 1492, 1408, 1330, 1256, 1184, 1118, 1056, 996, 940, 888, 838, 791, 746, 704, 665, 628, 592, 559, 528, 498, 470, 444, 419, 395, 373, 352, 332, 314, 296, 280, 264, 249, 235, 222, 209, 198, 187, 176, 166, 157, 148, 140, 132, 125, 118, 111, 104, 99, 93, 88, 83, 78, 74, 70, 66, 62, 59, 55, 52, 49, 46, 44, 41, 39, 37, 35, 33, 31, 29, 27, 0x0D00, 3140, 2964, 2796, 2640, 2492, 2352, 2220, 2096, 1980, 1868, 1764, 1664, 1570, 1482, 1398, 1320, 1246, 1176, 1110, 1048, 990, 934, 882, 832, 785, 741, 699, 660, 623, 588, 555, 524, 495, 467, 441, 416, 392, 370, 350, 330, 312, 294, 278, 262, 247, 233, 220, 208, 196, 185, 175, 165, 156, 147, 139, 131, 124, 117, 110, 104, 98, 92, 87, 82, 78, 73, 69, 65, 62, 58, 55, 52, 49, 46, 43, 41, 39, 36, 34, 32, 31, 29, 27, 3304, 3116, 2944, 2776, 2620, 2476, 2336, 2204, 2080, 1964, 1852, 1748, 1652, 1558, 1472, 1388, 1310, 1238, 1168, 1102, 1040, 982, 926, 874, 826, 779, 736, 694, 655, 619, 584, 551, 520, 491, 463, 437, 413, 390, 368, 347, 328, 309, 292, 276, 260, 245, 232, 219, 206, 195, 184, 174, 164, 155, 146, 138, 130, 123, 116, 109, 103, 97, 92, 87, 82, 77, 73, 69, 65, 61, 58, 54, 51, 48, 46, 43, 41, 38, 36, 34, 32, 30, 29, 27, 3280, 3096, 2920, 2756, 2604, 2456, 2320, 2188, 2064, 1948, 1840, 1736, 1640, 1548, 1460, 1378, 1302, 1228, 1160, 1094, 1032, 974, 920, 868, 820, 774, 730, 689, 651, 614, 580, 547, 516, 487, 460, 434, 410, 387, 365, 345, 325, 307, 290, 274, 258, 244, 230, 217, 205, 193, 183, 172, 163, 154, 145, 137, 129, 122, 115, 109, 102, 96, 91, 86, 81, 77, 72, 68, 64, 61, 57, 54, 51, 48, 45, 43, 40, 38, 36, 34, 32, 30, 28, 27, 3256, 0x0C00, 2900, 2736, 2584, 2440, 2300, 2172, 2052, 1936, 1828, 1724, 1628, 0x0600, 1450, 1368, 1292, 1220, 1150, 1086, 1026, 968, 914, 862, 814, 0x0300, 725, 684, 646, 610, 575, 543, 513, 484, 457, 431, 407, 384, 363, 342, 323, 305, 288, 272, 0x0100, 242, 228, 216, 204, 192, 181, 171, 161, 152, 144, 136, 128, 121, 114, 108, 102, 96, 90, 85, 80, 76, 72, 68, 64, 60, 57, 54, 51, 48, 45, 42, 40, 38, 36, 34, 32, 30, 28, 27];
this.periods = periods;
this.xtrace("Parsing mod data...");
this.chancount = 4;
this.smp = new Array();
if ((((((((((((data[1080] == 77)) && ((data[1081] == 46)))) && ((data[1082] == 75)))) && ((data[1083] == 46)))) || ((((((((data[1080] == 70)) && ((data[1081] == 76)))) && ((data[1082] == 84)))) && ((data[1083] == 52)))))) || ((((((((data[1080] == 52)) && ((data[1081] == 67)))) && ((data[1082] == 72)))) && ((data[1083] == 78)))))){
samplecount = 31;
} else {
if ((((((((data[1080] == 52)) && ((data[1081] == 67)))) && ((data[1082] == 72)))) && ((data[1083] == 78)))){
samplecount = 31;
this.chancount = 2;
} else {
if ((((((((data[1080] == 54)) && ((data[1081] == 67)))) && ((data[1082] == 72)))) && ((data[1083] == 78)))){
samplecount = 31;
this.chancount = 6;
} else {
if ((((((((((((data[1080] == 67)) && ((data[1081] == 68)))) && ((data[1082] == 56)))) && ((data[1083] == 49)))) || ((((((((data[1080] == 79)) && ((data[1081] == 67)))) && ((data[1082] == 84)))) && ((data[1083] == 65)))))) || ((((((((data[1080] == 56)) && ((data[1081] == 67)))) && ((data[1082] == 72)))) && ((data[1083] == 78)))))){
samplecount = 31;
this.chancount = 8;
} else {
samplecount = 15;
};
};
};
};
this.xtrace((((("Module has " + samplecount) + " samples, ") + this.chancount) + " channels"));
var name:String = "";
var _g:int;
while (_g < 20) {
var _temp1 = _g;
_g = (_g + 1);
j = _temp1;
c = data.readUnsignedByte();
if ((((c > 31)) && ((c < 127)))){
name = (name + String.fromCharCode(c));
} else {
break;
};
};
this.xtrace(("Module title: " + name));
data.position = 20;
var _g2:int;
while (_g2 < samplecount) {
var _temp2 = _g2;
_g2 = (_g2 + 1);
i = _temp2;
data.position = (data.position + 22);
len = (data.readUnsignedShort() * 2);
fine = (data.readUnsignedByte() & 15);
vol = data.readUnsignedByte();
loopstart = (data.readUnsignedShort() * 2);
looplen = (data.readUnsignedShort() * 2);
if (len < 4){
len = 0;
};
if (fine > 7){
fine = (fine - 16);
};
this.smp[i] = new Sample();
this.smp[i].length = len;
this.smp[i].fine = fine;
this.smp[i].volume = vol;
this.smp[i].loopstart = loopstart;
this.smp[i].looplen = looplen;
};
this.songlength = data.readByte();
if (this.songlength < 1){
this.songlength = 1;
};
data.readByte();
this.order = new Array();
var _g3:int;
while (_g3 < 128) {
var _temp3 = _g3;
_g3 = (_g3 + 1);
i2 = _temp3;
this.order[i2] = data.readUnsignedByte();
};
if (samplecount != 15){
data.readInt();
};
this.xtrace((("Song length is " + this.songlength) + " patterns."));
patcount = 0;
var _g1:int;
var _g4:int = this.songlength;
while (_g1 < _g4) {
var _temp4 = _g1;
_g1 = (_g1 + 1);
i3 = _temp4;
if (patcount < this.order[i3]){
patcount = this.order[i3];
};
};
patcount = (patcount + 1);
this.xtrace(("Pattern count: " + patcount));
this.pat = new Array();
var _g5:int;
while (_g5 < patcount) {
var _temp5 = _g5;
_g5 = (_g5 + 1);
i4 = _temp5;
this.pat[i4] = new Pattern();
this.pat[i4].channel = new Array();
_g22 = 0;
_g12 = this.chancount;
while (_g22 < _g12) {
var _temp6 = _g22;
_g22 = (_g22 + 1);
c2 = _temp6;
this.pat[i4].channel[c2] = new Channel();
this.pat[i4].channel[c2].note = new Array();
_g32 = 0;
while (_g32 < rowcount) {
var _temp7 = _g32;
_g32 = (_g32 + 1);
r = _temp7;
this.pat[i4].channel[c2].note[r] = new Note();
};
};
_g13 = 0;
while (_g13 < rowcount) {
var _temp8 = _g13;
_g13 = (_g13 + 1);
r2 = _temp8;
_g33 = 0;
_g23 = this.chancount;
while (_g33 < _g23) {
var _temp9 = _g33;
_g33 = (_g33 + 1);
ch = _temp9;
a = data.readUnsignedByte();
b = data.readUnsignedByte();
c3 = data.readUnsignedByte();
d = data.readUnsignedByte();
sampidx = ((((a >> 4) & 15) << 4) | ((c3 >> 4) & 15));
period = (b | ((a & 15) << 8));
effect = (d | ((c3 & 15) << 8));
peridx = -1;
if (period > 0){
diff = 50;
_g42 = 672;
while (_g42 < 756) {
var _temp10 = _g42;
_g42 = (_g42 + 1);
p = _temp10;
if (Math.abs((period - periods[p])) < diff){
peridx = p;
diff = Std._int(Math.abs((period - periods[p])));
};
};
};
this.pat[i4].channel[ch].note[r2].sample = ((sampidx == 0)) ? null : this.smp[(sampidx - 1)];
this.pat[i4].channel[ch].note[r2].period = period;
this.pat[i4].channel[ch].note[r2].peridx = peridx;
this.pat[i4].channel[ch].note[r2].command = ((effect >> 8) & 15);
this.pat[i4].channel[ch].note[r2].cmdarg = (effect & 0xFF);
};
};
};
var _g6:int;
while (_g6 < samplecount) {
var _temp11 = _g6;
_g6 = (_g6 + 1);
i5 = _temp11;
this.smp[i5].wave = new Array();
_g24 = 0;
_g14 = this.smp[i5].length;
while (_g24 < _g14) {
var _temp12 = _g24;
_g24 = (_g24 + 1);
j2 = _temp12;
b2 = data.readByte();
this.smp[i5].wave[j2] = b2;
};
};
this.xtrace("Done parsing module data");
}
}
}//package fmd
Section 86
//ModPlayer_musicdata (fmd.ModPlayer_musicdata)
package fmd {
import mx.core.*;
public class ModPlayer_musicdata extends ByteArrayAsset {
}
}//package fmd
Section 87
//Std (fmd.Std)
package fmd {
import fmd.flash.*;
public class Std {
public function Std(){
super();
}
public static function _int(x:Number):int{
return (int(x));
}
public static function string(s):String{
return (Boot.__string_rec(s, ""));
}
public static function random(x:int):int{
return (Math.floor((Math.random() * x)));
}
public static function _parseFloat(x:String):Number{
return (parseFloat(x));
}
public static function _is(v, t):Boolean{
return (Boot.__instanceof(v, t));
}
public static function _parseInt(x:String){
var v:* = parseInt(x);
if (isNaN(v)){
return (null);
};
return (v);
}
}
}//package fmd
Section 88
//Credits (General.Credits)
package General {
import flash.events.*;
import flash.display.*;
import flash.net.*;
import flash.filters.*;
public class Credits extends Sprite {
private var total:int;// = 3
public var texture:Class;
public var newCube1:Cube;
public var newCube2:Cube;
public var newCube3:Cube;
private var menu:MovieClip;
private var mm:Class;
public var par:Main;
public var cubes:Array;
private var buttonsActive:Boolean;// = true
public var targetZ:int;// = 0
public function Credits():void{
texture = Credits_texture;
mm = Credits_mm;
cubes = new Array();
super();
if (stage){
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
private function loadMainMenu(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
par.loadMainMenu();
parent.removeChild(this);
};
}
private function omo1(e:Event):void{
newCube1.filters = [new GlowFilter()];
}
private function omo3(e:Event):void{
newCube3.filters = [new GlowFilter()];
}
public function init(e:Event=null):void{
newCube1 = new Cube(0, 0, 0, 50, 600, 40, 40, texture, 35, this.parent);
addChild(newCube1);
cubes.push({obj:newCube1, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:(Math.random() - 0.5)});
newCube1.addEventListener(MouseEvent.MOUSE_OVER, omo1);
newCube1.addEventListener(MouseEvent.MOUSE_OUT, omot1);
newCube1.filters = [new GlowFilter(0, 0, 0, 0, 0)];
newCube2 = new Cube(0, 0, 0, 540, 390, -50, 70, texture, 35, this.parent);
addChild(newCube2);
cubes.push({obj:newCube2, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:Math.random()});
newCube3 = new Cube(0, 0, 0, 90, 245, 0, 90, texture, 35, this.parent);
addChild(newCube3);
cubes.push({obj:newCube3, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:Math.random()});
newCube3.addEventListener(MouseEvent.MOUSE_OVER, omo3);
newCube3.addEventListener(MouseEvent.MOUSE_OUT, omot3);
newCube1.addEventListener(MouseEvent.CLICK, loadMainMenu);
newCube3.addEventListener(MouseEvent.CLICK, myHomePage);
var mmm:* = new mm();
this.menu = (addChild(mmm) as MovieClip);
par = (parent as Main);
}
private function omot1(e:Event):void{
newCube1.filters = [];
}
private function omot3(e:Event):void{
newCube3.filters = [];
}
private function myHomePage(e:Event=null):void{
var e = e;
var url = "http://t-studio.de/";
var request:URLRequest = new URLRequest(url);
navigateToURL(request, "_blank");
//unresolved jump
var _slot1 = e;
trace("Error occurred!");
}
}
}//package General
Section 89
//Credits_mm (General.Credits_mm)
package General {
import flash.display.*;
import mx.core.*;
public class Credits_mm extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 90
//Credits_texture (General.Credits_texture)
package General {
import flash.display.*;
import mx.core.*;
public class Credits_texture extends MovieClipAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 91
//Cube (General.Cube)
package General {
import flash.display.*;
public class Cube extends MovieClip {
public var rx:int;
public var ry:int;
public var rz:int;
public var f0:QFace;
private var par;
public var h:int;
public var n:int;
public var w:int;
public var _x:int;
public var _y:int;
public var _z:int;
public function Cube(rx:Number, ry:Number, rz:Number, _x:int, _y:int, _z:int, w:int, texture:Class, frame:int, par){
super();
this.rx = rx;
this.ry = ry;
this.rz = rz;
this.x = _x;
this.y = _y;
this.w = w;
this.par = par;
f0 = new QFace(0, 0, 0, 0, 0, 0, this.w, this.w, texture, frame);
addChild(f0);
}
public function move(dx:int, dy:int, dz:int):void{
}
public function rotate(dx:Number, dy:Number, dz:Number):void{
}
private function viewDist(face:QFace):Number{
return (0);
}
}
}//package General
Section 92
//Cursor (General.Cursor)
package General {
import flash.events.*;
import flash.display.*;
import flash.ui.*;
public class Cursor extends MovieClip {
private var par;
private var sprite:Class;
private var hand:MovieClip;
public function Cursor(par){
sprite = Cursor_sprite;
super();
Mouse.hide();
this.par = par;
hand = (addChild(new sprite()) as MovieClip);
this.mouseChildren = false;
this.mouseEnabled = false;
par.addEventListener(MouseEvent.MOUSE_MOVE, omm);
par.addEventListener(MouseEvent.MOUSE_DOWN, omd);
par.addEventListener(MouseEvent.MOUSE_UP, omu);
par.addEventListener(MouseEvent.CLICK, click);
addEventListener(Event.MOUSE_LEAVE, oml);
hand.stop();
}
private function omm(e:Event):void{
hand.visible = true;
this.x = par.mouseX;
this.y = par.mouseY;
}
private function omu(e:Event):void{
hand.gotoAndStop(1);
}
private function click(e:Event):void{
Mouse.hide();
}
private function omd(e:Event):void{
hand.gotoAndStop(2);
}
private function oml(e:Event):void{
visible = false;
}
}
}//package General
Section 93
//Cursor_sprite (General.Cursor_sprite)
package General {
import flash.display.*;
import mx.core.*;
public class Cursor_sprite extends MovieClipAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 94
//D3Cube (General.D3Cube)
package General {
import flash.events.*;
import flash.display.*;
import flash.text.*;
import org.flashdevelop.utils.*;
import flash.filters.*;
public class D3Cube extends Sprite {
private var tf3:TextField;
private var total:int;// = 3
private var tf2:TextField;
public var texture:Class;
public var newCube1:Cube;
public var newCube2:Cube;
public var newCube3:Cube;
private var menu:MovieClip;
private var mm:Class;
public var par:Main;
public var cubes:Array;
public var buttonsActive:Boolean;// = true
public var targetZ:int;// = 0
private var tf1:TextField;
public function D3Cube():void{
texture = D3Cube_texture;
mm = D3Cube_mm;
cubes = new Array();
super();
addEventListener(Event.ADDED_TO_STAGE, initx);
}
private function loadGame(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
visible = false;
FlashConnect.atrace("loading game");
par.loadLevels();
};
}
private function omo3(e:Event):void{
tf1.visible = true;
newCube3.filters = [new GlowFilter()];
}
private function loadCredits(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
visible = false;
FlashConnect.atrace("loading credits");
par.loadCredits();
};
}
private function omot1(e:Event):void{
newCube1.filters = [];
tf1.visible = (tf2.visible = (tf3.visible = false));
}
private function loadHelp(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
visible = false;
FlashConnect.atrace("loading help");
par.loadHelp();
};
}
private function omot3(e:Event):void{
newCube3.filters = [];
tf1.visible = (tf2.visible = (tf3.visible = false));
}
private function omo1(e:Event):void{
tf2.visible = true;
newCube1.filters = [new GlowFilter()];
}
private function omo2(e:Event):void{
tf3.visible = true;
newCube2.filters = [new GlowFilter()];
}
public function initx(e:Event=null):void{
removeEventListener(Event.ADDED_TO_STAGE, initx);
newCube1 = new Cube(0, 0, 0, (270 + 30), (320 + 80), 200, 70, texture, 2, this.parent);
addChild(newCube1);
newCube1.addEventListener(MouseEvent.MOUSE_OVER, omo1);
newCube1.addEventListener(MouseEvent.MOUSE_OUT, omot1);
newCube1.filters = [new GlowFilter(0, 0, 0, 0, 0)];
newCube2 = new Cube(0, 0, 0, (270 - 100), (320 - 40), (Math.random() * 128), 75, texture, 3, this.parent);
addChild(newCube2);
newCube2.addEventListener(MouseEvent.MOUSE_OVER, omo2);
newCube2.addEventListener(MouseEvent.MOUSE_OUT, omot2);
newCube2.filters = [new GlowFilter(0, 0, 0, 0, 0)];
newCube3 = new Cube(0, 0, 0, (270 + 210), (320 + 10), 128, 90, texture, 1, this.parent);
addChild(newCube3);
newCube3.addEventListener(MouseEvent.MOUSE_OVER, omo3);
newCube3.addEventListener(MouseEvent.MOUSE_OUT, omot3);
newCube3.filters = [new GlowFilter(0, 0, 0, 0, 0)];
cubes.push({obj:newCube1, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:Math.random()});
cubes.push({obj:newCube2, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:Math.random()});
cubes.push({obj:newCube3, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:Math.random()});
newCube1.addEventListener(MouseEvent.CLICK, loadCredits);
newCube2.addEventListener(MouseEvent.CLICK, loadHelp);
newCube3.addEventListener(MouseEvent.CLICK, loadGame);
var mmm:* = new mm();
this.menu = (addChild(mmm) as MovieClip);
tf1 = (mmm.getChildByName("playtext") as TextField);
tf2 = (mmm.getChildByName("creditstext") as TextField);
tf3 = (mmm.getChildByName("helptext") as TextField);
tf1.visible = (tf2.visible = (tf3.visible = false));
par = (parent as Main);
addChild(newCube1);
addChild(newCube2);
addChild(newCube3);
}
private function omot2(e:Event):void{
newCube2.filters = [];
tf1.visible = (tf2.visible = (tf3.visible = false));
}
}
}//package General
Section 95
//D3Cube_mm (General.D3Cube_mm)
package General {
import flash.display.*;
import mx.core.*;
public class D3Cube_mm extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var playtext:DisplayObject;
public var reset:DisplayObject;
public var helptext:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var soundInd:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 96
//D3Cube_texture (General.D3Cube_texture)
package General {
import flash.display.*;
import mx.core.*;
public class D3Cube_texture extends MovieClipAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 97
//Help (General.Help)
package General {
import flash.events.*;
import flash.display.*;
import org.flashdevelop.utils.*;
import flash.filters.*;
public class Help extends Sprite {
private var mm:Class;
public var par:Main;
private var total:int;// = 1
private var buttonsActive:Boolean;// = true
public var texture:Class;
public var newCube1:Cube;
public var cubes:Array;
private var menu:MovieClip;
public function Help():void{
texture = Help_texture;
mm = Help_mm;
cubes = new Array();
super();
if (stage){
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
private function loadMainMenu(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
FlashConnect.atrace("loading main menu");
par.loadMainMenu();
par.removeChild(this);
};
}
private function omo1(e:Event):void{
newCube1.filters = [new GlowFilter()];
}
public function init(e:Event=null):void{
this.par = (this.parent as Main);
newCube1 = new Cube(0, 0, 0, 285, 555, 40, 40, texture, 35, this.parent);
addChild(newCube1);
cubes.push({obj:newCube1, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:(Math.random() - 0.5)});
newCube1.addEventListener(MouseEvent.MOUSE_OVER, omo1);
newCube1.addEventListener(MouseEvent.MOUSE_OUT, omot1);
newCube1.addEventListener(MouseEvent.CLICK, loadMainMenu);
newCube1.filters = [new GlowFilter(0, 0, 0, 0, 0)];
var mmm:* = new mm();
this.menu = (addChild(mmm) as MovieClip);
par = (parent as Main);
}
private function omot1(e:Event):void{
newCube1.filters = [];
}
}
}//package General
Section 98
//Help_mm (General.Help_mm)
package General {
import flash.display.*;
import mx.core.*;
public class Help_mm extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 99
//Help_texture (General.Help_texture)
package General {
import flash.display.*;
import mx.core.*;
public class Help_texture extends MovieClipAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 100
//Input (General.Input)
package General {
import flash.events.*;
import flash.display.*;
public class Input {
public static var mouseOffsetX:Number = 0;
private static var keyArr:Array;
public static var mouseDragX:Number = 0;
public static var mouseDragY:Number = 0;
public static var mouseOffsetY:Number = 0;
public static var ascii:Array;
public static var mouseX:Number = 0;
public static var mouseY:Number = 0;
public static var mouseOver:Boolean = false;
private static var bufferSize:int;
public static var mouse:Sprite = new Sprite();
public static var mouseDown:Boolean = false;
public static var mouseReleased:Boolean = false;
public static var lastKey:int = 0;
public static var m_stageMc:Sprite;
private static var keyState:Array;
public static var timeSinceLastKey:int = 0;
public static var mousePressed:Boolean = false;
private static var keyBuffer:Array;
public function Input(stageMc:MovieClip):void{
super();
m_stageMc = stageMc;
ascii = new Array(222);
fillAscii();
keyState = new Array(222);
keyArr = new Array();
var i:int;
while (i < 222) {
keyState[i] = new int(0);
if (ascii[i] != undefined){
keyArr.push(i);
};
i++;
};
bufferSize = 5;
keyBuffer = new Array(bufferSize);
var j:int;
while (j < bufferSize) {
keyBuffer[j] = new Array(0, 0);
j++;
};
stageMc.parent.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyPress, false, 0, true);
stageMc.parent.stage.addEventListener(KeyboardEvent.KEY_UP, keyRelease, false, 0, true);
stageMc.parent.stage.addEventListener(MouseEvent.MOUSE_DOWN, mousePress, false, 0, true);
stageMc.parent.stage.addEventListener(MouseEvent.CLICK, mouseRelease, false, 0, true);
stageMc.parent.stage.addEventListener(MouseEvent.MOUSE_MOVE, mouseMove, false, 0, true);
stageMc.parent.stage.addEventListener(Event.MOUSE_LEAVE, mouseLeave, false, 0, true);
mouse.graphics.lineStyle(0.1, 0, 100);
mouse.graphics.moveTo(0, 0);
mouse.graphics.lineTo(0, 0.1);
}
public function mouseLeave(e:Event):void{
mouseReleased = mouseDown;
mouseDown = false;
}
public function keyPress(e:KeyboardEvent):void{
keyState[e.keyCode] = Math.max(keyState[e.keyCode], 1);
lastKey = e.keyCode;
}
private function fillAscii():void{
ascii[65] = "A";
ascii[66] = "B";
ascii[67] = "C";
ascii[68] = "D";
ascii[69] = "E";
ascii[70] = "F";
ascii[71] = "G";
ascii[72] = "H";
ascii[73] = "I";
ascii[74] = "J";
ascii[75] = "K";
ascii[76] = "L";
ascii[77] = "M";
ascii[78] = "N";
ascii[79] = "O";
ascii[80] = "P";
ascii[81] = "Q";
ascii[82] = "R";
ascii[83] = "S";
ascii[84] = "T";
ascii[85] = "U";
ascii[86] = "V";
ascii[87] = "W";
ascii[88] = "X";
ascii[89] = "Y";
ascii[90] = "Z";
ascii[48] = "0";
ascii[49] = "1";
ascii[50] = "2";
ascii[51] = "3";
ascii[52] = "4";
ascii[53] = "5";
ascii[54] = "6";
ascii[55] = "7";
ascii[56] = "8";
ascii[57] = "9";
ascii[32] = "Spacebar";
ascii[17] = "Ctrl";
ascii[16] = "Shift";
ascii[192] = "~";
ascii[38] = "up";
ascii[40] = "down";
ascii[37] = "left";
ascii[39] = "right";
ascii[96] = "Numpad 0";
ascii[97] = "Numpad 1";
ascii[98] = "Numpad 2";
ascii[99] = "Numpad 3";
ascii[100] = "Numpad 4";
ascii[101] = "Numpad 5";
ascii[102] = "Numpad 6";
ascii[103] = "Numpad 7";
ascii[104] = "Numpad 8";
ascii[105] = "Numpad 9";
ascii[111] = "Numpad /";
ascii[106] = "Numpad *";
ascii[109] = "Numpad -";
ascii[107] = "Numpad +";
ascii[110] = "Numpad .";
ascii[45] = "Insert";
ascii[46] = "Delete";
ascii[33] = "Page Up";
ascii[34] = "Page Down";
ascii[35] = "End";
ascii[36] = "Home";
ascii[112] = "F1";
ascii[113] = "F2";
ascii[114] = "F3";
ascii[115] = "F4";
ascii[116] = "F5";
ascii[117] = "F6";
ascii[118] = "F7";
ascii[119] = "F8";
ascii[188] = ",";
ascii[190] = ".";
ascii[186] = ";";
ascii[222] = "'";
ascii[219] = "[";
ascii[221] = "]";
ascii[189] = "-";
ascii[187] = "+";
ascii[220] = "\\";
ascii[191] = "/";
ascii[9] = "TAB";
ascii[8] = "Backspace";
}
public function mouseMove(e:MouseEvent):void{
if (mouseDown != e.buttonDown){
mouseDown = e.buttonDown;
mouseReleased = !(e.buttonDown);
mousePressed = e.buttonDown;
mouseDragX = 0;
mouseDragY = 0;
};
mouseX = (e.stageX - m_stageMc.x);
mouseY = (e.stageY - m_stageMc.y);
mouseOffsetX = (mouseX - mouse.x);
mouseOffsetY = (mouseY - mouse.y);
if (mouseDown){
mouseDragX = (mouseDragX + mouseOffsetX);
mouseDragY = (mouseDragY + mouseOffsetY);
};
mouse.x = mouseX;
mouse.y = mouseY;
}
public function keyRelease(e:KeyboardEvent):void{
keyState[e.keyCode] = -1;
var i:int = (bufferSize - 1);
while (i > 0) {
keyBuffer[i] = keyBuffer[(i - 1)];
i--;
};
keyBuffer[0] = [e.keyCode, 0];
}
public function mouseRelease(e:MouseEvent):void{
mouseDown = false;
mouseReleased = true;
}
public function mousePress(e:MouseEvent):void{
mousePressed = true;
mouseDown = true;
mouseDragX = 0;
mouseDragY = 0;
}
public static function getKeyHold(k:int):int{
return (Math.max(0, keyState[k]));
}
public static function update():void{
var i:int;
while (i < keyArr.length) {
if (keyState[keyArr[i]] != 0){
var _local3 = keyState;
var _local4 = keyArr[i];
var _local5 = (_local3[_local4] + 1);
_local3[_local4] = _local5;
};
i++;
};
var j:int;
while (j < bufferSize) {
_local3 = keyBuffer[j];
_local4 = 1;
_local5 = (_local3[_local4] + 1);
_local3[_local4] = _local5;
j++;
};
mouseReleased = false;
mousePressed = false;
mouseOver = false;
}
public static function isKeyPressed(k:int):Boolean{
timeSinceLastKey = 0;
return ((keyState[k] == 1));
}
public static function isKeyDown(k:int):Boolean{
return ((keyState[k] > 0));
}
public static function getKeyString(k:uint):String{
return (ascii[k]);
}
public static function isKeyReleased(k:int):Boolean{
return ((keyState[k] == -1));
}
public static function isKeyInBuffer(k:int, i:int, t:int):Boolean{
return ((((keyBuffer[i][0] == k)) && ((keyBuffer[i][1] <= t))));
}
}
}//package General
Section 101
//LevelPack (General.LevelPack)
package General {
import flash.events.*;
import flash.display.*;
import org.flashdevelop.utils.*;
import flash.filters.*;
public class LevelPack extends Sprite {
private var mm:Class;
public var par:Main;
private var total:int;// = 29
public var targetZ:int;// = 0
private var buttonsActive:Boolean;// = true
private var passed:Array;
public var texture:Class;
public var cubes:Array;
private var menu:MovieClip;
public function LevelPack():void{
texture = LevelPack_texture;
mm = LevelPack_mm;
cubes = new Array();
super();
if (stage){
init();
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
private function loadLevel(e:Event):void{
if (buttonsActive){
buttonsActive = false;
par.loadLevel(e.target.parent.n);
par.removeChild(this);
};
}
private function loadMainMenu(e:Event=null):void{
if (buttonsActive){
buttonsActive = false;
FlashConnect.atrace("loading main menu");
par.loadMainMenu();
par.removeChild(this);
};
}
public function init(e:Event=null):void{
var newCube1:Cube;
passed = (parent as Main).shar.passed;
FlashConnect.atrace(passed);
var i:int;
while (i < (total - 1)) {
newCube1 = new Cube(0, 0, 0, (190 + (Math.floor((i % 5)) * 70)), (180 + (Math.round(((i / 5) + 0.5)) * 50)), 0, ((26 + (Math.random() * 5)) + ((total - i) / 1.5)), texture, (4 + i), this.parent);
addChild(newCube1);
newCube1.n = i;
cubes.push({obj:newCube1, dx:0.1, dy:-0.5, dz:0.2});
newCube1.filters = [new GlowFilter(0xFF6600, 1, 10, 10, 1)];
if (passed[i] != 0){
newCube1.filters = [new GlowFilter(0x66FF00, 1, 10, 10, 1)];
};
newCube1.addEventListener(MouseEvent.MOUSE_OVER, omo1);
newCube1.addEventListener(MouseEvent.MOUSE_OUT, omot1);
newCube1.addEventListener(MouseEvent.CLICK, loadLevel);
i++;
};
newCube1 = new Cube(0, 0, 0, 60, 600, 27, 38, texture, 35, this.parent);
addChild(newCube1);
cubes.push({obj:newCube1, dx:(Math.random() - 0.5), dy:(Math.random() - 0.5), dz:(Math.random() - 0.5)});
newCube1.filters = [new GlowFilter(0, 0, 0, 0, 0)];
newCube1.addEventListener(MouseEvent.MOUSE_OVER, omo1);
newCube1.addEventListener(MouseEvent.MOUSE_OUT, omot1);
newCube1.addEventListener(MouseEvent.CLICK, loadMainMenu);
var mmm:* = new mm();
this.menu = (addChild(mmm) as MovieClip);
par = (parent as Main);
}
private function omo1(e:Event):void{
if (passed[e.target.parent.n] == 0){
e.target.parent.filters = [new GlowFilter(0xFF6600, 1, 13, 13, 2)];
} else {
e.target.parent.filters = [new GlowFilter(0x66FF00, 1, 13, 13, 2)];
};
}
private function omot1(e:Event):void{
if (passed[e.target.parent.n] == 0){
e.target.parent.filters = [new GlowFilter(0xFF6600, 1, 10, 10, 1)];
} else {
e.target.parent.filters = [new GlowFilter(0x66FF00, 1, 10, 10, 1)];
};
}
}
}//package General
Section 102
//LevelPack_mm (General.LevelPack_mm)
package General {
import flash.display.*;
import mx.core.*;
public class LevelPack_mm extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 103
//LevelPack_texture (General.LevelPack_texture)
package General {
import flash.display.*;
import mx.core.*;
public class LevelPack_texture extends MovieClipAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package General
Section 104
//Levels (General.Levels)
package General {
import Box2D.Dynamics.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
public class Levels {
public function Levels(){
super();
}
private static function setBox(target:Main):void{
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;
bodyDef = new b2BodyDef();
boxDef = new b2PolygonDef();
bodyDef.position.Set(0, -62.5);
bodyDef.angle = 0;
boxDef.SetAsBox(30, 2);
boxDef.friction = 0;
boxDef.density = 0;
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
bodyDef = new b2BodyDef();
bodyDef.position.Set(-1, -20.2);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(1, 40);
boxDef.friction = 0.3;
boxDef.density = 0;
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
bodyDef = new b2BodyDef();
bodyDef.position.Set(22.3, -20.2);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(1, 40);
boxDef.friction = 0.3;
boxDef.density = 0;
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
}
public static function getLevel(n:int, target:Main):void{
var body:b2Body;
var bodyDef:b2BodyDef;
var boxDef:b2PolygonDef;
var circleDef:b2CircleDef;
var r:Number;
var triangleDef:b2PolygonDef;
var i:int;
var rX:Number;
var rY:Number;
var incr:Number;
var randomseed:Number;
var barDef:b2PolygonDef;
var n = n;
var target = target;
var setMassZero:Function = function (bb:b2Body):void{
bb.SetMass(new b2MassData());
};
switch (n){
case 27:
target.rl.y = -475;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 12) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((i * 1.5) + 3);
bodyDef.position.y = ((Math.random() * 3) - 20);
rX = 0.5;
rY = 2.5;
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 10) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-(i) * 2) + 5);
bodyDef.userData = new target.Lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0.5);
barDef.vertices[1].Set(0.5, 0.5);
barDef.vertices[2].Set(0.5, 2);
barDef.vertices[3].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1.5, 0.5);
barDef.vertices[1].Set(2.5, 0.5);
barDef.vertices[2].Set(2.5, 2);
barDef.vertices[3].Set(1.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0.5, 0);
barDef.vertices[1].Set(1.5, 0);
barDef.vertices[2].Set(1.5, 1.5);
barDef.vertices[3].Set(0.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(2.5, 0);
barDef.vertices[1].Set(3.5, 0);
barDef.vertices[2].Set(3.5, 1.5);
barDef.vertices[3].Set(2.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(3.5, 0.5);
barDef.vertices[1].Set(4, 0.5);
barDef.vertices[2].Set(4, 2);
barDef.vertices[3].Set(3.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 18:
target.rl.y = 30;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 10) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((Math.random() * 40) - 20);
bodyDef.userData = new target.L_lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 0);
barDef.vertices[2].Set(2, 1);
barDef.vertices[3].Set(0, 1);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 1);
barDef.vertices[1].Set(2, 1);
barDef.vertices[2].Set(2, 2);
barDef.vertices[3].Set(1, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 8) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-(i) * 2.5) + 5);
bodyDef.userData = new target.Lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0.5);
barDef.vertices[1].Set(0.5, 0.5);
barDef.vertices[2].Set(0.5, 2);
barDef.vertices[3].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1.5, 0.5);
barDef.vertices[1].Set(2.5, 0.5);
barDef.vertices[2].Set(2.5, 2);
barDef.vertices[3].Set(1.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0.5, 0);
barDef.vertices[1].Set(1.5, 0);
barDef.vertices[2].Set(1.5, 1.5);
barDef.vertices[3].Set(0.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(2.5, 0);
barDef.vertices[1].Set(3.5, 0);
barDef.vertices[2].Set(3.5, 1.5);
barDef.vertices[3].Set(2.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(3.5, 0.5);
barDef.vertices[1].Set(4, 0.5);
barDef.vertices[2].Set(4, 2);
barDef.vertices[3].Set(3.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 0:
target.rl.y = 270;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 1;
while (i < 5) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (1 + (i * 3.5));
rX = ((Math.random() / 1.5) + 1.4);
rY = ((Math.random() / 1.5) + 1.4);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(rX, rY);
boxDef.density = 1;
boxDef.friction = 0.8;
boxDef.restitution = 0.3;
bodyDef.userData = new target.PhysBox();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 3:
target.rl.y = -125;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 6) {
bodyDef = new b2BodyDef();
bodyDef.position.x = (((Math.random() * 5) + 2) + (i * 2));
bodyDef.position.y = (15 - (Math.random() * 5));
rX = (21 / 30);
rY = (96 / 30);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 11:
target.rl.y = -425;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 7) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = ((i * 2) - 15);
rX = (21 / 30);
rY = (96 / 30);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 10) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-3 * i) + 10);
bodyDef.userData = new target.Triangulator2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 2);
barDef.vertices[1].Set(0.5, 2);
barDef.vertices[2].Set(0.5, 3.5);
barDef.vertices[3].Set(0, 3.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 3.5);
barDef.vertices[1].Set(2, 3.5);
barDef.vertices[2].Set(0, 5.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 19:
target.rl.y = 240;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 6) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (((Math.random() * i) * 2) - 10);
r = ((Math.random() / 2) + 1);
circleDef = new b2CircleDef();
circleDef.radius = r;
circleDef.density = 1;
circleDef.friction = 0.9;
circleDef.restitution = 0.2;
bodyDef.userData = new target.PhysCircle();
bodyDef.userData.width = ((r * 2) * 30);
bodyDef.userData.height = ((r * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 6) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-3 * i) + 10);
bodyDef.userData = new target.Triangulator2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 2);
barDef.vertices[1].Set(0.5, 2);
barDef.vertices[2].Set(0.5, 3.5);
barDef.vertices[3].Set(0, 3.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 3.5);
barDef.vertices[1].Set(2, 3.5);
barDef.vertices[2].Set(0, 5.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 15:
target.rl.y = 125;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = ((i * 2) - 10);
rX = (21 / 30);
rY = (96 / 30);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 4) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-3 * i) + 10);
bodyDef.userData = new target.Triangulator2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 2);
barDef.vertices[1].Set(0.5, 2);
barDef.vertices[2].Set(0.5, 3.5);
barDef.vertices[3].Set(0, 3.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 3.5);
barDef.vertices[1].Set(2, 3.5);
barDef.vertices[2].Set(0, 5.5);
barDef.density = 1;
barDef.friction = 0.9;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 28:
target.rl.y = 125;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 10) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-2 * i) + 10);
bodyDef.userData = new target.Triangulator();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.1;
barDef.restitution = 0.03;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 2);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(3, 3);
barDef.vertices[3].Set(1, 3);
barDef.density = 1;
barDef.friction = 0.1;
barDef.restitution = 0.03;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 25:
target.rl.y = 175;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 13) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-2 * i) + 10);
bodyDef.userData = new target.Triangulator();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 2);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(3, 3);
barDef.vertices[3].Set(1, 3);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 14:
target.rl.y = 5;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 7) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
rX = 1.3;
boxDef = new b2PolygonDef();
boxDef.SetAsBox(rX, rX);
boxDef.density = 1;
boxDef.friction = 0.8;
boxDef.restitution = 0.3;
bodyDef.userData = new target.PhysBox();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rX * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 11) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangulator();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 2);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(3, 3);
barDef.vertices[3].Set(1, 3);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 9:
target.rl.y = 175;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
rX = 1.3;
boxDef = new b2PolygonDef();
boxDef.SetAsBox(rX, rX);
boxDef.density = 1;
boxDef.friction = 0.8;
boxDef.restitution = 0.3;
bodyDef.userData = new target.PhysBox();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rX * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 5) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangulator();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 2);
barDef.vertices[1].Set(2, 2);
barDef.vertices[2].Set(3, 3);
barDef.vertices[3].Set(1, 3);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 1:
target.rl.y = -110;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 10) {
bodyDef = new b2BodyDef();
bodyDef.position.x = (((Math.random() * 2) + (((i * 3) * i) % 3)) + 2);
bodyDef.position.y = (15 - (i * 3.5));
rX = ((Math.random() / 2) + 1.2);
rY = ((Math.random() / 2) + 1.2);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(rX, rY);
boxDef.density = 1;
boxDef.friction = 0.8;
boxDef.restitution = 0.3;
bodyDef.userData = new target.PhysBox();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 2:
target.rl.y = 20;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 20) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-(i) + 15);
bodyDef.userData = new target.Brick();
bodyDef.userData.gotoAndStop(((Math.round(Math.random()) * 4) + 1));
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(4, 0);
barDef.vertices[2].Set(4, 1.5);
barDef.vertices[3].Set(0, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 16:
target.rl.y = 170;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 9) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-3 * i);
bodyDef.userData = new target.Brick();
bodyDef.userData.gotoAndStop(((Math.round(Math.random()) * 4) + 1));
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(4, 0);
barDef.vertices[2].Set(4, 1.5);
barDef.vertices[3].Set(0, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 7:
target.rl.y = 0;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 4) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(3, 6);
barDef.vertices[2].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle3();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[2].Set(-3, 6);
barDef.vertices[1].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 26:
target.rl.y = 0;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(3, 6);
barDef.vertices[2].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle3();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[2].Set(-3, 6);
barDef.vertices[1].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 1) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle2();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(3.5, 6);
barDef.vertices[2].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
bodyDef.userData.scaleX = 1.1666;
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 2) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-6 * i);
bodyDef.userData = new target.Triangle3();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[2].Set(-3.5, 6);
barDef.vertices[1].Set(0, 6);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
bodyDef.userData.scaleX = 1.1666;
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 22:
target.rl.y = -225;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 9) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-3 * i);
bodyDef.userData = new target.UTriangle();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set((-55 / 30), (95 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set((-55 / 30), (95 / 30));
barDef.vertices[1].Set(-1, (95 / 30));
barDef.vertices[2].Set(-1, (156 / 30));
barDef.vertices[3].Set(-3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[3].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set(1, (95 / 30));
barDef.vertices[1].Set(1, (156 / 30));
barDef.vertices[0].Set(3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 23:
target.rl.y = -225;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 9) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-3 * i);
bodyDef.userData = new target.UTriangle();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set((-55 / 30), (95 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set((-55 / 30), (95 / 30));
barDef.vertices[1].Set(-1, (95 / 30));
barDef.vertices[2].Set(-1, (156 / 30));
barDef.vertices[3].Set(-3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[3].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set(1, (95 / 30));
barDef.vertices[1].Set(1, (156 / 30));
barDef.vertices[0].Set(3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 17:
target.rl.y = 1;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 7) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = (-3 * i);
bodyDef.userData = new target.UTriangle();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 3;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set((-55 / 30), (95 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set((-55 / 30), (95 / 30));
barDef.vertices[1].Set(-1, (95 / 30));
barDef.vertices[2].Set(-1, (156 / 30));
barDef.vertices[3].Set(-3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[3].Set((55 / 30), (95 / 30));
barDef.vertices[2].Set(1, (95 / 30));
barDef.vertices[1].Set(1, (156 / 30));
barDef.vertices[0].Set(3, (156 / 30));
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 8:
target.rl.y = 5;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 30) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 2);
bodyDef.position.y = (14 - (i * 2));
bodyDef.userData = new target.L_lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 0);
barDef.vertices[2].Set(2, 1);
barDef.vertices[3].Set(0, 1);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 1);
barDef.vertices[1].Set(2, 1);
barDef.vertices[2].Set(2, 2);
barDef.vertices[3].Set(1, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 10:
target.rl.y = 150;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 19) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((Math.random() * 40) - 20);
bodyDef.userData = new target.L_lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0);
barDef.vertices[1].Set(2, 0);
barDef.vertices[2].Set(2, 1);
barDef.vertices[3].Set(0, 1);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1, 1);
barDef.vertices[1].Set(2, 1);
barDef.vertices[2].Set(2, 2);
barDef.vertices[3].Set(1, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 4:
target.rl.y = 305;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 8) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((-(i) * 2.5) + 5);
bodyDef.userData = new target.Lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0.5);
barDef.vertices[1].Set(0.5, 0.5);
barDef.vertices[2].Set(0.5, 2);
barDef.vertices[3].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1.5, 0.5);
barDef.vertices[1].Set(2.5, 0.5);
barDef.vertices[2].Set(2.5, 2);
barDef.vertices[3].Set(1.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0.5, 0);
barDef.vertices[1].Set(1.5, 0);
barDef.vertices[2].Set(1.5, 1.5);
barDef.vertices[3].Set(0.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(2.5, 0);
barDef.vertices[1].Set(3.5, 0);
barDef.vertices[2].Set(3.5, 1.5);
barDef.vertices[3].Set(2.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(3.5, 0.5);
barDef.vertices[1].Set(4, 0.5);
barDef.vertices[2].Set(4, 2);
barDef.vertices[3].Set(3.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 24:
target.rl.y = 5;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 19) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 16) + 1);
bodyDef.position.y = ((Math.random() * 40) - 15);
bodyDef.userData = new target.Lego();
body = target.m_world.CreateBody(bodyDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0, 0.5);
barDef.vertices[1].Set(0.5, 0.5);
barDef.vertices[2].Set(0.5, 2);
barDef.vertices[3].Set(0, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(1.5, 0.5);
barDef.vertices[1].Set(2.5, 0.5);
barDef.vertices[2].Set(2.5, 2);
barDef.vertices[3].Set(1.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(0.5, 0);
barDef.vertices[1].Set(1.5, 0);
barDef.vertices[2].Set(1.5, 1.5);
barDef.vertices[3].Set(0.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(2.5, 0);
barDef.vertices[1].Set(3.5, 0);
barDef.vertices[2].Set(3.5, 1.5);
barDef.vertices[3].Set(2.5, 1.5);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
barDef = new b2PolygonDef();
barDef.vertexCount = 4;
barDef.vertices[0].Set(3.5, 0.5);
barDef.vertices[1].Set(4, 0.5);
barDef.vertices[2].Set(4, 2);
barDef.vertices[3].Set(3.5, 2);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 21:
target.rl.y = 160;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 8) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
r = ((Math.random() / 2) + 1);
circleDef = new b2CircleDef();
circleDef.radius = r;
circleDef.density = 1;
circleDef.friction = 0.8;
circleDef.restitution = 0.2;
bodyDef.userData = new target.PhysCircle();
bodyDef.userData.width = ((r * 2) * 30);
bodyDef.userData.height = ((r * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 2) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
triangleDef = new b2PolygonDef();
triangleDef.vertexCount = 3;
triangleDef.vertices[0].Set(-1.5, 0);
triangleDef.vertices[1].Set(1.5, 0);
triangleDef.vertices[2].Set(0, 3);
triangleDef.density = 1;
triangleDef.friction = 0.8;
triangleDef.restitution = 0.3;
bodyDef.userData = new target.PhysTriangle();
bodyDef.userData.width = (2 * 45);
bodyDef.userData.height = (2 * 45);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(triangleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 20:
target.rl.y = 160;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 0;
while (i < 16) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
r = ((Math.random() / 2) + 1);
circleDef = new b2CircleDef();
circleDef.radius = r;
circleDef.density = 1;
circleDef.friction = 0.8;
circleDef.restitution = 0.2;
bodyDef.userData = new target.PhysCircle();
bodyDef.userData.width = ((r * 2) * 30);
bodyDef.userData.height = ((r * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 1;
while (i < 7) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 6:
target.rl.y = -160;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 1;
while (i < 15) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
triangleDef = new b2PolygonDef();
triangleDef.vertexCount = 3;
triangleDef.vertices[0].Set(-1.5, 0);
triangleDef.vertices[1].Set(1.5, 0);
triangleDef.vertices[2].Set(0, 3);
triangleDef.density = 1;
triangleDef.friction = 0.8;
triangleDef.restitution = 0.3;
bodyDef.userData = new target.PhysTriangle();
bodyDef.userData.width = (2 * 45);
bodyDef.userData.height = (2 * 45);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(triangleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 1;
while (i < 7) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 5:
target.rl.y = 165;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 1;
while (i < 25) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() + 2) + (Math.round((i / 6)) * 4));
bodyDef.position.y = ((15 - (Math.random() * 1)) - (4 * Math.round((i % 8))));
triangleDef = new b2PolygonDef();
incr = ((i / 60) + 0.7);
triangleDef.vertexCount = 3;
triangleDef.vertices[0].Set((-1.5 * incr), 0);
triangleDef.vertices[1].Set((1.5 * incr), 0);
triangleDef.vertices[2].Set(0, (3 * incr));
triangleDef.density = 1;
triangleDef.friction = 0.8;
triangleDef.restitution = 0.3;
bodyDef.userData = new target.PhysTriangle();
bodyDef.userData.width = ((2 * 45) * incr);
bodyDef.userData.height = ((2 * 45) * incr);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(triangleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 12:
target.rl.y = 5;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 1;
while (i < 15) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
break;
case 13:
target.rl.y = 70;
setBox(target);
bodyDef = new b2BodyDef();
bodyDef.position.Set(15, 23);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(21.33, 3);
boxDef.friction = 0.8;
boxDef.density = 0;
bodyDef.userData = new target.PhysGround();
bodyDef.userData.width = (30 * 21.33);
bodyDef.userData.height = (30 * 1.6);
target.addChild(bodyDef.userData);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
i = 1;
while (i < 5) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
rX = ((Math.random() / 2) + 1.2);
rY = ((Math.random() / 2) + 1.2);
boxDef = new b2PolygonDef();
boxDef.SetAsBox(rX, rY);
boxDef.density = 1;
boxDef.friction = 0.8;
boxDef.restitution = 0.3;
bodyDef.userData = new target.PhysBox();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(boxDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 1;
while (i < 5) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
randomseed = (Math.random() / 2);
rX = ((randomseed * 0.45) + 0.45);
rY = ((randomseed * 2) + 2);
barDef = new b2PolygonDef();
barDef.SetAsBox(rX, rY);
barDef.density = 1;
barDef.friction = 0.8;
barDef.restitution = 0.3;
bodyDef.userData = new target.PhysBar();
bodyDef.userData.width = ((rX * 2) * 30);
bodyDef.userData.height = ((rY * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(barDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
i = 0;
while (i < 3) {
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
r = ((Math.random() / 2) + 1);
circleDef = new b2CircleDef();
circleDef.radius = r;
circleDef.density = 1;
circleDef.friction = 0.8;
circleDef.restitution = 0.2;
bodyDef.userData = new target.PhysCircle();
bodyDef.userData.width = ((r * 2) * 30);
bodyDef.userData.height = ((r * 2) * 30);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(circleDef);
body.SetMassFromShapes();
body.PutToSleep();
target.addRigid(bodyDef.userData);
i = (i + 1);
};
bodyDef = new b2BodyDef();
bodyDef.position.x = ((Math.random() * 15) + 5);
bodyDef.position.y = (Math.random() * 10);
triangleDef = new b2PolygonDef();
triangleDef.vertexCount = 3;
triangleDef.vertices[0].Set(-1.5, 0);
triangleDef.vertices[1].Set(1.5, 0);
triangleDef.vertices[2].Set(0, 3);
triangleDef.density = 1;
triangleDef.friction = 0.8;
triangleDef.restitution = 0.3;
bodyDef.userData = new target.PhysTriangle();
bodyDef.userData.width = (2 * 45);
bodyDef.userData.height = (2 * 45);
body = target.m_world.CreateBody(bodyDef);
body.CreateShape(triangleDef);
body.SetMassFromShapes();
target.addRigid(bodyDef.userData);
break;
};
}
}
}//package General
Section 105
//QFace (General.QFace)
package General {
import flash.display.*;
import flash.geom.*;
public class QFace extends MovieClip {
public var rx:int;
public var ry:int;
public var rz:int;
public var h:int;
public var w:int;
public var _x:int;
public var _y:int;
public var _z:int;
public function QFace(rx:int, ry:int, rz:int, _x:int, _y:int, _z:int, w:int, h:int, texture:Class, frame:int){
var bitmap:BitmapData;
var mm1:Matrix;
var tex:MovieClip;
var mm2:Matrix;
super();
this.rx = rx;
this.ry = ry;
this.rz = rz;
this.x = _x;
this.y = _y;
this.w = w;
this.h = h;
if (texture == null){
this.graphics.lineStyle(((w + h) / 50), 0xFFFFFF);
this.graphics.beginFill(0);
this.graphics.moveTo((-(w) / 2), (-(h) / 2));
this.graphics.lineTo((w / 2), (-(h) / 2));
this.graphics.lineTo((w / 2), (h / 2));
this.graphics.lineTo((-(w) / 2), (h / 2));
this.graphics.lineTo((-(w) / 2), (-(h) / 2));
this.graphics.endFill();
this.graphics.lineTo((w / 2), (h / 2));
this.graphics.moveTo((w / 2), (-(h) / 2));
this.graphics.lineTo((-(w) / 2), (h / 2));
} else {
bitmap = new BitmapData(w, h, false, 0);
mm1 = new Matrix();
mm1.scale((w / 128), (h / 128));
tex = (new (texture) as MovieClip);
tex.gotoAndStop(frame);
bitmap.draw(tex, mm1);
mm2 = new Matrix();
mm2.translate((-(w) / 2), (-(h) / 2));
this.graphics.beginBitmapFill(bitmap, mm2, false);
this.graphics.moveTo((-(w) / 2), (-(h) / 2));
this.graphics.lineTo((w / 2), (-(h) / 2));
this.graphics.lineTo((w / 2), (h / 2));
this.graphics.lineTo((-(w) / 2), (h / 2));
this.graphics.lineTo((-(w) / 2), (-(h) / 2));
this.graphics.endFill();
};
}
public function rotate(dx:Number, dy:Number, dz:Number):void{
}
public function move(dx:int, dy:int, dz:int):void{
}
}
}//package General
Section 106
//Shar (General.Shar)
package General {
import flash.net.*;
import org.flashdevelop.utils.*;
public class Shar {
public var so:SharedObject;
public function Shar(){
so = SharedObject.getLocal("SpaceBox");
super();
so = SharedObject.getLocal("SpaceBox");
if (so.data.passed == undefined){
so.data.instructionsReaded = false;
so.data.passed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
};
}
public function get passed():Array{
so = SharedObject.getLocal("SpaceBox");
return (so.data.passed);
}
public function get score():int{
so = SharedObject.getLocal("SpaceBox");
var score:int;
var i:int;
while (i < 25) {
if (so.data.passed[i]){
score = (score + so.data.passed[i]);
};
i++;
};
return (score);
}
public function set instructionsReaded(b:Boolean):void{
so = SharedObject.getLocal("SpaceBox");
so.data.instructionsReaded = b;
so.flush();
}
public function setScore(n:int, score:int):void{
so = SharedObject.getLocal("SpaceBox");
so.data.passed[n] = score;
so.flush();
FlashConnect.atrace(((((n + " - ") + score) + " - ") + so.data.passed));
}
public function get instructionsReaded():Boolean{
so = SharedObject.getLocal("SpaceBox");
return (so.data.instructionsReaded);
}
public function reset():void{
so = SharedObject.getLocal("SpaceBox");
so.clear();
so.data.instructionsReaded = false;
so.data.passed = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];
}
}
}//package General
Section 107
//ByteArrayAsset (mx.core.ByteArrayAsset)
package mx.core {
import flash.utils.*;
public class ByteArrayAsset extends ByteArray implements IFlexAsset {
mx_internal static const VERSION:String = "3.3.0.4716";
public function ByteArrayAsset(){
super();
}
}
}//package mx.core
Section 108
//EdgeMetrics (mx.core.EdgeMetrics)
package mx.core {
public class EdgeMetrics {
public var top:Number;
public var left:Number;
public var bottom:Number;
public var right:Number;
mx_internal static const VERSION:String = "3.3.0.4716";
public static const EMPTY:EdgeMetrics = new EdgeMetrics(0, 0, 0, 0);
;
public function EdgeMetrics(left:Number=0, top:Number=0, right:Number=0, bottom:Number=0){
super();
this.left = left;
this.top = top;
this.right = right;
this.bottom = bottom;
}
public function clone():EdgeMetrics{
return (new EdgeMetrics(left, top, right, bottom));
}
}
}//package mx.core
Section 109
//FlexMovieClip (mx.core.FlexMovieClip)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexMovieClip extends MovieClip {
mx_internal static const VERSION:String = "3.3.0.4716";
public function FlexMovieClip(){
super();
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 110
//FlexSprite (mx.core.FlexSprite)
package mx.core {
import flash.display.*;
import mx.utils.*;
public class FlexSprite extends Sprite {
mx_internal static const VERSION:String = "3.3.0.4716";
public function FlexSprite(){
super();
name = NameUtil.createUniqueName(this);
//unresolved jump
var _slot1 = e;
}
override public function toString():String{
return (NameUtil.displayObjectToString(this));
}
}
}//package mx.core
Section 111
//IBorder (mx.core.IBorder)
package mx.core {
public interface IBorder {
function get borderMetrics():EdgeMetrics;
}
}//package mx.core
Section 112
//IFlexAsset (mx.core.IFlexAsset)
package mx.core {
public interface IFlexAsset {
}
}//package mx.core
Section 113
//IFlexDisplayObject (mx.core.IFlexDisplayObject)
package mx.core {
import flash.events.*;
import flash.display.*;
import flash.geom.*;
import flash.accessibility.*;
public interface IFlexDisplayObject extends IBitmapDrawable, IEventDispatcher {
function get visible():Boolean;
function get rotation():Number;
function localToGlobal(void:Point):Point;
function get name():String;
function set width(flash.display:Number):void;
function get measuredHeight():Number;
function get blendMode():String;
function get scale9Grid():Rectangle;
function set name(flash.display:String):void;
function set scaleX(flash.display:Number):void;
function set scaleY(flash.display:Number):void;
function get measuredWidth():Number;
function get accessibilityProperties():AccessibilityProperties;
function set scrollRect(flash.display:Rectangle):void;
function get cacheAsBitmap():Boolean;
function globalToLocal(void:Point):Point;
function get height():Number;
function set blendMode(flash.display:String):void;
function get parent():DisplayObjectContainer;
function getBounds(String:DisplayObject):Rectangle;
function get opaqueBackground():Object;
function set scale9Grid(flash.display:Rectangle):void;
function setActualSize(_arg1:Number, _arg2:Number):void;
function set alpha(flash.display:Number):void;
function set accessibilityProperties(flash.display:AccessibilityProperties):void;
function get width():Number;
function hitTestPoint(_arg1:Number, _arg2:Number, _arg3:Boolean=false):Boolean;
function set cacheAsBitmap(flash.display:Boolean):void;
function get scaleX():Number;
function get scaleY():Number;
function get scrollRect():Rectangle;
function get mouseX():Number;
function get mouseY():Number;
function set height(flash.display:Number):void;
function set mask(flash.display:DisplayObject):void;
function getRect(String:DisplayObject):Rectangle;
function get alpha():Number;
function set transform(flash.display:Transform):void;
function move(_arg1:Number, _arg2:Number):void;
function get loaderInfo():LoaderInfo;
function get root():DisplayObject;
function hitTestObject(mx.core:IFlexDisplayObject/mx.core:IFlexDisplayObject:stage/get:DisplayObject):Boolean;
function set opaqueBackground(flash.display:Object):void;
function set visible(flash.display:Boolean):void;
function get mask():DisplayObject;
function set x(flash.display:Number):void;
function set y(flash.display:Number):void;
function get transform():Transform;
function set filters(flash.display:Array):void;
function get x():Number;
function get y():Number;
function get filters():Array;
function set rotation(flash.display:Number):void;
function get stage():Stage;
}
}//package mx.core
Section 114
//IRepeaterClient (mx.core.IRepeaterClient)
package mx.core {
public interface IRepeaterClient {
function get instanceIndices():Array;
function set instanceIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get isDocument():Boolean;
function set repeaters(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function initializeRepeaterArrays(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:IRepeaterClient):void;
function get repeaters():Array;
function set repeaterIndices(C:\autobuild\3.3.0\frameworks\projects\framework\src;mx\core;IRepeaterClient.as:Array):void;
function get repeaterIndices():Array;
}
}//package mx.core
Section 115
//MovieClipAsset (mx.core.MovieClipAsset)
package mx.core {
public class MovieClipAsset extends FlexMovieClip implements IFlexAsset, IFlexDisplayObject, IBorder {
private var _measuredHeight:Number;
private var _measuredWidth:Number;
mx_internal static const VERSION:String = "3.3.0.4716";
public function MovieClipAsset(){
super();
_measuredWidth = width;
_measuredHeight = height;
}
public function get measuredWidth():Number{
return (_measuredWidth);
}
public function get measuredHeight():Number{
return (_measuredHeight);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
public function get borderMetrics():EdgeMetrics{
if (scale9Grid == null){
return (EdgeMetrics.EMPTY);
};
return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom))));
}
}
}//package mx.core
Section 116
//mx_internal (mx.core.mx_internal)
package mx.core {
public namespace mx_internal = "http://www.adobe.com/2006/flex/mx/internal";
}//package mx.core
Section 117
//SoundAsset (mx.core.SoundAsset)
package mx.core {
import flash.media.*;
public class SoundAsset extends Sound implements IFlexAsset {
mx_internal static const VERSION:String = "3.3.0.4716";
public function SoundAsset(){
super();
}
}
}//package mx.core
Section 118
//SpriteAsset (mx.core.SpriteAsset)
package mx.core {
public class SpriteAsset extends FlexSprite implements IFlexAsset, IFlexDisplayObject, IBorder {
private var _measuredHeight:Number;
private var _measuredWidth:Number;
mx_internal static const VERSION:String = "3.3.0.4716";
public function SpriteAsset(){
super();
_measuredWidth = width;
_measuredHeight = height;
}
public function get measuredWidth():Number{
return (_measuredWidth);
}
public function get measuredHeight():Number{
return (_measuredHeight);
}
public function setActualSize(newWidth:Number, newHeight:Number):void{
width = newWidth;
height = newHeight;
}
public function move(x:Number, y:Number):void{
this.x = x;
this.y = y;
}
public function get borderMetrics():EdgeMetrics{
if (scale9Grid == null){
return (EdgeMetrics.EMPTY);
};
return (new EdgeMetrics(scale9Grid.left, scale9Grid.top, Math.ceil((measuredWidth - scale9Grid.right)), Math.ceil((measuredHeight - scale9Grid.bottom))));
}
}
}//package mx.core
Section 119
//NameUtil (mx.utils.NameUtil)
package mx.utils {
import flash.display.*;
import mx.core.*;
import flash.utils.*;
public class NameUtil {
mx_internal static const VERSION:String = "3.3.0.4716";
private static var counter:int = 0;
public function NameUtil(){
super();
}
public static function displayObjectToString(displayObject:DisplayObject):String{
var result:String;
var o:DisplayObject;
var s:String;
var indices:Array;
var displayObject = displayObject;
o = displayObject;
while (o != null) {
if (((((o.parent) && (o.stage))) && ((o.parent == o.stage)))){
break;
};
s = o.name;
if ((o is IRepeaterClient)){
indices = IRepeaterClient(o).instanceIndices;
if (indices){
s = (s + (("[" + indices.join("][")) + "]"));
};
};
result = ((result == null)) ? s : ((s + ".") + result);
o = o.parent;
};
//unresolved jump
var _slot1 = e;
return (result);
}
public static function createUniqueName(object:Object):String{
if (!object){
return (null);
};
var name:String = getQualifiedClassName(object);
var index:int = name.indexOf("::");
if (index != -1){
name = name.substr((index + 2));
};
var charCode:int = name.charCodeAt((name.length - 1));
if ((((charCode >= 48)) && ((charCode <= 57)))){
name = (name + "_");
};
return ((name + counter++));
}
}
}//package mx.utils
Section 120
//FlashConnect (org.flashdevelop.utils.FlashConnect)
package org.flashdevelop.utils {
import flash.events.*;
import flash.utils.*;
import flash.xml.*;
import flash.net.*;
public class FlashConnect {
public static var onReturnData:Function;
public static var port:Number = 1978;
private static var interval:Number;
private static var messages:Array;
public static var onConnection:Function;
public static var host:String = "localhost";
public static var status:Number = 0;
private static var socket:XMLSocket;
public static var limit:Number = 1000;
private static var counter:Number;
public function FlashConnect(){
super();
}
private static function onIOError(event:IOErrorEvent):void{
FlashConnect.status = -1;
if (FlashConnect.onConnection != null){
FlashConnect.onConnection();
};
}
public static function atrace(... _args):void{
var result:String = _args.join(",");
var message:XMLNode = createMsgNode(result, TraceLevel.DEBUG);
FlashConnect.send(message);
}
private static function createMsgNode(message:String, level:Number):XMLNode{
if (isNaN(level)){
level = TraceLevel.DEBUG;
};
var msgNode:XMLNode = new XMLNode(1, null);
var txtNode:XMLNode = new XMLNode(3, encodeURI(message));
msgNode.attributes.state = level.toString();
msgNode.attributes.cmd = "trace";
msgNode.nodeName = "message";
msgNode.appendChild(txtNode);
return (msgNode);
}
public static function send(message:XMLNode):void{
if (messages == null){
initialize();
};
messages.push(message);
}
private static function onSecurityError(event:SecurityErrorEvent):void{
FlashConnect.status = -1;
if (FlashConnect.onConnection != null){
FlashConnect.onConnection();
};
}
private static function onConnect(event:Event):void{
FlashConnect.status = 1;
if (FlashConnect.onConnection != null){
FlashConnect.onConnection();
};
}
public static function trace(value:Object, level:Number=1):void{
var msgNode:XMLNode = createMsgNode(value.toString(), level);
FlashConnect.send(msgNode);
}
private static function initialize():void{
counter = 0;
messages = new Array();
socket = new XMLSocket();
socket.addEventListener(DataEvent.DATA, onData);
socket.addEventListener(Event.CONNECT, onConnect);
socket.addEventListener(IOErrorEvent.IO_ERROR, onIOError);
socket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, onSecurityError);
interval = setInterval(sendStack, 50);
socket.connect(host, port);
}
private static function sendStack():void{
var message:XMLDocument;
var rootNode:XMLNode;
var msg:String;
var errorNode:XMLNode;
var msgNode:XMLNode;
if ((((messages.length > 0)) && ((status == 1)))){
message = new XMLDocument();
rootNode = message.createElement("flashconnect");
while (messages.length != 0) {
counter++;
if (counter > limit){
clearInterval(interval);
msg = new String("FlashConnect aborted. You have reached the limit of maximum messages.");
errorNode = createMsgNode(msg, TraceLevel.ERROR);
rootNode.appendChild(errorNode);
break;
} else {
msgNode = XMLNode(messages.shift());
rootNode.appendChild(msgNode);
};
};
message.appendChild(rootNode);
socket.send(message);
};
}
private static function onData(event:DataEvent):void{
FlashConnect.status = 1;
if (FlashConnect.onReturnData != null){
FlashConnect.onReturnData(event.data);
};
}
public static function mtrace(value:Object, method:String, path:String, line:Number):void{
var fixed:String = path.split("/").join("\\");
var formatted:String = ((((fixed + ":") + line) + ":") + value);
FlashConnect.trace(formatted, TraceLevel.DEBUG);
}
}
}//package org.flashdevelop.utils
Section 121
//TraceLevel (org.flashdevelop.utils.TraceLevel)
package org.flashdevelop.utils {
public class TraceLevel {
public static const DEBUG:Number = 1;
public static const FATAL:Number = 4;
public static const WARNING:Number = 2;
public static const INFO:Number = 0;
public static const ERROR:Number = 3;
public function TraceLevel(){
super();
}
}
}//package org.flashdevelop.utils
Section 122
//Main (Main)
package {
import flash.events.*;
import flash.display.*;
import Box2D.Dynamics.*;
import flash.geom.*;
import flash.utils.*;
import Box2D.Dynamics.Joints.*;
import Box2D.Common.Math.*;
import Box2D.Collision.Shapes.*;
import Box2D.Collision.*;
import flash.text.*;
import General.*;
import fmd.*;
import fmd.flash.*;
import flash.media.*;
import org.flashdevelop.utils.*;
import flash.filters.*;
public class Main extends MovieClip {
public var redline:Class;
public var m_mouseJoint:b2MouseJoint;
private var bodiesHeight:int;// = 0
private var maxFixedScore:int;// = 0
public var Triangle2:Class;
public var Triangle3:Class;
public var m_physScale:Number;// = 30
private var clock:MovieClip;
public var m_timeDefStep:Number;// = 0.0333333333333333
private var targetHeight:int;// = 80
public var Triangulator2:Class;
public var Brick:Class;
public var stg:Stage;
public var L_lego:Class;
public var cube:D3Cube;
public var PhysBox:Class;
public var rl:DisplayObject;
public var m_bomb:b2Body;
public var dataloader:MovieClip;
public var m_world:b2World;
public var Lego:Class;
public var IngameInterface:Class;
private var bg:DisplayObject;
public var shar:Shar;
public var m_iterations:int;// = 10
private var initY:int;// = 0
public var cursor:Cursor;
private var constructionHeight:int;// = 0
public var PhysGround:Class;
public var PhysTriangle:Class;
private var mousePVec:b2Vec2;
private var rigidsList:Array;
private var caution:Sprite;
public var PreloaderMC:Class;
private var levelScore:int;// = 0
public var BackGround:Class;
public var greenline:Class;
public var Ingamehelp:Class;
public var UTriangle:Class;
private var bound:Rectangle;
private var m_input:Input;
public var PhysBar:Class;
private var scoreTF:TextField;
private var isDraggin:Boolean;// = false
public var Triangulator:Class;
public var PhysCircle:Class;
private var mp:ModPlayer;
public var m_DefIterations:int;// = 10
public var currentlevel:int;// = 0
private var readyButton;
private var ssButton;
public var m_timeStep:Number;// = 0.0333333333333333
private var forced:Boolean;// = false
private var gl:DisplayObject;
private var targetY:int;// = 0
private var nextLevelButton;
private var inter;
private var hlp;
public var CautionSprite:Class;
public var YOUNEEDFP10:Class;
public static var mouseYWorld:Number;
public static var mouseYWorldPhys:Number;
public static var mouseXWorldPhys:Number;
public static var soundEnabled:Boolean = true;
public static var hitsound:Class = Main_hitsound;
private static var lastKnock:int = 50;
public static var mouseXWorld:Number;
public function Main(stg:Stage){
PreloaderMC = Main_PreloaderMC;
BackGround = Main_BackGround;
PhysGround = Main_PhysGround;
PhysCircle = Main_PhysCircle;
PhysBox = Main_PhysBox;
PhysBar = Main_PhysBar;
PhysTriangle = Main_PhysTriangle;
redline = Main_redline;
greenline = Main_greenline;
IngameInterface = Main_IngameInterface;
CautionSprite = Main_CautionSprite;
Lego = Main_Lego;
L_lego = Main_L_lego;
UTriangle = Main_UTriangle;
Triangle2 = Main_Triangle2;
Triangle3 = Main_Triangle3;
Brick = Main_Brick;
Triangulator = Main_Triangulator;
Triangulator2 = Main_Triangulator2;
Ingamehelp = Main_Ingamehelp;
YOUNEEDFP10 = Main_YOUNEEDFP10;
rigidsList = new Array();
cursor = new Cursor(this);
shar = new Shar();
mousePVec = new b2Vec2();
super();
this.stg = stg;
if (stage){
init(null);
} else {
addEventListener(Event.ADDED_TO_STAGE, init);
};
}
public function init(e:Event):void{
dataloader = new PreloaderMC();
dataloader.x = (dataloader.y = 320);
new Boot(this);
mp = new ModPlayer();
mp.onProgress = MODProgress;
mp.test();
MochiBot.track(this, "97cad2b5");
m_input = new Input((this as MovieClip));
var m_sprite:Sprite = new Sprite();
addChild(m_sprite);
addEventListener(Event.ENTER_FRAME, Update, false, 0, true);
var worldAABB:b2AABB = new b2AABB();
worldAABB.lowerBound.Set(-100, -100);
worldAABB.upperBound.Set(100, 100);
var gravity:b2Vec2 = new b2Vec2(0, 10);
var doSleep:Boolean;
m_world = new b2World(worldAABB, gravity, doSleep);
m_world.SetContactListener(new b2ContactListener());
bg = (new BackGround() as DisplayObject);
addChild(bg);
addChild(dataloader);
rl = addChild(new redline());
rl.visible = false;
rl.y = targetHeight;
gl = addChild(new greenline());
gl.x = 640;
gl.visible = false;
cube = new D3Cube();
addChild(cube);
inter = new IngameInterface();
addChild(inter);
readyButton = inter.getChildByName("readyButton");
readyButton.visible = false;
ssButton = inter.getChildByName("submitscore");
ssButton.visible = false;
nextLevelButton = inter.getChildByName("nextlevel");
nextLevelButton.visible = false;
nextLevelButton.addEventListener(MouseEvent.CLICK, nextLevelHandler);
inter.visible = false;
scoreTF = inter.getChildByName("scoreview");
clock = inter.getChildByName("clock");
clock.visible = false;
inter.getChildByName("soundInd").visible = !(soundEnabled);
inter.getChildByName("soundInd").mouseChildren = false;
inter.getChildByName("soundInd").mouseEnabled = false;
inter.getChildByName("reset").addEventListener(MouseEvent.CLICK, resetLevel);
inter.getChildByName("toggleSound").addEventListener(MouseEvent.CLICK, toggleSound);
scoreTF.text = "0";
caution = new Sprite();
caution = new CautionSprite();
caution.visible = false;
addChild(caution);
readyButton.addEventListener(MouseEvent.CLICK, readyHandler);
addChild(cursor);
}
private function hideReadyButton():void{
readyButton.visible = false;
}
public function loadLevels():void{
addChild(new LevelPack());
inter.visible = (gl.visible = (rl.visible = false));
nextLevelButton.visible = (ssButton.visible = false);
addChild(cursor);
y = 0;
}
public function addRigid(rigid:DisplayObject):void{
addChild(rigid);
rigidsList.push(rigid);
}
public function GetBodyAtMouse(includeStatic:Boolean=false):b2Body{
var tShape:b2Shape;
var inside:Boolean;
mousePVec.Set(mouseXWorldPhys, mouseYWorldPhys);
var aabb:b2AABB = new b2AABB();
aabb.lowerBound.Set((mouseXWorldPhys - 0.001), (mouseYWorldPhys - 0.001));
aabb.upperBound.Set((mouseXWorldPhys + 0.001), (mouseYWorldPhys + 0.001));
var k_maxCount = 10;
var shapes:Array = new Array();
var count:int = m_world.Query(aabb, shapes, k_maxCount);
var body:b2Body;
var i:int;
while (i < count) {
if ((((shapes[i].GetBody().IsStatic() == false)) || (includeStatic))){
tShape = (shapes[i] as b2Shape);
inside = tShape.TestPoint(tShape.GetBody().GetXForm(), mousePVec);
if (inside){
body = tShape.GetBody();
body.usedInGame = true;
body.SetMassFromShapes();
break;
};
};
i++;
};
return (body);
}
private function toggleSound(e:Event=null):void{
soundEnabled = !(soundEnabled);
if (soundEnabled){
mp.playBytes((new mp.musicdata() as ByteArray));
} else {
mp.stop();
};
inter.getChildByName("soundInd").visible = !(soundEnabled);
}
private function readyHandler(e:Event=null):void{
forced = true;
clock.vidible = true;
clock.gotoAndPlay(1);
readyButton.visible = false;
}
private function MODProgress(prg:int):void{
if (prg < 100){
dataloader.visible = true;
addChild(dataloader);
dataloader.gotoAndStop((1 + Math.round((prg / 5.3))));
} else {
dataloader.visible = false;
};
}
public function loadLevel(n:int):void{
currentlevel = n;
Levels.getLevel(n, this);
maxFixedScore = shar.passed[n];
scoreTF.text = String(maxFixedScore);
inter.visible = (rl.visible = (gl.visible = true));
addChild(inter);
addChild(cursor);
targetY = 0;
inter.y = -(y);
bg.y = (-(y) / 3);
if (!new Shar().instructionsReaded){
hlp = new Ingamehelp();
addChild(hlp);
addChild(cursor);
hlp.getChildByName("creditstext").addEventListener(MouseEvent.CLICK, closeHelp);
};
}
private function getHeight():int{
var f:Boolean;
var h = 640;
var bh = 640;
var cv:Boolean;
var cx:int;
var cy:int;
var bb:b2Body = m_world.m_bodyList;
while (bb) {
if ((((bb.m_userData is Sprite)) && (!((getQualifiedClassName(bb.m_userData) == "Main_PhysGround"))))){
if (bb.usedInGame){
f = false;
bound = bb.m_userData.getBounds(this);
bb.m_userData.filters = [];
if (bound.y < h){
h = bound.y;
};
if (bound.x < 10){
bb.m_userData.filters = [new GlowFilter()];
cx = 7;
cy = bb.m_userData.y;
cv = true;
f = true;
};
if ((bound.x + bound.width) > 630){
bb.m_userData.filters = [new GlowFilter()];
cx = 633;
cy = bb.m_userData.y;
cv = true;
f = true;
};
if (((f) && ((bb.m_userData.filters.length == 0)))){
bb.m_userData.filters = [new GlowFilter()];
};
if (((!(f)) && ((bb.m_userData.filters.length == 1)))){
bb.m_userData.filters = [];
};
} else {
bound = bb.m_userData.getBounds(this);
if (bound.y < bh){
bh = bound.y;
};
};
};
bb = bb.m_next;
};
if (caution.x != cx){
caution.x = cx;
};
if (caution.y != cy){
caution.y = cy;
};
if (caution.visible != cv){
caution.visible = cv;
};
bodiesHeight = bh;
return (h);
}
public function loadHelp():void{
addChild(new Help());
inter.visible = (gl.visible = (rl.visible = false));
addChild(cursor);
}
public function MouseDrag():void{
var body:b2Body;
var md:b2MouseJointDef;
var p2:b2Vec2;
if (((Input.mouseDown) && (!(m_mouseJoint)))){
body = GetBodyAtMouse();
if (body){
md = new b2MouseJointDef();
md.body1 = m_world.GetGroundBody();
md.body2 = body;
md.target.Set(mouseXWorldPhys, mouseYWorldPhys);
md.maxForce = (300 * body.GetMass());
md.timeStep = m_timeStep;
m_mouseJoint = (m_world.CreateJoint(md) as b2MouseJoint);
body.WakeUp();
} else {
if (!isDraggin){
initY = (y - cursor.y);
isDraggin = true;
};
targetY = (initY + cursor.y);
};
} else {
isDraggin = false;
};
if (!Input.mouseDown){
if (m_mouseJoint){
m_world.DestroyJoint(m_mouseJoint);
m_mouseJoint = null;
};
};
if (((m_mouseJoint) && (!(isDraggin)))){
p2 = new b2Vec2(mouseXWorldPhys, mouseYWorldPhys);
m_mouseJoint.SetTarget(p2);
};
if ((((((targetY < 1500)) && ((stage.mouseY < 30)))) && (m_mouseJoint))){
targetY = (targetY + 3);
};
if ((((((targetY > -2500)) && ((stage.mouseY > 600)))) && (m_mouseJoint))){
targetY = (targetY - 3);
};
}
public function closeHelp(e:Event=null):void{
new Shar().instructionsReaded = true;
trace(new Shar().instructionsReaded);
removeChild(hlp);
}
private function resetLevel(e:Event=null):void{
var e = e;
shar.setScore(currentlevel, maxFixedScore);
maxFixedScore = 0;
var bb:b2Body = m_world.m_bodyList;
while (bb) {
if ((bb.m_userData is Sprite)){
try {
removeChild(bb.m_userData);
} catch(e) {
};
};
try {
m_world.DestroyBody(bb);
} catch(e) {
};
bb = bb.m_next;
};
rigidsList = new Array();
loadLevel(currentlevel);
}
private function showReadyButton():void{
if (((((((!(forced)) && (!(Input.mouseDown)))) && ((constructionHeight < rl.y)))) && (!(caution.visible)))){
readyButton.visible = true;
};
}
public function UpdateMouseWorld():void{
mouseXWorldPhys = (Input.mouseX / m_physScale);
mouseYWorldPhys = (Input.mouseY / m_physScale);
mouseXWorld = Input.mouseX;
mouseYWorld = Input.mouseY;
}
public function MouseDestroy():void{
var body:b2Body;
if (((!(Input.mouseDown)) && (Input.isKeyPressed(68)))){
body = GetBodyAtMouse(true);
if (body){
m_world.DestroyBody(body);
return;
};
};
}
public function loadMainMenu():void{
inter.visible = (gl.visible = (rl.visible = false));
this.cube.visible = true;
this.cube.buttonsActive = true;
addChild(cursor);
}
private function nextLevelHandler(e:Event=null):void{
var e = e;
shar.setScore(currentlevel, maxFixedScore);
maxFixedScore = 0;
var bb:b2Body = m_world.m_bodyList;
for (;bb;(bb = bb.m_next)) {
if ((bb.m_userData is Sprite)){
removeChild(bb.m_userData);
};
m_world.DestroyBody(bb);
continue;
var _slot1 = e;
};
rigidsList = new Array();
loadLevels();
}
public function loadCredits():void{
addChild(new Credits());
inter.visible = (gl.visible = (rl.visible = false));
addChild(cursor);
}
public function Update(e:Event):void{
scoreTF.text = String(maxFixedScore);
if (lastKnock){
lastKnock--;
};
Input.update();
UpdateMouseWorld();
MouseDestroy();
MouseDrag();
m_world.Step(m_timeStep, m_iterations);
caution.visible = false;
var bb:b2Body = m_world.m_bodyList;
while (bb) {
if ((bb.m_userData is Sprite)){
bb.m_userData.x = (bb.GetPosition().x * 30);
bb.m_userData.y = (bb.GetPosition().y * 30);
bb.m_userData.rotation = (bb.GetAngle() * (180 / Math.PI));
};
bb = bb.m_next;
};
constructionHeight = getHeight();
gl.y = constructionHeight;
if ((((((((m_world.GetBodyCount() > 1)) && (Input.mouseDown))) && ((targetY > 0)))) && ((targetY < 1500)))){
y = (y + ((targetY - y) / 2));
} else {
if (m_world.GetBodyCount() <= 1){
y = (y - (y / 30));
};
};
cursor.y = mouseY;
inter.y = -(y);
bg.y = (-(y) / 3);
if ((((((gl.y <= rl.y)) && (!(Input.mouseDown)))) && (!(caution.visible)))){
levelScore = (200 + ((rl.y - gl.y) * 2));
};
var percen:int = ((100 * (rl.y - gl.y)) / (640 - rl.y));
((gl as Sprite).getChildByName("perc") as TextField).text = (percen.toString() + "%");
if ((((((gl.y > rl.y)) || (Input.mouseDown))) || (caution.visible))){
if (readyButton.visible){
forced = false;
levelScore = 0;
};
forced = false;
clock.gotoAndStop(1);
};
if (forced){
m_timeStep = (2 / 30);
m_iterations = 30;
if (clock.currentFrame == clock.totalFrames){
clock.gotoAndStop(1);
forced = false;
if (maxFixedScore < levelScore){
maxFixedScore = levelScore;
scoreTF.text = String(maxFixedScore);
FlashConnect.atrace("LEVEL PASSED");
};
ssButton.visible = true;
nextLevelButton.visible = true;
};
} else {
if (m_timeStep != m_timeDefStep){
m_timeStep = m_timeDefStep;
m_iterations = m_DefIterations;
};
clock.stop();
};
showReadyButton();
clock.visible = forced;
}
public static function hitSound():void{
var s:Sound;
if (((soundEnabled) && (!(lastKnock)))){
s = new hitsound();
s.play();
lastKnock = (lastKnock + (10 + (Math.random() * 15)));
};
}
try {
} catch(e:Error) {
};
}
}//package
Section 123
//Main_BackGround (Main_BackGround)
package {
import flash.display.*;
import mx.core.*;
public class Main_BackGround extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 124
//Main_Brick (Main_Brick)
package {
import flash.display.*;
import mx.core.*;
public class Main_Brick extends MovieClipAsset {
public var perc:DisplayObject;
}
}//package
Section 125
//Main_CautionSprite (Main_CautionSprite)
package {
import flash.display.*;
import mx.core.*;
public class Main_CautionSprite extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 126
//Main_greenline (Main_greenline)
package {
import flash.display.*;
import mx.core.*;
public class Main_greenline extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 127
//Main_hitsound (Main_hitsound)
package {
import flash.display.*;
import mx.core.*;
public class Main_hitsound extends SoundAsset {
public var perc:DisplayObject;
}
}//package
Section 128
//Main_Ingamehelp (Main_Ingamehelp)
package {
import flash.display.*;
import mx.core.*;
public class Main_Ingamehelp extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 129
//Main_IngameInterface (Main_IngameInterface)
package {
import flash.display.*;
import mx.core.*;
public class Main_IngameInterface extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package
Section 130
//Main_L_lego (Main_L_lego)
package {
import flash.display.*;
import mx.core.*;
public class Main_L_lego extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 131
//Main_Lego (Main_Lego)
package {
import flash.display.*;
import mx.core.*;
public class Main_Lego extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 132
//Main_PhysBar (Main_PhysBar)
package {
import flash.display.*;
import mx.core.*;
public class Main_PhysBar extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 133
//Main_PhysBox (Main_PhysBox)
package {
import flash.display.*;
import mx.core.*;
public class Main_PhysBox extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 134
//Main_PhysCircle (Main_PhysCircle)
package {
import flash.display.*;
import mx.core.*;
public class Main_PhysCircle extends SpriteAsset {
public var perc:DisplayObject;
public var creditstext:DisplayObject;
public var reset:DisplayObject;
public var soundInd:DisplayObject;
public var nextlevel:DisplayObject;
public var readyButton:DisplayObject;
public var scoreview:DisplayObject;
public var submitscore:DisplayObject;
public var toggleSound:DisplayObject;
public var clock:DisplayObject;
}
}//package
Section 135
//Main_PhysGround (Main_PhysGround)
package {
import flash.display.*;
import mx.core.*;
public class Main_PhysGround extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 136
//Main_PhysTriangle (Main_PhysTriangle)
package {
import flash.display.*;
import mx.core.*;
public class Main_PhysTriangle extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 137
//Main_PreloaderMC (Main_PreloaderMC)
package {
import flash.display.*;
import mx.core.*;
public class Main_PreloaderMC extends MovieClipAsset {
public var perc:DisplayObject;
}
}//package
Section 138
//Main_redline (Main_redline)
package {
import flash.display.*;
import mx.core.*;
public class Main_redline extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 139
//Main_Triangle2 (Main_Triangle2)
package {
import flash.display.*;
import mx.core.*;
public class Main_Triangle2 extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 140
//Main_Triangle3 (Main_Triangle3)
package {
import flash.display.*;
import mx.core.*;
public class Main_Triangle3 extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 141
//Main_Triangulator (Main_Triangulator)
package {
import flash.display.*;
import mx.core.*;
public class Main_Triangulator extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 142
//Main_Triangulator2 (Main_Triangulator2)
package {
import flash.display.*;
import mx.core.*;
public class Main_Triangulator2 extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 143
//Main_UTriangle (Main_UTriangle)
package {
import flash.display.*;
import mx.core.*;
public class Main_UTriangle extends SpriteAsset {
public var perc:DisplayObject;
}
}//package
Section 144
//Main_YOUNEEDFP10 (Main_YOUNEEDFP10)
package {
import flash.display.*;
import mx.core.*;
public class Main_YOUNEEDFP10 extends SpriteAsset {
public var readyButton:DisplayObject;
public var perc:DisplayObject;
public var creditstext:DisplayObject;
}
}//package
Section 145
//MochiAd (MochiAd)
package {
import flash.events.*;
import flash.display.*;
import flash.utils.*;
import flash.net.*;
import flash.system.*;
public class MochiAd {
public function MochiAd(){
super();
}
public static function getVersion():String{
return ("2.7");
}
public static function showClickAwayAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, regpt:"o", method:"showClickAwayAd", res:"300x250", no_bg:true, ad_started:function ():void{
}, ad_finished:function ():void{
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
var sendHostProgress:Boolean;
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
finished = true;
chk.started = getTimer();
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (this.root == null){
finished = true;
};
if (finished){
delete this.onEnterFrame;
};
};
doOnEnterFrame(chk);
}
public static function _isNetworkAvailable():Boolean{
return (!((Security.sandboxType == "localWithFile")));
}
public static function _allowDomains(server:String):String{
var hostname:String = server.split("/")[2].split(":")[0];
Security.allowDomain("*");
Security.allowDomain(hostname);
Security.allowInsecureDomain("*");
Security.allowInsecureDomain(hostname);
return (hostname);
}
public static function unload(clip:Object):Boolean{
if (((clip.clip) && (clip.clip._mochiad))){
clip = clip.clip;
};
if (clip.origFrameRate != undefined){
clip.stage.frameRate = clip.origFrameRate;
};
if (!clip._mochiad){
return (false);
};
if (clip._mochiad._containerLCName != undefined){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"unload"});
};
if (clip._mochiad.onUnload){
clip._mochiad.onUnload();
};
delete clip._mochiad_loaded;
delete clip._mochiad;
return (true);
}
public static function showInterLevelAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:2000, fadeout_time:250, regpt:"o", method:"showTimedAd", ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showInterLevelAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
options.ad_finished();
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
mc.unloadAd = function ():void{
MochiAd.unload(clip);
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = (msec - 250);
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (!this.parent){
delete this.onEnterFrame;
delete this.fadeFunction;
return;
};
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if (elapsed > chk.ad_timeout){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (finished){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = this.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function _parseOptions(options:Object, defaults:Object):Object{
var k:String;
var pairs:Array;
var i:Number;
var kv:Array;
var optcopy:Object = {};
for (k in defaults) {
optcopy[k] = defaults[k];
};
if (options){
for (k in options) {
optcopy[k] = options[k];
};
};
if (optcopy.clip == undefined){
throw (new Error("MochiAd is missing the 'clip' parameter. This should be a MovieClip, Sprite or an instance of a class that extends MovieClip or Sprite."));
};
options = optcopy.clip.loaderInfo.parameters.mochiad_options;
if (options){
pairs = options.split("&");
i = 0;
while (i < pairs.length) {
kv = pairs[i].split("=");
optcopy[unescape(kv[0])] = unescape(kv[1]);
i++;
};
};
if (optcopy.id == "test"){
trace("[MochiAd] WARNING: Using the MochiAds test identifier, make sure to use the code from your dashboard, not this example!");
};
return (optcopy);
}
public static function _cleanup(mc:Object):void{
var k:String;
var lc:LocalConnection;
var f:Function;
var mc = mc;
if (("lc" in mc)){
lc = mc.lc;
f = function ():void{
lc.client = null;
lc.close();
//unresolved jump
var _slot1 = e;
};
setTimeout(f, 0);
};
var idx:Number = DisplayObjectContainer(mc).numChildren;
while (idx > 0) {
idx = (idx - 1);
DisplayObjectContainer(mc).removeChildAt(idx);
};
for (k in mc) {
delete mc[k];
};
}
public static function load(options:Object):MovieClip{
var clip:Object;
var k:String;
var server:String;
var hostname:String;
var lc:LocalConnection;
var name:String;
var loader:Loader;
var g:Function;
var req:URLRequest;
var v:Object;
var options = options;
var DEFAULTS:Object = {server:"http://x.mochiads.com/srv/1/", method:"load", depth:10333, id:"_UNKNOWN_"};
options = MochiAd._parseOptions(options, DEFAULTS);
options.swfv = 9;
options.mav = MochiAd.getVersion();
clip = options.clip;
if (!MochiAd._isNetworkAvailable()){
return (null);
};
if (clip._mochiad_loaded){
return (null);
};
//unresolved jump
var _slot1 = e;
throw (new Error("MochiAd requires a clip that is an instance of a dynamic class. If your class extends Sprite or MovieClip, you must make it dynamic."));
var depth:Number = options.depth;
delete options.depth;
var mc:MovieClip = createEmptyMovieClip(clip, "_mochiad", depth);
var wh:Array = MochiAd._getRes(options, clip);
options.res = ((wh[0] + "x") + wh[1]);
options.server = (options.server + options.id);
delete options.id;
clip._mochiad_loaded = true;
if (clip.loaderInfo.loaderURL.indexOf("http") == 0){
options.as3_swf = clip.loaderInfo.loaderURL;
};
var lv:URLVariables = new URLVariables();
for (k in options) {
v = options[k];
if (!(v is Function)){
lv[k] = v;
};
};
server = lv.server;
delete lv.server;
hostname = _allowDomains(server);
lc = new LocalConnection();
lc.client = mc;
name = ["", Math.floor(new Date().getTime()), Math.floor((Math.random() * 999999))].join("_");
lc.allowDomain("*", "localhost");
lc.allowInsecureDomain("*", "localhost");
lc.connect(name);
mc.lc = lc;
mc.lcName = name;
lv.lc = name;
lv.st = getTimer();
loader = new Loader();
g = function (ev:Object):void{
ev.target.removeEventListener(ev.type, arguments.callee);
MochiAd.unload(clip);
};
loader.contentLoaderInfo.addEventListener(Event.UNLOAD, g);
req = new URLRequest(((server + ".swf?cacheBust=") + new Date().getTime()));
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
loader.load(req);
mc.addChild(loader);
mc._mochiad_ctr = loader;
return (mc);
}
public static function runMethod(base:Object, methodName:String, argsArray:Array):Object{
var nameArray:Array = methodName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
if (typeof(base[nameArray[i]]) == "function"){
return (base[nameArray[i]].apply(base, argsArray));
};
return (undefined);
}
public static function createEmptyMovieClip(parent:Object, name:String, depth:Number):MovieClip{
var mc:MovieClip = new MovieClip();
if (((false) && (depth))){
parent.addChildAt(mc, depth);
} else {
parent.addChild(mc);
};
parent[name] = mc;
mc["_name"] = name;
return (mc);
}
public static function _getRes(options:Object, clip:Object):Array{
var xy:Array;
var b:Object = clip.getBounds(clip.root);
var w:Number = 0;
var h:Number = 0;
if (typeof(options.res) != "undefined"){
xy = options.res.split("x");
w = parseFloat(xy[0]);
h = parseFloat(xy[1]);
} else {
w = (b.xMax - b.xMin);
h = (b.yMax - b.yMin);
};
if ((((w == 0)) || ((h == 0)))){
w = clip.stage.stageWidth;
h = clip.stage.stageHeight;
};
return ([w, h]);
}
public static function adShowing(mc:Object):void{
mc.origFrameRate = mc.stage.frameRate;
mc.stage.frameRate = 30;
}
public static function getValue(base:Object, objectName:String):Object{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return (undefined);
};
base = base[nameArray[i]];
i++;
};
return (base[nameArray[i]]);
}
public static function rpc(clip:Object, callbackID:Number, arg:Object):void{
var _local4:Object;
var _local5:Object;
switch (arg.id){
case "setValue":
MochiAd.setValue(clip, arg.objectName, arg.value);
break;
case "getValue":
_local4 = MochiAd.getValue(clip, arg.objectName);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local4);
break;
case "runMethod":
_local5 = MochiAd.runMethod(clip, arg.method, arg.args);
clip._mochiad.lc.send(clip._mochiad._containerLCName, "rpcResult", callbackID, _local5);
break;
default:
trace(("[mochiads rpc] unknown rpc id: " + arg.id));
};
}
public static function setValue(base:Object, objectName:String, value:Object):void{
var nameArray:Array = objectName.split(".");
var i:Number = 0;
while (i < (nameArray.length - 1)) {
if ((((base[nameArray[i]] == undefined)) || ((base[nameArray[i]] == null)))){
return;
};
base = base[nameArray[i]];
i++;
};
base[nameArray[i]] = value;
}
public static function showPreGameAd(options:Object):void{
var clip:Object;
var mc:MovieClip;
var chk:MovieClip;
var complete:Boolean;
var unloaded:Boolean;
var sendHostProgress:Boolean;
var fn:Function;
var r:MovieClip;
var options = options;
var DEFAULTS:Object = {ad_timeout:3000, fadeout_time:250, regpt:"o", method:"showPreloaderAd", color:0xFF8A00, background:16777161, outline:13994812, no_progress_bar:false, ad_started:function ():void{
if ((this.clip is MovieClip)){
this.clip.stop();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_finished:function ():void{
if ((this.clip is MovieClip)){
this.clip.play();
} else {
throw (new Error("MochiAd.showPreGameAd requires a clip that is a MovieClip or is an instance of a class that extends MovieClip. If your clip is a Sprite, then you must provide custom ad_started and ad_finished handlers."));
};
}, ad_loaded:function (width:Number, height:Number):void{
}, ad_failed:function ():void{
trace("[MochiAd] Couldn't load an ad, make sure your game's local security sandbox is configured for Access Network Only and that you are not using ad blocking software");
}, ad_skipped:function ():void{
}, ad_progress:function (percent:Number):void{
}};
options = MochiAd._parseOptions(options, DEFAULTS);
if ("c862232051e0a94e1c3609b3916ddb17".substr(0) == "dfeada81ac97cde83665f81c12da7def"){
options.ad_started();
fn = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
return;
};
clip = options.clip;
var ad_msec:Number = 11000;
var ad_timeout:Number = options.ad_timeout;
delete options.ad_timeout;
var fadeout_time:Number = options.fadeout_time;
delete options.fadeout_time;
if (!MochiAd.load(options)){
options.ad_failed();
options.ad_finished();
return;
};
options.ad_started();
mc = clip._mochiad;
mc["onUnload"] = function ():void{
MochiAd._cleanup(mc);
var fn:Function = function ():void{
options.ad_finished();
};
setTimeout(fn, 100);
};
var wh:Array = MochiAd._getRes(options, clip);
var w:Number = wh[0];
var h:Number = wh[1];
mc.x = (w * 0.5);
mc.y = (h * 0.5);
chk = createEmptyMovieClip(mc, "_mochiad_wait", 3);
chk.x = (w * -0.5);
chk.y = (h * -0.5);
var bar:MovieClip = createEmptyMovieClip(chk, "_mochiad_bar", 4);
if (options.no_progress_bar){
bar.visible = false;
delete options.no_progress_bar;
} else {
bar.x = 10;
bar.y = (h - 20);
};
var bar_color:Number = options.color;
delete options.color;
var bar_background:Number = options.background;
delete options.background;
var bar_outline:Number = options.outline;
delete options.outline;
var backing_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 1);
var backing:Object = backing_mc.graphics;
backing.beginFill(bar_background);
backing.moveTo(0, 0);
backing.lineTo((w - 20), 0);
backing.lineTo((w - 20), 10);
backing.lineTo(0, 10);
backing.lineTo(0, 0);
backing.endFill();
var inside_mc:MovieClip = createEmptyMovieClip(bar, "_inside", 2);
var inside:Object = inside_mc.graphics;
inside.beginFill(bar_color);
inside.moveTo(0, 0);
inside.lineTo((w - 20), 0);
inside.lineTo((w - 20), 10);
inside.lineTo(0, 10);
inside.lineTo(0, 0);
inside.endFill();
inside_mc.scaleX = 0;
var outline_mc:MovieClip = createEmptyMovieClip(bar, "_outline", 3);
var outline:Object = outline_mc.graphics;
outline.lineStyle(0, bar_outline, 100);
outline.moveTo(0, 0);
outline.lineTo((w - 20), 0);
outline.lineTo((w - 20), 10);
outline.lineTo(0, 10);
outline.lineTo(0, 0);
chk.ad_msec = ad_msec;
chk.ad_timeout = ad_timeout;
chk.started = getTimer();
chk.showing = false;
chk.last_pcnt = 0;
chk.fadeout_time = fadeout_time;
chk.fadeFunction = function ():void{
var p:Number = (100 * (1 - ((getTimer() - this.fadeout_start) / this.fadeout_time)));
if (p > 0){
this.parent.alpha = (p * 0.01);
} else {
MochiAd.unload(clip);
delete this["onEnterFrame"];
};
};
complete = false;
unloaded = false;
var f:Function = function (ev:Event):void{
ev.target.removeEventListener(ev.type, arguments.callee);
complete = true;
if (unloaded){
MochiAd.unload(clip);
};
};
clip.loaderInfo.addEventListener(Event.COMPLETE, f);
if ((clip.root is MovieClip)){
r = (clip.root as MovieClip);
if (r.framesLoaded >= r.totalFrames){
complete = true;
};
};
mc.unloadAd = function ():void{
unloaded = true;
if (complete){
MochiAd.unload(clip);
};
};
mc.adLoaded = options.ad_loaded;
mc.adSkipped = options.ad_skipped;
mc.adjustProgress = function (msec:Number):void{
var _chk:Object = mc._mochiad_wait;
_chk.server_control = true;
_chk.showing = true;
_chk.started = getTimer();
_chk.ad_msec = msec;
};
mc.rpc = function (callbackID:Number, arg:Object):void{
MochiAd.rpc(clip, callbackID, arg);
};
mc.rpcTestFn = function (s:String):Object{
trace(("[MOCHIAD rpcTestFn] " + s));
return (s);
};
mc.regContLC = function (lc_name:String):void{
mc._containerLCName = lc_name;
};
sendHostProgress = false;
mc.sendHostLoadProgress = function (lc_name:String):void{
sendHostProgress = true;
};
chk["onEnterFrame"] = function ():void{
var total:Number;
if (((!(this.parent)) || (!(this.parent.parent)))){
delete this["onEnterFrame"];
return;
};
var _clip:Object = this.parent.parent.root;
var ad_clip:Object = this.parent._mochiad_ctr;
var elapsed:Number = (getTimer() - this.started);
var finished:Boolean;
var clip_total:Number = _clip.loaderInfo.bytesTotal;
var clip_loaded:Number = _clip.loaderInfo.bytesLoaded;
if (complete){
clip_loaded = Math.max(1, clip_loaded);
clip_total = clip_loaded;
};
var clip_pcnt:Number = ((100 * clip_loaded) / clip_total);
var ad_pcnt:Number = ((100 * elapsed) / chk.ad_msec);
var _inside:Object = this._mochiad_bar._inside;
var pcnt:Number = Math.min(100, Math.min(((clip_pcnt) || (0)), ad_pcnt));
pcnt = Math.max(this.last_pcnt, pcnt);
this.last_pcnt = pcnt;
_inside.scaleX = (pcnt * 0.01);
options.ad_progress(pcnt);
if (sendHostProgress){
clip._mochiad.lc.send(clip._mochiad._containerLCName, "notify", {id:"hostLoadPcnt", pcnt:clip_pcnt});
if (clip_pcnt == 100){
sendHostProgress = false;
};
};
if (!chk.showing){
total = this.parent._mochiad_ctr.contentLoaderInfo.bytesTotal;
if (total > 0){
chk.showing = true;
chk.started = getTimer();
MochiAd.adShowing(clip);
} else {
if ((((elapsed > chk.ad_timeout)) && ((clip_pcnt == 100)))){
options.ad_failed();
finished = true;
};
};
};
if (elapsed > chk.ad_msec){
finished = true;
};
if (((complete) && (finished))){
if (this.server_control){
delete this.onEnterFrame;
} else {
this.fadeout_start = getTimer();
this.onEnterFrame = chk.fadeFunction;
};
};
};
doOnEnterFrame(chk);
}
public static function showPreloaderAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showPreloaderAd was renamed to showPreGameAd in 2.0");
MochiAd.showPreGameAd(options);
}
public static function showTimedAd(options:Object):void{
trace("[MochiAd] DEPRECATED: showTimedAd was renamed to showInterLevelAd in 2.0");
MochiAd.showInterLevelAd(options);
}
public static function doOnEnterFrame(mc:MovieClip):void{
var mc = mc;
var f:Function = function (ev:Object):void{
if (((("onEnterFrame" in mc)) && (mc.onEnterFrame))){
mc.onEnterFrame();
} else {
ev.target.removeEventListener(ev.type, arguments.callee);
};
};
mc.addEventListener(Event.ENTER_FRAME, f);
}
}
}//package
Section 146
//MochiBot (MochiBot)
package {
import flash.display.*;
import flash.net.*;
import flash.system.*;
public dynamic class MochiBot extends Sprite {
public function MochiBot(){
super();
}
public static function track(parent:Sprite, tag:String):MochiBot{
if (Security.sandboxType == "localWithFile"){
return (null);
};
var self:MochiBot = new (MochiBot);
parent.addChild(self);
Security.allowDomain("*");
Security.allowInsecureDomain("*");
var server:String = "http://core.mochibot.com/my/core.swf";
var lv:URLVariables = new URLVariables();
lv["sb"] = Security.sandboxType;
lv["v"] = Capabilities.version;
lv["swfid"] = tag;
lv["mv"] = "8";
lv["fv"] = "9";
var url:String = self.root.loaderInfo.loaderURL;
if (url.indexOf("http") == 0){
lv["url"] = url;
} else {
lv["url"] = "local";
};
var req:URLRequest = new URLRequest(server);
req.contentType = "application/x-www-form-urlencoded";
req.method = URLRequestMethod.POST;
req.data = lv;
var loader:Loader = new Loader();
self.addChild(loader);
loader.load(req);
return (self);
}
}
}//package
Section 147
//Preoader (Preoader)
package {
import flash.events.*;
import flash.display.*;
import flash.text.*;
public dynamic class Preoader extends MovieClip {
private var tf:TextField;
public var level:Main;
public var lock:Boolean;
public function Preoader(){
super();
lock = false;
addEventListener(Event.ENTER_FRAME, oef);
tf = new TextField();
tf.defaultTextFormat = new TextFormat("Verdana, Arial", 10, 0xFFFFFF, null, null, null, null, null, "center");
tf.x = 280;
tf.y = 320;
addChild(tf);
MochiAd.showPreGameAd({clip:root, id:"a4b2d2edb5bbe3b4", res:"640x640", background:13623029, color:3158852, outline:4745110, no_bg:false});
}
public function oef(e:Event=null):void{
tf.text = (Math.round(((root.loaderInfo.bytesLoaded / root.loaderInfo.bytesTotal) * 100)) + "%");
if (tf.text == "100%"){
level = new Main(stage);
addChild(level);
removeChild(tf);
removeEventListener(Event.ENTER_FRAME, oef);
};
}
}
}//package